sparsemap/CMakeLists.txt

95 lines
3.8 KiB
CMake
Raw Normal View History

2024-05-16 14:38:33 +00:00
cmake_minimum_required(VERSION 3.27)
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR)
message(FATAL_ERROR "Do not build in-source. Please remove CMakeCache.txt and the CMakeFiles/ directory. Then build out-of-source.")
endif()
project(sparsemap LANGUAGES C)
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_C_OUTPUT_EXTENSION .o)
2024-07-16 10:20:28 +00:00
set(SOURCE_DIR .)
set(HEADER_DIR . test)
2024-05-16 14:38:33 +00:00
set(COMMON_CMAKE_C_FLAGS "-Wall -Wextra -Wpedantic")
2024-07-19 08:44:26 +00:00
set(CMAKE_C_FLAGS_DEBUG "-DSPARSEMAP_DIAGNOSTIC -DSPARSEMAP_TESTING -DDEBUG -g -O0")
2024-05-16 14:38:33 +00:00
set(CMAKE_C_FLAGS_PROFILE "-DSPARSEMAP_DIAGNOSTIC -DDEBUG -g -Og -fsanitize=address,leak,object-size,pointer-compare,pointer-subtract,null,return,bounds,pointer-overflow,undefined -fsanitize-address-use-after-scope")
set(CMAKE_C_FLAGS_RELEASE "-Ofast")
# Include all header files from the header directory
file(GLOB_RECURSE HEADERS CONFIGURE_FILES ${HEADER_DIR}/*.h)
# Configure library sources
set(LIB_SRC
${SOURCE_DIR}/sparsemap.c
)
# Option to control building shared/static libraries
option(BUILD_SHARED_LIBS "Build shared libraries" ON)
# Add shared library
add_library(sparsemap_SHARED SHARED ${LIB_SRC} ${HEADERS})
# Set target properties for the shared library (adjust if needed)
2024-05-16 14:38:33 +00:00
set_target_properties(sparsemap_SHARED PROPERTIES
VERSION 1.0.0 # Set library version
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib" # Set output directory
COMPILE_FLAGS "${CMAKE_C_FLAGS_${CMAKE_CURRENT_LIST_MODE}}"
)
target_include_directories(sparsemap_SHARED PRIVATE ${HEADER_DIR})
# Add static library
add_library(sparsemap STATIC ${LIB_SRC} ${HEADERS})
# Set target properties for static library (adjust if needed)
set_target_properties(sparsemap PROPERTIES
OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib" # Set output directory
)
target_include_directories(sparsemap PRIVATE ${HEADER_DIR})
# Add ex_1 program
2024-07-16 10:20:28 +00:00
add_executable(ex_1 test/ex_1.c test/munit.c test/common.c)
2024-05-16 14:38:33 +00:00
target_link_libraries(ex_1 PRIVATE sparsemap)
target_include_directories(ex_1 PRIVATE ${HEADER_DIR})
add_custom_target(run_ex_1 COMMAND ex_1 WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
# Add ex_2 program
2024-07-16 10:20:28 +00:00
add_executable(ex_2 test/ex_2.c test/munit.c test/common.c)
2024-05-16 14:38:33 +00:00
target_link_libraries(ex_2 PRIVATE sparsemap)
target_include_directories(ex_2 PRIVATE ${HEADER_DIR})
add_custom_target(run_ex_2 COMMAND ex_2 WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
# Add ex_3 program
2024-07-16 10:20:28 +00:00
add_executable(ex_3 test/ex_3.c test/munit.c test/common.c)
2024-05-16 14:38:33 +00:00
target_link_libraries(ex_3 PRIVATE sparsemap)
target_include_directories(ex_3 PRIVATE ${HEADER_DIR})
add_custom_target(run_ex_3 COMMAND ex_3 WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
# Add ex_4 program
2024-07-16 10:20:28 +00:00
add_executable(ex_4 test/ex_4.c test/munit.c test/common.c)
2024-05-16 14:38:33 +00:00
target_link_libraries(ex_4 PRIVATE sparsemap)
target_include_directories(ex_4 PRIVATE ${HEADER_DIR})
add_custom_target(run_ex_4 COMMAND ex_4 WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
# Add test program
2024-07-19 08:44:26 +00:00
add_executable(test test/test.c test/munit.c test/qc.c test/common.c)
2024-05-16 14:38:33 +00:00
target_link_libraries(test PRIVATE sparsemap)
target_include_directories(test PRIVATE ${HEADER_DIR})
2024-07-19 08:44:26 +00:00
set_source_files_properties(test/test.c PROPERTIES COMPILE_FLAGS "-DDEBUG -DDIAGNOSTIC -DSPARSEMAP_TESTING" )
2024-05-16 14:38:33 +00:00
add_custom_target(run_test COMMAND test WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
2024-05-16 16:00:09 +00:00
# Add soak program
2024-07-16 10:20:28 +00:00
add_executable(soak test/soak.c test/common.c test/tdigest.c test/roaring.c)
2024-05-16 16:00:09 +00:00
target_link_libraries(soak PRIVATE sparsemap)
target_include_directories(soak PRIVATE ${HEADER_DIR} lib)
target_link_libraries(soak PUBLIC m)
add_custom_target(run_soak COMMAND soak WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
# Add fuzzer program
2024-07-12 11:45:07 +00:00
# add_executable(fuzzer EXCLUDE_FROM_ALL tests/fuzzer.c)
# target_link_libraries(fuzzer PRIVATE sparsemap)
# target_include_directories(fuzzer PRIVATE ${HEADER_DIR} lib)
# target_link_libraries(fuzzer PUBLIC m)
# add_custom_target(run_fuzzer COMMAND fuzzer WORKING_DIRECTORY ${CMAKE_BINARY_DIR})