Skip to content

Commit

Permalink
cleanup top cmake
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreyMlashkin committed May 29, 2024
1 parent 2cfaa0d commit 66096ae
Show file tree
Hide file tree
Showing 54 changed files with 90 additions and 497 deletions.
19 changes: 5 additions & 14 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@ cm_workspace(crypto3)
cm_setup_version(VERSION 0.3.0 PREFIX ${CMAKE_WORKSPACE_NAME})

option(BUILD_SHARED_LIBS "Build shared library" FALSE) # TODO: it makes no sense for header-only lib, remove
option(USE_STATIC_BOOST "Use static libraries for Boost" FALSE)
option(BUILD_TESTS "Include tests to `all` target" FALSE) # used by CMTest module
option(CMAKE_ENABLE_TESTS "Enable tests" FALSE) # used by CMTest module
option(Boost_USE_STATIC_LIBS "Use static libraries for Boost" OFF)
option(ENABLE_TESTS "Enable tests" TRUE) # used by CMTest module
option(BUILD_BENCH_TESTS "Build performance benchmark tests" FALSE)
option(BUILD_DOCS "Build with configuring Doxygen documentation compiler" FALSE)

Expand All @@ -40,18 +39,10 @@ else()
target_architecture(CMAKE_TARGET_ARCHITECTURE)
endif()

if(USE_STATIC_BOOST)
set(Boost_USE_STATIC_LIBS ON)
else()
set(Boost_USE_STATIC_LIBS OFF)
endif()

# TODO: in subdirs use Boost::lib_name instead of wide ${Boost_LIBRARIES}, split next lines into 2 find_package calls
set(BOOST_COMPONENTS "container;random;system")
if(CMAKE_ENABLE_TESTS)
list(APPEND BOOST_COMPONENTS "unit_test_framework")
find_package(Boost REQUIRED COMPONENTS container random filesystem log log_setup program_options thread system)
if(ENABLE_TESTS)
find_package(Boost REQUIRED COMPONENTS unit_test_framework timer)
endif()
find_package(Boost REQUIRED COMPONENTS ${BOOST_COMPONENTS})

add_subdirectories("${CMAKE_CURRENT_LIST_DIR}/libs/")
add_subdirectories("${CMAKE_CURRENT_LIST_DIR}/libs/marshalling")
Expand Down
3 changes: 1 addition & 2 deletions libs/algebra/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ target_include_directories(${CMAKE_WORKSPACE_NAME}_${CURRENT_PROJECT_NAME} INTER
$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/include>)

target_link_libraries(${CMAKE_WORKSPACE_NAME}_${CURRENT_PROJECT_NAME} INTERFACE
${CMAKE_WORKSPACE_NAME}::multiprecision
Boost::unit_test_framework)
${CMAKE_WORKSPACE_NAME}::multiprecision)

cm_deploy(TARGETS ${CMAKE_WORKSPACE_NAME}_${CURRENT_PROJECT_NAME}
INCLUDE include
Expand Down
2 changes: 1 addition & 1 deletion libs/algebra/example/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ macro(define_algebra_example name)
${CMAKE_WORKSPACE_NAME}_algebra

$<TARGET_NAME_IF_EXISTS:boost_multiprecision>
)

${Boost_LIBRARIES})
set_target_properties(algebra_${name}_example PROPERTIES CXX_STANDARD 14)
endmacro()

Expand Down
23 changes: 1 addition & 22 deletions libs/algebra/test/bench_test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,13 @@

include(CMTest)

if(NOT Boost_UNIT_TEST_FRAMEWORK_FOUND)
find_package(Boost REQUIRED COMPONENTS unit_test_framework)
endif()

add_custom_target(algebra_runtime_bench_tests)

macro(define_runtime_algebra_test name)
set(test_name "algebra_${name}_bench_test")
add_dependencies(algebra_runtime_bench_tests ${test_name})

