From bdbdf7eaefa26d731fe697a1bdb1481027c2871e Mon Sep 17 00:00:00 2001 From: Garrett Brown Date: Wed, 16 Feb 2022 08:24:27 -0800 Subject: [PATCH 1/5] CMake: Expose CMake options to includes This change shuffles the order of several CMake steps to expose CMake options to included files. By defining options before inclusion, included files are able to access the input provided by the build system. --- CMakeLists.txt | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0ac568fc71..222ad991ca 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -34,19 +34,9 @@ endif () set(CMAKE_EXPORT_COMPILE_COMMANDS ON) -include(CheckCXXCompilerFlag) -include(cmake/toolchain-util.cmake) -include(cmake/dependencies.cmake) -include(cmake/functions.cmake) -include(cmake/san.cmake) - # export compile commands for clang-tidy to analyse only changed files set(CMAKE_EXPORT_COMPILE_COMMANDS ON) -print("C flags: ${CMAKE_C_FLAGS}") -print("CXX flags: ${CMAKE_CXX_FLAGS}") -print("Using CMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}") - option(TESTING "Build tests" ON) option(TESTING_PROOFS "Build proofs tests" OFF) option(TESTING_ACTORS "Build actors tests" OFF) @@ -60,6 +50,15 @@ option(MSAN "Enable memory sanitizer" OFF) option(TSAN "Enable thread sanitizer" OFF) option(UBSAN "Enable UB sanitizer" OFF) +include(CheckCXXCompilerFlag) +include(cmake/toolchain-util.cmake) +include(cmake/dependencies.cmake) +include(cmake/functions.cmake) +include(cmake/san.cmake) + +print("C flags: ${CMAKE_C_FLAGS}") +print("CXX flags: ${CMAKE_CXX_FLAGS}") +print("Using CMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}") ## setup compilation flags if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "^(AppleClang|Clang|GNU)$") From 19e9b6f6647e8f8d2f182ba39eeddb09dcfca601 Mon Sep 17 00:00:00 2001 From: Garrett Brown Date: Wed, 16 Feb 2022 08:24:30 -0800 Subject: [PATCH 2/5] CMake: Exclude test-related depends when building tests When building without tests, GTest and GMock are not needed. This change allows build systems to continue with filecoin compilation without devoting resources to its testing infrastructure. --- cmake/dependencies.cmake | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/cmake/dependencies.cmake b/cmake/dependencies.cmake index 11c568c3ea..e791c0a7f2 100644 --- a/cmake/dependencies.cmake +++ b/cmake/dependencies.cmake @@ -1,9 +1,11 @@ # hunter dependencies # https://docs.hunter.sh/en/latest/packages/ -# https://docs.hunter.sh/en/latest/packages/pkg/GTest.html -hunter_add_package(GTest) -find_package(GTest CONFIG REQUIRED) +if (TESTING) + # https://docs.hunter.sh/en/latest/packages/pkg/GTest.html + hunter_add_package(GTest) + find_package(GTest CONFIG REQUIRED) +endif() hunter_add_package(libarchive) find_package(libarchive CONFIG REQUIRED) From 53a168b9a962cdef9ccf3246e0ed86e1e8aeeac0 Mon Sep 17 00:00:00 2001 From: Garrett Brown Date: Wed, 16 Feb 2022 08:24:32 -0800 Subject: [PATCH 3/5] CMake: Allow excluding git submodule depends Not every build system can handle git submodules, so expose an option to exclude these dependencies from the build --- CMakeLists.txt | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 222ad991ca..bd97cb8ba9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -40,6 +40,7 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON) option(TESTING "Build tests" ON) option(TESTING_PROOFS "Build proofs tests" OFF) option(TESTING_ACTORS "Build actors tests" OFF) +option(BUILD_INTERNAL_DEPS "Build internal dependencies from git submodules" ON) option(CLANG_FORMAT "Enable clang-format target" ON) option(CLANG_TIDY "Enable clang-tidy checks during compilation" OFF) option(COVERAGE "Enable generation of coverage info" OFF) @@ -102,7 +103,9 @@ if (CLANG_FORMAT) include(cmake/clang-format.cmake) endif () -add_subdirectory(deps) +if (BUILD_INTERNAL_DEPS) + add_subdirectory(deps) +endif() include_directories( # project includes @@ -110,12 +113,14 @@ include_directories( ${PROJECT_SOURCE_DIR}/libs ) -include_directories( - SYSTEM - # system includes - deps/indicators/include - deps/libsecp256k1/include -) +if (BUILD_INTERNAL_DEPS) + include_directories( + SYSTEM + # system includes + deps/indicators/include + deps/libsecp256k1/include + ) +endif() add_subdirectory(libs) add_subdirectory(core) From de30c3199bccd418dde46aa52c3f4a49cadb0836 Mon Sep 17 00:00:00 2001 From: Garrett Brown Date: Wed, 16 Feb 2022 08:24:34 -0800 Subject: [PATCH 4/5] CMake: Allow build system to provide protobuf compiler When building without Hunter, it is desirable to pass the path to protoc and the protobuf include directory from the build system. Allow these variables to be overridden. --- cmake/functions.cmake | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/cmake/functions.cmake b/cmake/functions.cmake index 178b7cce52..e2fc4cafed 100644 --- a/cmake/functions.cmake +++ b/cmake/functions.cmake @@ -46,8 +46,13 @@ function(add_flag flag) endfunction() function(compile_proto_to_cpp PB_H PB_CC PROTO) - get_target_property(Protobuf_INCLUDE_DIR protobuf::libprotobuf INTERFACE_INCLUDE_DIRECTORIES) - get_target_property(Protobuf_PROTOC_EXECUTABLE protobuf::protoc IMPORTED_LOCATION_RELEASE) + if (NOT Protobuf_INCLUDE_DIR) + get_target_property(Protobuf_INCLUDE_DIR protobuf::libprotobuf INTERFACE_INCLUDE_DIRECTORIES) + endif() + if (NOT Protobuf_PROTOC_EXECUTABLE) + get_target_property(Protobuf_PROTOC_EXECUTABLE protobuf::protoc IMPORTED_LOCATION_RELEASE) + set(PROTOBUF_DEPENDS protobuf::protoc) + endif() if (NOT Protobuf_PROTOC_EXECUTABLE) message(FATAL_ERROR "Protobuf_PROTOC_EXECUTABLE is empty") @@ -73,7 +78,7 @@ function(compile_proto_to_cpp PB_H PB_CC PROTO) COMMAND ${GEN_COMMAND} ARGS -I${PROJECT_SOURCE_DIR}/core -I${GEN_ARGS} -I${CMAKE_CURRENT_SOURCE_DIR} --cpp_out=${SCHEMA_OUT_DIR} ${PROTO_ABS} WORKING_DIRECTORY ${CMAKE_BINARY_DIR} - DEPENDS protobuf::protoc + DEPENDS ${PROTOBUF_DEPENDS} VERBATIM ) From 174b696e622f48289072991b5241a8eecdb3eead Mon Sep 17 00:00:00 2001 From: Garrett Brown Date: Wed, 16 Feb 2022 08:24:36 -0800 Subject: [PATCH 5/5] CMake: Remove c-ares dependency --- cmake/dependencies.cmake | 3 --- 1 file changed, 3 deletions(-) diff --git a/cmake/dependencies.cmake b/cmake/dependencies.cmake index e791c0a7f2..49b580ad16 100644 --- a/cmake/dependencies.cmake +++ b/cmake/dependencies.cmake @@ -50,9 +50,6 @@ find_package(leveldb CONFIG REQUIRED) hunter_add_package(libp2p) find_package(libp2p CONFIG REQUIRED) -hunter_add_package(c-ares) -find_package(c-ares CONFIG REQUIRED) - hunter_add_package(soralog) find_package(soralog CONFIG REQUIRED)