Reorganize cmake

This commit is contained in:
2024-01-22 12:54:32 -08:00
parent 387b04d7a3
commit d782419d37

View File

@@ -5,7 +5,6 @@ project(
DESCRIPTION "A data structure for detecting mvcc read-write conflicts in a keyspace of lexicographically-ordered byte sequences."
LANGUAGES C CXX)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
add_compile_options(-fdata-sections -ffunction-sections -fPIE)
if(APPLE)
@@ -25,39 +24,19 @@ if (NOT APPLE)
target_link_options(conflict_set PRIVATE "LINKER:--version-script=${CMAKE_CURRENT_SOURCE_DIR}/linker.map")
endif()
set(TEST_FLAGS -Wall -Wextra -Wpedantic -Wunreachable-code -Werror -UNDEBUG)
include(CTest)
# unit test
add_executable(conflict_set_test ConflictSet.cpp ConflictSet.h)
target_compile_definitions(conflict_set_test PRIVATE ENABLE_TESTS)
# keep asserts for test
target_compile_options(conflict_set_test PRIVATE -UNDEBUG)
# Only emit compile warnings for test
target_compile_options(conflict_set_test PRIVATE -Wall -Wextra -Wpedantic -Wunreachable-code)
target_compile_options(conflict_set_test PRIVATE ${TEST_FLAGS})
target_compile_options(conflict_set_test PRIVATE -fsanitize=address,undefined)
target_link_options(conflict_set_test PRIVATE -fsanitize=address,undefined)
add_test(NAME conflict_set_test COMMAND conflict_set_test)
# api smoke tests
# c90
add_executable(conflict_set_c_api_test conflict_set_c_api_test.c ConflictSet.h)
target_link_libraries(conflict_set_c_api_test PRIVATE conflict_set)
target_compile_options(conflict_set_c_api_test PRIVATE -UNDEBUG)
set_property(TARGET conflict_set_c_api_test PROPERTY C_STANDARD 90)
set_property(TARGET conflict_set_c_api_test PROPERTY C_STANDARD_REQUIRED ON)
add_test(NAME conflict_set_c_api_test COMMAND conflict_set_c_api_test)
target_compile_options(conflict_set_c_api_test PRIVATE -Wall -Wextra -Wpedantic -Wunreachable-code -Werror)
# c++98
add_executable(conflict_set_cxx_api_test conflict_set_cxx_api_test.cpp ConflictSet.h)
target_link_libraries(conflict_set_cxx_api_test PRIVATE conflict_set)
target_compile_options(conflict_set_cxx_api_test PRIVATE -UNDEBUG)
set_property(TARGET conflict_set_cxx_api_test PROPERTY CXX_STANDARD 98)
add_test(NAME conflict_set_cxx_api_test COMMAND conflict_set_cxx_api_test)
target_compile_options(conflict_set_cxx_api_test PRIVATE -Wall -Wextra -Wpedantic -Wunreachable-code -Werror)
# fuzz test
set(FUZZ_FLAGS "-fsanitize=fuzzer-no-link,address,undefined")
include(CheckCXXCompilerFlag)
@@ -67,9 +46,25 @@ check_cxx_compiler_flag(${FUZZ_FLAGS} HAS_LIB_FUZZER)
if (HAS_LIB_FUZZER)
add_executable(conflict_set_fuzz_test ConflictSet.cpp ConflictSet.h)
target_compile_definitions(conflict_set_fuzz_test PRIVATE ENABLE_FUZZ)
# keep asserts for test
target_compile_options(conflict_set_fuzz_test PRIVATE -UNDEBUG)
target_compile_options(conflict_set_fuzz_test PRIVATE -Wall -Wextra -Wpedantic -Wunreachable-code)
target_compile_options(conflict_set_fuzz_test PRIVATE ${TEST_FLAGS})
target_compile_options(conflict_set_fuzz_test PRIVATE ${FUZZ_FLAGS})
target_link_options(conflict_set_fuzz_test PRIVATE ${FUZZ_FLAGS} -fsanitize=fuzzer)
endif()
# api smoke tests
# c90
add_executable(conflict_set_c_api_test conflict_set_c_api_test.c)
target_compile_options(conflict_set_c_api_test PRIVATE ${TEST_FLAGS})
target_link_libraries(conflict_set_c_api_test PRIVATE conflict_set)
set_property(TARGET conflict_set_c_api_test PROPERTY C_STANDARD 90)
set_property(TARGET conflict_set_c_api_test PROPERTY C_STANDARD_REQUIRED ON)
add_test(NAME conflict_set_c_api_test COMMAND conflict_set_c_api_test)
# c++98
add_executable(conflict_set_cxx_api_test conflict_set_cxx_api_test.cpp)
target_compile_options(conflict_set_cxx_api_test PRIVATE ${TEST_FLAGS})
target_link_libraries(conflict_set_cxx_api_test PRIVATE conflict_set)
set_property(TARGET conflict_set_c_api_test PROPERTY CXX_STANDARD 98)
set_property(TARGET conflict_set_c_api_test PROPERTY CXX_STANDARD_REQUIRED ON)
add_test(NAME conflict_set_cxx_api_test COMMAND conflict_set_cxx_api_test)