Skip to content

Commit

Permalink
cmake: Add subtree_add_library function
Browse files Browse the repository at this point in the history
  • Loading branch information
hebasto committed Apr 25, 2024
1 parent c1f05f8 commit a77c1aa
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 12 deletions.
4 changes: 1 addition & 3 deletions cmake/crc32c.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ check_cxx_source_compiles_with_flags("${ARM_CRC_CXXFLAGS}" "
" HAVE_ARM64_CRC32C
)

add_library(crc32c STATIC EXCLUDE_FROM_ALL
subtree_add_library(crc32c STATIC EXCLUDE_FROM_ALL
${PROJECT_SOURCE_DIR}/src/crc32c/src/crc32c.cc
${PROJECT_SOURCE_DIR}/src/crc32c/src/crc32c_portable.cc
)
Expand Down Expand Up @@ -111,5 +111,3 @@ if(HAVE_ARM64_CRC32C)
APPEND PROPERTY COMPILE_OPTIONS ${ARM_CRC_CXXFLAGS}
)
endif()

target_link_libraries(crc32c PRIVATE core_base_interface)
3 changes: 1 addition & 2 deletions cmake/leveldb.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
include(CheckCXXSymbolExists)
check_cxx_symbol_exists(F_FULLFSYNC "fcntl.h" HAVE_FULLFSYNC)

add_library(leveldb STATIC EXCLUDE_FROM_ALL
subtree_add_library(leveldb STATIC EXCLUDE_FROM_ALL
${PROJECT_SOURCE_DIR}/src/leveldb/db/builder.cc
${PROJECT_SOURCE_DIR}/src/leveldb/db/c.cc
${PROJECT_SOURCE_DIR}/src/leveldb/db/db_impl.cc
Expand Down Expand Up @@ -95,7 +95,6 @@ else()
endif()

target_link_libraries(leveldb PRIVATE
core_base_interface
nowarn_leveldb_interface
crc32c
)
6 changes: 2 additions & 4 deletions cmake/minisketch.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ if(MSVC)
endif()

if(HAVE_CLMUL)
add_library(minisketch_clmul OBJECT EXCLUDE_FROM_ALL
subtree_add_library(minisketch_clmul OBJECT EXCLUDE_FROM_ALL
${PROJECT_SOURCE_DIR}/src/minisketch/src/fields/clmul_1byte.cpp
${PROJECT_SOURCE_DIR}/src/minisketch/src/fields/clmul_2bytes.cpp
${PROJECT_SOURCE_DIR}/src/minisketch/src/fields/clmul_3bytes.cpp
Expand All @@ -54,12 +54,11 @@ if(HAVE_CLMUL)
target_compile_options(minisketch_clmul PRIVATE ${CLMUL_CXXFLAGS})
target_link_libraries(minisketch_clmul
PRIVATE
core_base_interface
minisketch_common
)
endif()

add_library(minisketch STATIC EXCLUDE_FROM_ALL
subtree_add_library(minisketch STATIC EXCLUDE_FROM_ALL
${PROJECT_SOURCE_DIR}/src/minisketch/src/minisketch.cpp
${PROJECT_SOURCE_DIR}/src/minisketch/src/fields/generic_1byte.cpp
${PROJECT_SOURCE_DIR}/src/minisketch/src/fields/generic_2bytes.cpp
Expand All @@ -78,7 +77,6 @@ target_include_directories(minisketch

target_link_libraries(minisketch
PRIVATE
core_base_interface
minisketch_common
$<TARGET_NAME_IF_EXISTS:minisketch_clmul>
)
12 changes: 12 additions & 0 deletions cmake/module/AddTargetMacros.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,18 @@

include_guard(GLOBAL)

function(subtree_add_library name)
cmake_parse_arguments(PARSE_ARGV 1 FWD "" "" "")
add_library("${name}" ${FWD_UNPARSED_ARGUMENTS})
target_link_libraries("${name}" PRIVATE core_base_interface)
cmake_language(EVAL CODE "
cmake_language(DEFER
DIRECTORY ${PROJECT_SOURCE_DIR}
CALL target_link_libraries ${name} PRIVATE extra_flags_interface
)
")
endfunction()

function(bitcoincore_add_library name)
cmake_parse_arguments(PARSE_ARGV 1 FWD "" "" "")
add_library("${name}" ${FWD_UNPARSED_ARGUMENTS})
Expand Down
4 changes: 1 addition & 3 deletions cmake/secp256k1.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ check_c_source_compiles("
" HAVE_64BIT_ASM
)

add_library(secp256k1 STATIC EXCLUDE_FROM_ALL
subtree_add_library(secp256k1 STATIC EXCLUDE_FROM_ALL
${PROJECT_SOURCE_DIR}/src/secp256k1/src/secp256k1.c
${PROJECT_SOURCE_DIR}/src/secp256k1/src/precomputed_ecmult.c
${PROJECT_SOURCE_DIR}/src/secp256k1/src/precomputed_ecmult_gen.c
Expand Down Expand Up @@ -54,5 +54,3 @@ if(MSVC)
/wd4267
)
endif()

target_link_libraries(secp256k1 PRIVATE core_base_interface)

0 comments on commit a77c1aa

Please sign in to comment.