set(additional_args "")
if(ENABLE_JUNIT_TEST_OUTPUT)
set(TEST_RESULTS_DIR "${CMAKE_CURRENT_BINARY_DIR}/junit_results")
set(TEST_LOGS_DIR "${TEST_RESULTS_DIR}/logs")
file(MAKE_DIRECTORY ${TEST_LOGS_DIR})

set(additional_args "--log_format=JUNIT"
"--log_sink=${TEST_LOGS_DIR}/${test_name}.xml")
endif()

cm_test(NAME ${test_name} SOURCES ${name}.cpp ARGS ${additional_args})
cm_test(NAME ${test_name} SOURCES ${name}.cpp)

target_include_directories(${test_name} PRIVATE
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
Expand All @@ -39,13 +25,6 @@ macro(define_runtime_algebra_test name)
set_target_properties(${test_name} PROPERTIES CXX_STANDARD 17
CXX_STANDARD_REQUIRED TRUE)

get_target_property(target_type Boost::unit_test_framework TYPE)
if(target_type STREQUAL "SHARED_LIB")
target_compile_definitions(${test_name} PRIVATE BOOST_TEST_DYN_LINK)
elseif(target_type STREQUAL "STATIC_LIB")

endif()

if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
target_compile_options(${test_name} PRIVATE "-fconstexpr-steps=2147483647")
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
Expand Down
6 changes: 1 addition & 5 deletions libs/block/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ endif()

cm_project(block WORKSPACE_NAME ${CMAKE_WORKSPACE_NAME} LANGUAGES C CXX)

if((NOT Boost_CONTAINER_FOUND OR NOT Boost_FOUND) AND NOT CMAKE_CROSSCOMPILING)
find_package(Boost COMPONENTS REQUIRED container)
endif()

include(TargetArchitecture)
include(TargetConfiguration)
include(PlatformConfiguration)
Expand Down Expand Up @@ -492,7 +488,7 @@ elseif(${CMAKE_TARGET_ARCHITECTURE} STREQUAL "ppc64")
endif()

target_link_libraries(${CMAKE_WORKSPACE_NAME}_${CURRENT_PROJECT_NAME} INTERFACE
${Boost_LIBRARIES})
Boost::container)

target_include_directories(${CMAKE_WORKSPACE_NAME}_${CURRENT_PROJECT_NAME} INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
Expand Down
13 changes: 1 addition & 12 deletions libs/block/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,8 @@
# http://www.boost.org/LICENSE_1_0.txt
#---------------------------------------------------------------------------#

if(NOT Boost_UNIT_TEST_FRAMEWORK_FOUND)
find_package(Boost REQUIRED COMPONENTS unit_test_framework)
endif()

cm_test_link_libraries(${CMAKE_WORKSPACE_NAME}_${CURRENT_PROJECT_NAME}
${Boost_LIBRARIES})
Boost::unit_test_framework)

macro(define_block_cipher_test name)
set(test_name "block_${name}_test")
Expand All @@ -28,13 +24,6 @@ macro(define_block_cipher_test name)
set_target_properties(${test_name} PROPERTIES CXX_STANDARD 14)
endif()

get_target_property(target_type Boost::unit_test_framework TYPE)
if(target_type STREQUAL "SHARED_LIB")
target_compile_definitions(${test_name} PRIVATE BOOST_TEST_DYN_LINK)
elseif(target_type STREQUAL "STATIC_LIB")

endif()

string(CONCAT TEST_DATA ${CMAKE_CURRENT_SOURCE_DIR} "/data/" "${name}" ".json")
target_compile_definitions(${test_name} PRIVATE TEST_DATA="${TEST_DATA}")
endmacro()
Expand Down
6 changes: 1 addition & 5 deletions libs/codec/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@ endif()

cm_project(codec WORKSPACE_NAME ${CMAKE_WORKSPACE_NAME} LANGUAGES C CXX)

