From 8c4ec3b7b0d69649c04778a39eed5cdca338c1c0 Mon Sep 17 00:00:00 2001 From: David Benjamin Date: Mon, 27 Feb 2023 12:46:12 -0500 Subject: [PATCH] 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 Commit-Queue: David Benjamin --- CMakeLists.txt | 16 ++++++++-------- cmake/go.cmake | 6 +++--- crypto/CMakeLists.txt | 2 +- rust/CMakeLists.txt | 2 +- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a66a37fa4..23154a2c6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -475,7 +475,7 @@ if(USE_CUSTOM_LIBCXX) 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 @@ endif() 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:$,testmodulewrapper:${CMAKE_BINARY_DIR}/testmodulewrapper + -tool ${CMAKE_CURRENT_BINARY_DIR}/acvptool + -module-wrappers 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 @@ set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS 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 $ ${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 6aca79a89..61a01f519 100644 --- a/cmake/go.cmake +++ b/cmake/go.cmake @@ -13,7 +13,7 @@ if(NOT GO_EXECUTABLE) 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 @@ function(go_executable dest package) 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 @@ function(go_executable dest package) 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 f917b79eb..8ece558a7 100644 --- a/crypto/CMakeLists.txt +++ b/crypto/CMakeLists.txt @@ -296,7 +296,7 @@ if(OPENSSL_NASM) target_sources(crypto PRIVATE ${CRYPTO_SOURCES_NASM}) endif() target_include_directories(crypto PUBLIC - $ + $ $ ) install_if_enabled(TARGETS crypto EXPORT OpenSSLTargets ${INSTALL_DESTINATION_DEFAULT}) diff --git a/rust/CMakeLists.txt b/rust/CMakeLists.txt index 019976bcc..422905f32 100644 --- a/rust/CMakeLists.txt +++ b/rust/CMakeLists.txt @@ -3,7 +3,7 @@ add_library(rust_wrapper STATIC rust_wrapper.c) 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