Replace almost all instances of CMAKE_SOURCE_DIR and CMAKE_BINARY_DIR
If another project includes us as a subproject, as gRPC does,
CMAKE_SOURCE_DIR points to the top-level source directory, not ours.
PROJECT_SOURCE_DIR points to ours. Likewise, CMAKE_BINARY_DIR will
point to the top-level one.
gRPC doesn't consume this CMake build, but in preparation for
eventually unifying the two CMake builds, replace CMAKE_SOURCE_DIR and
CMAKE_BINARY_DIR with a combination of CMAKE_CURRENT_{SOURCE,BINARY}_DIR
and PROJECT_SOURCE_DIR.
There's one more CMAKE_SOURCE_DIR which controls some default install
directory. I've left that one alone for now as I'm not sure what to do
with it. Probably the answer is to, like in gRPC, disable the install
target by default when we're not the top-level source directory.
Bug: 542
Change-Id: Iea26bbef8a4637671fd0e7476101512e871e7e18
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/57686
Reviewed-by: Bob Beck <bbe@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
diff --git a/CMakeLists.txt b/CMakeLists.txt
index a66a37f..23154a2 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -475,7 +475,7 @@
CXX_STANDARD_REQUIRED TRUE
)
# libc++abi depends on libc++ internal headers.
- set_property(TARGET libcxx libcxxabi APPEND PROPERTY INCLUDE_DIRECTORIES "${CMAKE_SOURCE_DIR}/util/bot/libcxx/src")
+ set_property(TARGET libcxx libcxxabi APPEND PROPERTY INCLUDE_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR}/util/bot/libcxx/src")
target_link_libraries(libcxx libcxxabi)
endif()
@@ -551,16 +551,16 @@
if(FIPS)
add_custom_target(
acvp_tests
- COMMAND ${GO_EXECUTABLE} build -o ${CMAKE_BINARY_DIR}/acvptool
+ COMMAND ${GO_EXECUTABLE} build -o ${CMAKE_CURRENT_BINARY_DIR}/acvptool
boringssl.googlesource.com/boringssl/util/fipstools/acvp/acvptool
- COMMAND ${GO_EXECUTABLE} build -o ${CMAKE_BINARY_DIR}/testmodulewrapper
+ COMMAND ${GO_EXECUTABLE} build -o ${CMAKE_CURRENT_BINARY_DIR}/testmodulewrapper
boringssl.googlesource.com/boringssl/util/fipstools/acvp/acvptool/testmodulewrapper
COMMAND cd util/fipstools/acvp/acvptool/test &&
${GO_EXECUTABLE} run check_expected.go
- -tool ${CMAKE_BINARY_DIR}/acvptool
- -module-wrappers modulewrapper:$<TARGET_FILE:modulewrapper>,testmodulewrapper:${CMAKE_BINARY_DIR}/testmodulewrapper
+ -tool ${CMAKE_CURRENT_BINARY_DIR}/acvptool
+ -module-wrappers modulewrapper:$<TARGET_FILE:modulewrapper>,testmodulewrapper:${CMAKE_CURRENT_BINARY_DIR}/testmodulewrapper
-tests tests.json
- WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
+ WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
DEPENDS modulewrapper
USES_TERMINAL)
@@ -582,12 +582,12 @@
add_custom_target(
run_tests
COMMAND ${GO_EXECUTABLE} run util/all_tests.go -build-dir
- ${CMAKE_BINARY_DIR}
+ ${CMAKE_CURRENT_BINARY_DIR}
COMMAND cd ssl/test/runner &&
${GO_EXECUTABLE} test -shim-path $<TARGET_FILE:bssl_shim>
${HANDSHAKER_ARGS} ${RUNNER_ARGS}
COMMAND ${GO_EXECUTABLE} test ${GO_TESTS}
- WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
+ WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
DEPENDS all_tests bssl_shim handshaker fips_specific_tests_if_any
USES_TERMINAL)
diff --git a/cmake/go.cmake b/cmake/go.cmake
index 6aca79a..61a01f5 100644
--- a/cmake/go.cmake
+++ b/cmake/go.cmake
@@ -13,7 +13,7 @@
endif()
function(go_executable dest package)
- set(godeps "${CMAKE_SOURCE_DIR}/util/godeps.go")
+ set(godeps "${PROJECT_SOURCE_DIR}/util/godeps.go")
if(NOT CMAKE_GENERATOR STREQUAL "Ninja")
# The DEPFILE parameter to add_custom_command only works with Ninja. Query
# the sources at configure time. Additionally, everything depends on go.mod.
@@ -30,7 +30,7 @@
COMMAND ${GO_EXECUTABLE} build
-o ${CMAKE_CURRENT_BINARY_DIR}/${dest} ${package}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
- DEPENDS ${sources} ${CMAKE_SOURCE_DIR}/go.mod)
+ DEPENDS ${sources} ${PROJECT_SOURCE_DIR}/go.mod)
else()
# Ninja expects the target in the depfile to match the output. This is a
# relative path from the build directory.
@@ -46,7 +46,7 @@
COMMAND ${GO_EXECUTABLE} run ${godeps} -format depfile
-target ${target} -pkg ${package} -out ${depfile}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
- DEPENDS ${godeps} ${CMAKE_SOURCE_DIR}/go.mod
+ DEPENDS ${godeps} ${PROJECT_SOURCE_DIR}/go.mod
DEPFILE ${depfile})
endif()
endfunction()
diff --git a/crypto/CMakeLists.txt b/crypto/CMakeLists.txt
index f917b79..8ece558 100644
--- a/crypto/CMakeLists.txt
+++ b/crypto/CMakeLists.txt
@@ -296,7 +296,7 @@
target_sources(crypto PRIVATE ${CRYPTO_SOURCES_NASM})
endif()
target_include_directories(crypto PUBLIC
- $<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/include>
+ $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)
install_if_enabled(TARGETS crypto EXPORT OpenSSLTargets ${INSTALL_DESTINATION_DEFAULT})
diff --git a/rust/CMakeLists.txt b/rust/CMakeLists.txt
index 019976b..422905f 100644
--- a/rust/CMakeLists.txt
+++ b/rust/CMakeLists.txt
@@ -3,7 +3,7 @@
target_link_libraries(rust_wrapper crypto)
# Generate architecture-specific wrappers.
-set(WRAPPER_TARGET ${CMAKE_BINARY_DIR}/rust/src/wrapper_${RUST_BINDINGS}.rs)
+set(WRAPPER_TARGET ${CMAKE_CURRENT_BINARY_DIR}/src/wrapper_${RUST_BINDINGS}.rs)
set(COMMAND ${BINDGEN_EXECUTABLE} "wrapper.h"
-o ${WRAPPER_TARGET}
--no-derive-default