Skip to content

Commit 03fd9bd

Browse files
authored
Cross compiling fixes, improvements and additions (#128)
Signed-off-by: Garrett Brown <[email protected]>
1 parent 9f37400 commit 03fd9bd

File tree

3 files changed

+34
-26
lines changed

3 files changed

+34
-26
lines changed

CMakeLists.txt

+21-17
Original file line numberDiff line numberDiff line change
@@ -34,22 +34,13 @@ endif ()
3434

3535
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
3636

37-
include(CheckCXXCompilerFlag)
38-
include(cmake/toolchain-util.cmake)
39-
include(cmake/dependencies.cmake)
40-
include(cmake/functions.cmake)
41-
include(cmake/san.cmake)
42-
4337
# export compile commands for clang-tidy to analyse only changed files
4438
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
4539

46-
print("C flags: ${CMAKE_C_FLAGS}")
47-
print("CXX flags: ${CMAKE_CXX_FLAGS}")
48-
print("Using CMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}")
49-
5040
option(TESTING "Build tests" ON)
5141
option(TESTING_PROOFS "Build proofs tests" OFF)
5242
option(TESTING_ACTORS "Build actors tests" OFF)
43+
option(BUILD_INTERNAL_DEPS "Build internal dependencies from git submodules" ON)
5344
option(CLANG_FORMAT "Enable clang-format target" ON)
5445
option(CLANG_TIDY "Enable clang-tidy checks during compilation" OFF)
5546
option(COVERAGE "Enable generation of coverage info" OFF)
@@ -60,6 +51,15 @@ option(MSAN "Enable memory sanitizer" OFF)
6051
option(TSAN "Enable thread sanitizer" OFF)
6152
option(UBSAN "Enable UB sanitizer" OFF)
6253

54+
include(CheckCXXCompilerFlag)
55+
include(cmake/toolchain-util.cmake)
56+
include(cmake/dependencies.cmake)
57+
include(cmake/functions.cmake)
58+
include(cmake/san.cmake)
59+
60+
print("C flags: ${CMAKE_C_FLAGS}")
61+
print("CXX flags: ${CMAKE_CXX_FLAGS}")
62+
print("Using CMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}")
6363

6464
## setup compilation flags
6565
if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "^(AppleClang|Clang|GNU)$")
@@ -103,20 +103,24 @@ if (CLANG_FORMAT)
103103
include(cmake/clang-format.cmake)
104104
endif ()
105105

106-
add_subdirectory(deps)
106+
if (BUILD_INTERNAL_DEPS)
107+
add_subdirectory(deps)
108+
endif()
107109

108110
include_directories(
109111
# project includes
110112
${PROJECT_SOURCE_DIR}/core
111113
${PROJECT_SOURCE_DIR}/libs
112114
)
113115

114-
include_directories(
115-
SYSTEM
116-
# system includes
117-
deps/indicators/include
118-
deps/libsecp256k1/include
119-
)
116+
if (BUILD_INTERNAL_DEPS)
117+
include_directories(
118+
SYSTEM
119+
# system includes
120+
deps/indicators/include
121+
deps/libsecp256k1/include
122+
)
123+
endif()
120124

121125
add_subdirectory(libs)
122126
add_subdirectory(core)

cmake/dependencies.cmake

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
# hunter dependencies
22
# https://docs.hunter.sh/en/latest/packages/
33

4-
# https://docs.hunter.sh/en/latest/packages/pkg/GTest.html
5-
hunter_add_package(GTest)
6-
find_package(GTest CONFIG REQUIRED)
4+
if (TESTING)
5+
# https://docs.hunter.sh/en/latest/packages/pkg/GTest.html
6+
hunter_add_package(GTest)
7+
find_package(GTest CONFIG REQUIRED)
8+
endif()
79

810
# https://docs.hunter.sh/en/latest/packages/pkg/Boost.html
911
hunter_add_package(Boost COMPONENTS date_time filesystem iostreams random program_options thread)
@@ -45,9 +47,6 @@ find_package(leveldb CONFIG REQUIRED)
4547
hunter_add_package(libp2p)
4648
find_package(libp2p CONFIG REQUIRED)
4749

48-
hunter_add_package(c-ares)
49-
find_package(c-ares CONFIG REQUIRED)
50-
5150
hunter_add_package(soralog)
5251
find_package(soralog CONFIG REQUIRED)
5352

cmake/functions.cmake

+8-3
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,13 @@ function(add_flag flag)
4646
endfunction()
4747

4848
function(compile_proto_to_cpp PB_H PB_CC PROTO)
49-
get_target_property(Protobuf_INCLUDE_DIR protobuf::libprotobuf INTERFACE_INCLUDE_DIRECTORIES)
50-
get_target_property(Protobuf_PROTOC_EXECUTABLE protobuf::protoc IMPORTED_LOCATION_RELEASE)
49+
if (NOT Protobuf_INCLUDE_DIR)
50+
get_target_property(Protobuf_INCLUDE_DIR protobuf::libprotobuf INTERFACE_INCLUDE_DIRECTORIES)
51+
endif()
52+
if (NOT Protobuf_PROTOC_EXECUTABLE)
53+
get_target_property(Protobuf_PROTOC_EXECUTABLE protobuf::protoc IMPORTED_LOCATION_RELEASE)
54+
set(PROTOBUF_DEPENDS protobuf::protoc)
55+
endif()
5156

5257
if (NOT Protobuf_PROTOC_EXECUTABLE)
5358
message(FATAL_ERROR "Protobuf_PROTOC_EXECUTABLE is empty")
@@ -73,7 +78,7 @@ function(compile_proto_to_cpp PB_H PB_CC PROTO)
7378
COMMAND ${GEN_COMMAND}
7479
ARGS -I${PROJECT_SOURCE_DIR}/core -I${GEN_ARGS} -I${CMAKE_CURRENT_SOURCE_DIR} --cpp_out=${SCHEMA_OUT_DIR} ${PROTO_ABS}
7580
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
76-
DEPENDS protobuf::protoc
81+
DEPENDS ${PROTOBUF_DEPENDS}
7782
VERBATIM
7883
)
7984

0 commit comments

Comments
 (0)