|
| 1 | +cmake_minimum_required(VERSION 3.15) |
| 2 | +project(DNLP_Diff_Engine C) |
| 3 | +set(CMAKE_C_STANDARD 99) |
| 4 | + |
| 5 | +set(DIFF_ENGINE_VERSION_MAJOR 0) |
| 6 | +set(DIFF_ENGINE_VERSION_MINOR 0) |
| 7 | +set(DIFF_ENGINE_VERSION_PATCH 1) |
| 8 | +set(DIFF_ENGINE_VERSION "${DIFF_ENGINE_VERSION_MAJOR}.${DIFF_ENGINE_VERSION_MINOR}.${DIFF_ENGINE_VERSION_PATCH}") |
| 9 | +add_compile_definitions(DIFF_ENGINE_VERSION="${DIFF_ENGINE_VERSION}") |
| 10 | + |
| 11 | +message(STATUS "Configuring DNLP Differentiation Engine (version ${DIFF_ENGINE_VERSION})") |
| 12 | + |
| 13 | + |
| 14 | +#Set default build type to Release if not specified |
| 15 | +if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) |
| 16 | + message(STATUS "Setting build type to 'Release' as none was specified.") |
| 17 | + set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE) |
| 18 | + set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo") |
| 19 | +else() |
| 20 | + message(STATUS "Build type: ${CMAKE_BUILD_TYPE}") |
| 21 | +endif() |
| 22 | + |
| 23 | +# Warning flags (always enabled) |
| 24 | +add_compile_options( |
| 25 | + -Wall # Enable most warnings |
| 26 | + -Wextra # Extra warnings |
| 27 | + -Wpedantic # Strict ISO C compliance |
| 28 | + -Wshadow # Warn about variable shadowing |
| 29 | + -Wformat=2 # Extra format string checks |
| 30 | + -Wcast-qual # Warn about cast that removes qualifiers |
| 31 | + -Wcast-align # Warn about pointer cast alignment issues |
| 32 | + -Wunused # Warn about unused variables/functions |
| 33 | + -Wdouble-promotion # Warn about float->double promotion |
| 34 | + -Wnull-dereference # Warn about null pointer dereference |
| 35 | +) |
| 36 | + |
| 37 | +# Include directories |
| 38 | +include_directories(${PROJECT_SOURCE_DIR}/include) |
| 39 | + |
| 40 | +# Source files - automatically gather all .c files from src/ |
| 41 | +file(GLOB_RECURSE SOURCES "src/*.c") |
| 42 | + |
| 43 | + |
| 44 | +# Create core library |
| 45 | +add_library(dnlp_diff ${SOURCES}) |
| 46 | +target_link_libraries(dnlp_diff m) |
| 47 | + |
| 48 | +# Config-specific compile options |
| 49 | +target_compile_options(dnlp_diff PRIVATE |
| 50 | + $<$<CONFIG:Debug>:-g -O0> |
| 51 | + $<$<CONFIG:Release>:-O3 -DNDEBUG> |
| 52 | + $<$<CONFIG:RelWithDebInfo>:-O2 -g -DNDEBUG> |
| 53 | + $<$<CONFIG:MinSizeRel>:-Os -DNDEBUG> |
| 54 | +) |
| 55 | + |
| 56 | +# This is needed for clock_gettime on Linux without compiler extensions |
| 57 | +if(CMAKE_SYSTEM_NAME STREQUAL "Linux") |
| 58 | + add_compile_definitions(_POSIX_C_SOURCE=200809L) |
| 59 | +endif() |
| 60 | + |
| 61 | +# Enable position-independent code for shared library compatibility |
| 62 | +set_property(TARGET dnlp_diff PROPERTY POSITION_INDEPENDENT_CODE ON) |
| 63 | + |
| 64 | +# ============================================================================= |
| 65 | +# Python bindings (built when using scikit-build-core) |
| 66 | +# ============================================================================= |
| 67 | +if(SKBUILD) |
| 68 | + find_package(Python3 REQUIRED COMPONENTS Interpreter Development.Module NumPy) |
| 69 | + |
| 70 | + # Create Python extension module |
| 71 | + Python3_add_library(_core MODULE python/bindings.c) |
| 72 | + target_include_directories(_core PRIVATE |
| 73 | + ${PROJECT_SOURCE_DIR}/include |
| 74 | + ${PROJECT_SOURCE_DIR}/python |
| 75 | + ${Python3_NumPy_INCLUDE_DIRS} |
| 76 | + ) |
| 77 | + target_link_libraries(_core PRIVATE dnlp_diff) |
| 78 | + |
| 79 | + # Install to the package directory |
| 80 | + install(TARGETS _core LIBRARY DESTINATION dnlp_diff_engine) |
| 81 | +endif() |
| 82 | + |
| 83 | +# ============================================================================= |
| 84 | +# C tests (only for standalone builds) |
| 85 | +# ============================================================================= |
| 86 | +if(NOT SKBUILD) |
| 87 | + include_directories(${PROJECT_SOURCE_DIR}/tests) |
| 88 | + enable_testing() |
| 89 | + |
| 90 | + add_executable(all_tests |
| 91 | + tests/all_tests.c |
| 92 | + tests/test_helpers.c |
| 93 | + ) |
| 94 | + target_link_libraries(all_tests dnlp_diff) |
| 95 | + add_test(NAME AllTests COMMAND all_tests) |
| 96 | +endif() |
0 commit comments