if((NOT Boost_CONTAINER_FOUND OR NOT Boost_FOUND) AND NOT CMAKE_CROSSCOMPILING)
find_package(Boost COMPONENTS REQUIRED container)
endif()

option(CRYPTO3_CODEC_BASE58 "Build unit tests" TRUE)

set(BUILD_WITH_CONFIGURATION_FILE_DIR "${CMAKE_CURRENT_LIST_DIR}/cmake" CACHE STRING "Directory for build.hpp lookup")
Expand Down Expand Up @@ -78,7 +74,7 @@ set_target_properties(${CMAKE_WORKSPACE_NAME}_${CURRENT_PROJECT_NAME} PROPERTIES
target_link_libraries(${CMAKE_WORKSPACE_NAME}_${CURRENT_PROJECT_NAME} INTERFACE
$<$<BOOL:${CRYPTO3_CODEC_BASE58}>:${CMAKE_WORKSPACE_NAME}::multiprecision>

${Boost_LIBRARIES})
Boost::container)

target_include_directories(${CMAKE_WORKSPACE_NAME}_${CURRENT_PROJECT_NAME} INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
Expand Down
12 changes: 1 addition & 11 deletions libs/codec/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,10 @@

include(CMTest)

if(NOT Boost_UNIT_TEST_FRAMEWORK_FOUND)
find_package(Boost REQUIRED COMPONENTS unit_test_framework)
endif()

cm_test_link_libraries(${CMAKE_WORKSPACE_NAME}_${CURRENT_PROJECT_NAME}
${CMAKE_WORKSPACE_NAME}::multiprecision

${Boost_LIBRARIES})
Boost::unit_test_framework)

macro(define_codec_test name)
cm_test(NAME codec_${name}_test SOURCES ${name}.cpp)
Expand All @@ -32,12 +28,6 @@ macro(define_codec_test name)
CXX_STANDARD_REQUIRED TRUE)
endif()

get_target_property(target_type Boost::unit_test_framework TYPE)
if(target_type STREQUAL "SHARED_LIB")
target_compile_definitions(codec_${name}_test PRIVATE BOOST_TEST_DYN_LINK)
elseif(target_type STREQUAL "STATIC_LIB")

endif()
endmacro()

set(TESTS_NAMES "hex" "base")
Expand Down
11 changes: 3 additions & 8 deletions libs/containers/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,6 @@ cm_workspace(crypto3)
include(CMDeploy)
include(CMSetupVersion)

if (NOT Boost_FOUND AND NOT CMAKE_CROSSCOMPILING)
find_package(Boost COMPONENTS REQUIRED filesystem)
endif ()

cm_project(containers WORKSPACE_NAME ${CMAKE_WORKSPACE_NAME})

option(BUILD_DOXYGEN_DOCS "Build with configuring Doxygen documentation compiler" TRUE)
Expand Down Expand Up @@ -76,7 +72,7 @@ target_link_libraries(${CMAKE_WORKSPACE_NAME}_${CURRENT_PROJECT_NAME} INTERFACE
${CMAKE_WORKSPACE_NAME}::algebra
${CMAKE_WORKSPACE_NAME}::hash

${Boost_LIBRARIES})
Boost::container)

target_include_directories(${CMAKE_WORKSPACE_NAME}_${CURRENT_PROJECT_NAME} INTERFACE
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
Expand All @@ -86,9 +82,8 @@ target_include_directories(${CMAKE_WORKSPACE_NAME}_${CURRENT_PROJECT_NAME} INTER

cm_deploy(TARGETS ${CMAKE_WORKSPACE_NAME}_${CURRENT_PROJECT_NAME} INCLUDE include NAMESPACE ${CMAKE_WORKSPACE_NAME}::)

if (BUILD_TESTS)
add_subdirectory(test)
endif ()
include(CMTest)
cm_add_test_subdirectory(test)

if (BUILD_EXAMPLES)
add_subdirectory(example)
Expand Down
2 changes: 1 addition & 1 deletion libs/containers/example/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ macro(define_containers_example example)
target_link_libraries(${target_name} PRIVATE
${CMAKE_WORKSPACE_NAME}::algebra
${CMAKE_WORKSPACE_NAME}::hash
${Boost_LIBRARIES})
Boost::container)
set_target_properties(${target_name} PROPERTIES CXX_STANDARD 17)
endmacro()

Expand Down
27 changes: 4 additions & 23 deletions libs/containers/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,14 @@

include(CMTest)

if(NOT Boost_UNIT_TEST_FRAMEWORK_FOUND)
find_package(Boost REQUIRED COMPONENTS unit_test_framework)
endif()

cm_test_link_libraries(${CMAKE_WORKSPACE_NAME}_${CURRENT_PROJECT_NAME}

${CMAKE_WORKSPACE_NAME}::algebra
${CMAKE_WORKSPACE_NAME}::hash

${Boost_LIBRARIES})
Boost::unit_test_framework
Boost::random
)

macro(define_storage_test test)
get_filename_component(test_name ${test} NAME)
Expand All @@ -46,17 +44,7 @@ macro(define_storage_test test)
set(target_name ${PARENT_DIR}_${target_name})
endwhile()

set(additional_args "")
if(ENABLE_JUNIT_TEST_OUTPUT)
set(TEST_RESULTS_DIR "${CMAKE_CURRENT_BINARY_DIR}/junit_results")
set(TEST_LOGS_DIR "${TEST_RESULTS_DIR}/logs")
file(MAKE_DIRECTORY ${TEST_LOGS_DIR})

set(additional_args "--log_format=JUNIT"
"--log_sink=${TEST_LOGS_DIR}/${target_name}.xml")
endif()

cm_test(NAME ${target_name} SOURCES ${test}.cpp ARGS ${additional_args})
cm_test(NAME ${target_name} SOURCES ${test}.cpp)

target_include_directories(${target_name} PRIVATE
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
Expand All @@ -66,13 +54,6 @@ macro(define_storage_test test)

set_target_properties(${target_name} PROPERTIES CXX_STANDARD 17)

get_target_property(target_type Boost::unit_test_framework TYPE)
if(target_type STREQUAL "SHARED_LIB")
target_compile_definitions(${target_name} PRIVATE BOOST_TEST_DYN_LINK)
elseif(target_type STREQUAL "STATIC_LIB")

endif()

if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
target_compile_options(${target_name} PRIVATE "-fconstexpr-steps=2147483647" "-ftemplate-backtrace-limit=0")
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
Expand Down
6 changes: 1 addition & 5 deletions libs/hash/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@ endif()

cm_project(hash WORKSPACE_NAME ${CMAKE_WORKSPACE_NAME} LANGUAGES C CXX)

if(NOT Boost_FOUND AND NOT CMAKE_CROSSCOMPILING)
find_package(Boost COMPONENTS REQUIRED container)
endif()

include(TargetArchitecture)
include(TargetConfiguration)
include(PlatformConfiguration)
Expand Down Expand Up @@ -241,7 +237,7 @@ target_link_libraries(${CMAKE_WORKSPACE_NAME}_${CURRENT_PROJECT_NAME} INTERFACE
${CMAKE_WORKSPACE_NAME}::algebra
${CMAKE_WORKSPACE_NAME}::block

${Boost_LIBRARIES})
Boost::container)

target_include_directories(${CMAKE_WORKSPACE_NAME}_${CURRENT_PROJECT_NAME} INTERFACE
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
Expand Down
25 changes: 2 additions & 23 deletions libs/hash/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,17 @@ include(CMTest)

cm_find_package(${CMAKE_WORKSPACE_NAME}_block)

if(NOT Boost_UNIT_TEST_FRAMEWORK_FOUND)
find_package(Boost REQUIRED COMPONENTS unit_test_framework)
endif()

cm_test_link_libraries(${CMAKE_WORKSPACE_NAME}_${CURRENT_PROJECT_NAME}
${${CURRENT_PROJECT_NAME}_INTERFACE_LIBRARIES}

${CMAKE_WORKSPACE_NAME}::block

${Boost_LIBRARIES})
Boost::unit_test_framework)

macro(define_hash_test name)
set(test_name "hash_${name}_test")

set(additional_args "")
if(ENABLE_JUNIT_TEST_OUTPUT)
set(TEST_RESULTS_DIR "${CMAKE_CURRENT_BINARY_DIR}/junit_results")
set(TEST_LOGS_DIR "${TEST_RESULTS_DIR}/logs")
file(MAKE_DIRECTORY ${TEST_LOGS_DIR})

set(additional_args "--log_format=JUNIT"
"--log_sink=${TEST_LOGS_DIR}/${test_name}.xml")
endif()

cm_test(NAME ${test_name} SOURCES ${name}.cpp ARGS ${additional_args})
cm_test(NAME ${test_name} SOURCES ${name}.cpp)

target_include_directories(${test_name} PRIVATE
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
Expand All @@ -46,13 +32,6 @@ macro(define_hash_test name)
CXX_STANDARD 17
CXX_STANDARD_REQUIRED TRUE)

get_target_property(target_type Boost::unit_test_framework TYPE)
if(target_type STREQUAL "SHARED_LIB")
target_compile_definitions(${test_name} PRIVATE BOOST_TEST_DYN_LINK)
elseif(target_type STREQUAL "STATIC_LIB")

endif()

if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
target_compile_options(${test_name} PRIVATE "-fconstexpr-steps=2147483647")
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
Expand Down
4 changes: 0 additions & 4 deletions libs/kdf/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@ cm_find_package(${CMAKE_WORKSPACE_NAME}_block)
cm_find_package(${CMAKE_WORKSPACE_NAME}_hash)
cm_find_package(${CMAKE_WORKSPACE_NAME}_mac)

if(NOT Boost)
find_package(Boost REQUIRED)
endif()

list(APPEND ${CURRENT_PROJECT_NAME}_PUBLIC_HEADERS
include/nil/crypto3/kdf/algorithm/derive.hpp

Expand Down
12 changes: 1 addition & 11 deletions libs/kdf/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,12 @@ include(CMTest)
cm_find_package(${CMAKE_WORKSPACE_NAME}_block)
cm_find_package(${CMAKE_WORKSPACE_NAME}_hash)

if(NOT Boost_UNIT_TEST_FRAMEWORK_FOUND)
find_package(Boost REQUIRED COMPONENTS unit_test_framework)
endif()

cm_test_link_libraries(${CMAKE_WORKSPACE_NAME}_${CURRENT_PROJECT_NAME}

${CMAKE_WORKSPACE_NAME}::block
${CMAKE_WORKSPACE_NAME}::hash

${Boost_LIBRARIES})
Boost::unit_test_framework)

macro(define_kdf_test name)
cm_test(NAME ${name}_test SOURCES ${name}.cpp)
Expand All @@ -33,12 +29,6 @@ macro(define_kdf_test name)

set_target_properties(${name}_test PROPERTIES CXX_STANDARD 14)

get_target_property(target_type Boost::unit_test_framework TYPE)
if(target_type STREQUAL "SHARED_LIB")
target_compile_definitions(${name}_test PRIVATE BOOST_TEST_DYN_LINK)
elseif(target_type STREQUAL "STATIC_LIB")

endif()
endmacro()

set(TESTS_NAMES
Expand Down
Loading

1 comment on commit 66096ae

@x-mass
Copy link
Member

@x-mass x-mass commented on 66096ae May 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inappropriate commit name

Please sign in to comment.