|
1 | | -cmake_minimum_required(VERSION 3.8) |
2 | | -project(TI_CCD) |
3 | | - |
4 | | -################################################################################ |
5 | | -set(CMAKE_CXX_STANDARD 11) |
6 | | -set(CMAKE_CXX_STANDARD_REQUIRED ON) |
| 1 | +# Detects whether this is a top-level project |
| 2 | +get_directory_property(HAS_PARENT PARENT_DIRECTORY) |
| 3 | +if(HAS_PARENT) |
| 4 | + set(TIGHT_INCLUSION_TOPLEVEL_PROJECT OFF) |
| 5 | +else() |
| 6 | + set(TIGHT_INCLUSION_TOPLEVEL_PROJECT ON) |
| 7 | +endif() |
7 | 8 |
|
8 | | -if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) |
9 | | - set(TIGHT_INCLUSION_TOPLEVEL_PROJECT ON) |
10 | | - message(STATUS "Tight-Inclusion CCD top-level project") |
| 9 | +# Check required CMake version |
| 10 | +set(REQUIRED_CMAKE_VERSION "3.14.0") |
| 11 | +if(TIGHT_INCLUSION_TOPLEVEL_PROJECT) |
| 12 | + cmake_minimum_required(VERSION ${REQUIRED_CMAKE_VERSION}) |
11 | 13 | else() |
12 | | - set(TIGHT_INCLUSION_TOPLEVEL_PROJECT OFF) |
13 | | - message(STATUS "Tight-Inclusion CCD bottom-level project") |
14 | | -# message(STATUS "${CMAKE_CURRENT_SOURCE_DIR}") |
15 | | -# message(STATUS "${CMAKE_SOURCE_DIR}") |
| 14 | + # Don't use cmake_minimum_required here to avoid implicitly overriding parent policies |
| 15 | + if(${CMAKE_VERSION} VERSION_LESS ${REQUIRED_CMAKE_VERSION}) |
| 16 | + message(FATAL_ERROR "CMake required version to build Tight Inclusion is ${REQUIRED_CMAKE_VERSION}") |
| 17 | + endif() |
16 | 18 | endif() |
17 | 19 |
|
18 | | -### Configuration |
19 | | -set(TIGHT_INCLUSION_EXTERNAL "${CMAKE_CURRENT_SOURCE_DIR}/external") |
20 | | -set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake) |
| 20 | +# Include user-provided default options if available. We do that before the main |
| 21 | +# `project()` so that we can define the C/C++ compilers from the option file. |
| 22 | +if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/TightInclusionOptions.cmake) |
| 23 | + message(STATUS "Using local options file: ${CMAKE_CURRENT_SOURCE_DIR}/TightInclusionOptions.cmake") |
| 24 | + include(${CMAKE_CURRENT_SOURCE_DIR}/TightInclusionOptions.cmake) |
| 25 | +endif() |
21 | 26 |
|
22 | | -include(Warnings) |
23 | | -include(UseColors) |
24 | | -include(TI_CCDUtils) |
| 27 | +################################################################################ |
| 28 | + |
| 29 | +project(TightInclusion |
| 30 | + DESCRIPTION "Tight Inclusion CCD" |
| 31 | + LANGUAGES CXX) |
25 | 32 |
|
26 | | -OPTION(TIGHT_INCLUSION_WITH_GMP "Enable rational based predicates, for debug" OFF) |
27 | | -OPTION(TIGHT_INCLUSION_WITH_TESTS "Enable test functions" OFF) |
28 | | -OPTION(TIGHT_INCLUSION_WITH_TIMER "Enable profiling timers, for debug" OFF) |
29 | | -OPTION(TIGHT_INCLUSION_WITH_NO_ZERO_TOI "Enable refinement if CCD produces a zero ToI" OFF) |
| 33 | +OPTION(TIGHT_INCLUSION_WITH_TESTS "Enable test functions" OFF) |
| 34 | +OPTION(TIGHT_INCLUSION_WITH_GMP "Enable rational based predicates, for debug" OFF) |
| 35 | +OPTION(TIGHT_INCLUSION_WITH_TIMER "Enable profiling timers, for debug" OFF) |
30 | 36 | OPTION(TIGHT_INCLUSION_WITH_DOUBLE_PRECISION "Enable double precision floating point numbers as input" ON) |
31 | | -OPTION(TIGHT_INCLUSION_LIMIT_QUEUE_SIZE "Enable limitation of maximal queue size" OFF) |
| 37 | +OPTION(TIGHT_INCLUSION_LIMIT_QUEUE_SIZE "Enable limitation of maximal queue size" OFF) |
| 38 | + |
| 39 | +# Option to supress progress output when on GH actions. |
| 40 | +OPTION(TIGHT_INCLUSION_SUPPRESS_PROGRESS_OUTPUT "Enable limitation of maximal queue size" OFF) |
| 41 | +mark_as_advanced(TIGHT_INCLUSION_SUPPRESS_PROGRESS_OUTPUT) |
| 42 | + |
| 43 | +include(CMakeDependentOption) |
| 44 | +cmake_dependent_option(TIGHT_INCLUSION_FLOAT_WITH_DOUBLE_INPUT "Enable converting double queries to float" OFF "TIGHT_INCLUSION_WITH_DOUBLE_PRECISION" OFF) |
32 | 45 |
|
33 | | -if(NOT TIGHT_INCLUSION_WITH_DOUBLE_PRECISION) |
34 | | -OPTION(TIGHT_INCLUSION_FLOAT_WITH_DOUBLE_INPUT "Enable converting double queries to float" OFF) |
| 46 | +# Set default minimum C++ standard |
| 47 | +if(TIGHT_INCLUSION_TOPLEVEL_PROJECT) |
| 48 | + set(CMAKE_CXX_STANDARD 17) |
| 49 | + set(CMAKE_CXX_STANDARD_REQUIRED ON) |
| 50 | + set(CMAKE_CXX_EXTENSIONS OFF) |
35 | 51 | endif() |
36 | 52 |
|
37 | | -include(${PROJECT_NAME}Dependencies) |
| 53 | +### Configuration |
| 54 | +set(TIGHT_INCLUSION_SOURCE_DIR "${PROJECT_SOURCE_DIR}/src") |
| 55 | + |
| 56 | +list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/tight_inclusion/") |
| 57 | +list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/recipes/") |
| 58 | +list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/find/") |
38 | 59 |
|
| 60 | +# Tight Inclusion utils |
| 61 | +include(tight_inclusion_utils) |
| 62 | + |
| 63 | +################################################################################ |
| 64 | +# Tight Inclusion Library |
| 65 | +################################################################################ |
| 66 | + |
| 67 | +# Add an empty library and fill in the list of sources in `src/CMakeLists.txt`. |
| 68 | +add_library(tight_inclusion) |
| 69 | +add_library(tight_inclusion::tight_inclusion ALIAS tight_inclusion) |
39 | 70 |
|
40 | | -# inclusion CCD |
41 | 71 | add_subdirectory(tight_inclusion) |
42 | | -prepend_current_path(INCLUSION_SOURCES) |
43 | | -inclusionCCD_copy_headers(${INCLUSION_SOURCES}) |
44 | | -CCD_set_source_group(${INCLUSION_SOURCES}) |
45 | | -add_library(tight_inclusion ${INCLUSION_SOURCES}) |
| 72 | + |
| 73 | +# Public include directory for Tight Inclusion |
46 | 74 | target_include_directories(tight_inclusion PUBLIC ${PROJECT_BINARY_DIR}/include) |
| 75 | + |
| 76 | +################################################################################ |
| 77 | +# Optional Definitions |
| 78 | +################################################################################ |
| 79 | + |
| 80 | +# For MSVC, do not use the min and max macros. |
| 81 | +target_compile_definitions(tight_inclusion PUBLIC NOMINMAX) |
| 82 | + |
| 83 | +################################################################################ |
| 84 | +# Dependencies |
| 85 | +################################################################################ |
| 86 | + |
| 87 | +# Extra warnings |
| 88 | +include(tight_inclusion_warnings) |
| 89 | +target_link_libraries(tight_inclusion PRIVATE tight_inclusion::warnings) |
| 90 | + |
| 91 | +# libigl |
| 92 | +include(eigen) |
47 | 93 | target_link_libraries(tight_inclusion PUBLIC Eigen3::Eigen) |
48 | | -target_link_libraries(tight_inclusion PRIVATE warnings::all) |
49 | | - |
50 | | -#Optional |
51 | | -#GMP |
52 | | -if(TIGHT_INCLUSION_WITH_GMP) |
53 | | - message(STATUS "TIGHT_INCLUSION_WITH_GMP is defined, now using rational root finder") |
54 | | - target_link_libraries(tight_inclusion PUBLIC gmp::gmp) |
55 | | - target_compile_definitions(tight_inclusion PUBLIC TIGHT_INCLUSION_USE_GMP) |
56 | | -endif() |
57 | 94 |
|
58 | | -if(TIGHT_INCLUSION_WITH_TIMER) |
59 | | - target_compile_definitions(tight_inclusion PRIVATE TIGHT_INCLUSION_USE_TIMER) |
| 95 | +# GMP (optional) |
| 96 | +if(TIGHT_INCLUSION_WITH_GMP OR TIGHT_INCLUSION_WITH_TESTS) |
| 97 | + find_package(GMP REQUIRED) |
| 98 | + target_link_libraries(tight_inclusion PUBLIC gmp::gmp) |
| 99 | + target_compile_definitions(tight_inclusion PUBLIC TIGHT_INCLUSION_USE_GMP) |
60 | 100 | endif() |
61 | 101 |
|
62 | | -# Figure out AVX level support |
63 | | -message(STATUS "Searching for AVX...") |
64 | | -find_package(AVX) |
65 | | -# Add SSE, AVX, and FMA flags to compiler flags |
66 | | -string(REPLACE " " ";" SIMD_FLAGS "${AVX_FLAGS}") |
67 | | -target_compile_options(tight_inclusion PRIVATE ${SIMD_FLAGS}) |
68 | | -if (TIGHT_INCLUSION_WITH_NO_ZERO_TOI) |
69 | | - target_compile_definitions(tight_inclusion PRIVATE TIGHT_INCLUSION_NO_ZERO_TOI) |
| 102 | +################################################################################ |
| 103 | +# Definitions |
| 104 | +################################################################################ |
| 105 | + |
| 106 | +if(TIGHT_INCLUSION_WITH_TIMER) |
| 107 | + target_compile_definitions(tight_inclusion PRIVATE TIGHT_INCLUSION_USE_TIMER) |
70 | 108 | endif() |
71 | 109 |
|
72 | 110 | if (TIGHT_INCLUSION_WITH_DOUBLE_PRECISION) |
73 | | - target_compile_definitions(tight_inclusion PUBLIC TIGHT_INCLUSION_DOUBLE) |
74 | | - message(STATUS "Using Double Precision Floating Points") |
| 111 | + message(STATUS "Tight Inclusion: Using Double Precision Floating Points") |
| 112 | + target_compile_definitions(tight_inclusion PUBLIC TIGHT_INCLUSION_DOUBLE) |
75 | 113 | else() |
76 | | -message(STATUS "Using Single Precision Floating Points") |
| 114 | + message(STATUS "Tight Inclusion: Using Single Precision Floating Points") |
77 | 115 | endif() |
| 116 | + |
78 | 117 | if(TIGHT_INCLUSION_LIMIT_QUEUE_SIZE) |
79 | | - target_compile_definitions(tight_inclusion PUBLIC TI_LIMIT_QUEUE_SIZE) |
80 | | - message(STATUS "TICCD limiting maximal queue size") |
| 118 | + message(STATUS "Tight Inclusion: Limiting maximal queue size") |
| 119 | + target_compile_definitions(tight_inclusion PUBLIC TIGHT_INCLUSION_LIMIT_QUEUE_SIZE) |
81 | 120 | endif() |
82 | 121 |
|
83 | 122 | if(TIGHT_INCLUSION_FLOAT_WITH_DOUBLE_INPUT) |
84 | | - target_compile_definitions(tight_inclusion PUBLIC TIGHT_INCLUSION_FWDI) |
85 | | - message(STATUS "Converting double inputs to float for tests") |
| 123 | + message(STATUS "Tight Inclusion: Converting double inputs to float for tests") |
| 124 | + target_compile_definitions(tight_inclusion PUBLIC TIGHT_INCLUSION_FWDI) |
86 | 125 | endif() |
87 | | -target_compile_definitions(tight_inclusion PUBLIC NOMINMAX) |
88 | 126 |
|
89 | | -if(TIGHT_INCLUSION_TOPLEVEL_PROJECT) |
90 | | - #message(STATUS "Tight-Inclusion CCD top-level project") |
91 | | - if (TIGHT_INCLUSION_WITH_TESTS) |
92 | | - add_executable(Tight_Inclusion_bin |
93 | | - app/main.cpp |
94 | | - app/read_rational_csv.cpp |
95 | | - ) |
96 | | - else() |
97 | | - add_executable(Tight_Inclusion_bin app/main.cpp) |
98 | | - endif() |
| 127 | +################################################################################ |
| 128 | +# Compiler options |
| 129 | +################################################################################ |
| 130 | + |
| 131 | +# Figure out AVX level support |
| 132 | +message(STATUS "Searching for AVX...") |
| 133 | +find_package(AVX) |
| 134 | +string(REPLACE " " ";" SIMD_FLAGS "${AVX_FLAGS}") |
| 135 | +target_compile_options(tight_inclusion PRIVATE ${SIMD_FLAGS}) |
99 | 136 |
|
100 | | - target_link_libraries(Tight_Inclusion_bin PUBLIC tight_inclusion) |
| 137 | +# Use C++17 |
| 138 | +target_compile_features(tight_inclusion PUBLIC cxx_std_17) |
101 | 139 |
|
102 | | - ticcd_download_sample_queries() |
| 140 | +################################################################################ |
| 141 | +# App |
| 142 | +################################################################################ |
103 | 143 |
|
104 | | - if (NOT TIGHT_INCLUSION_WITH_GMP AND TIGHT_INCLUSION_WITH_TESTS) |
105 | | - target_link_libraries(tight_inclusion PUBLIC gmp::gmp) |
106 | | - target_compile_definitions(tight_inclusion PUBLIC TIGHT_INCLUSION_RUN_EXAMPLES) |
107 | | - target_compile_definitions(Tight_Inclusion_bin PUBLIC |
108 | | - TICCD_EXAMPLE_QUERIES_DIR="${CMAKE_CURRENT_SOURCE_DIR}/external/Sample-Queries/") |
109 | | - endif() |
| 144 | +if(TIGHT_INCLUSION_TOPLEVEL_PROJECT) |
| 145 | + add_executable(Tight_Inclusion_bin "app/main.cpp") |
| 146 | + target_link_libraries(Tight_Inclusion_bin PUBLIC tight_inclusion) |
| 147 | + |
| 148 | + set(TIGHT_INCLUSION_SAMPLE_QUERIES_DIR "${PROJECT_SOURCE_DIR}/sample-queries") |
| 149 | + include(sample_queries) |
| 150 | + |
| 151 | + if(TIGHT_INCLUSION_SUPPRESS_PROGRESS_OUTPUT) |
| 152 | + target_compile_definitions(Tight_Inclusion_bin PUBLIC TIGHT_INCLUSION_SUPPRESS_PROGRESS_OUTPUT) |
| 153 | + endif() |
| 154 | + |
| 155 | + if (TIGHT_INCLUSION_WITH_TESTS) |
| 156 | + target_sources(Tight_Inclusion_bin PUBLIC "app/read_rational_csv.cpp") |
| 157 | + target_compile_definitions(Tight_Inclusion_bin PUBLIC TIGHT_INCLUSION_RUN_EXAMPLES) |
| 158 | + target_compile_definitions(Tight_Inclusion_bin PUBLIC |
| 159 | + TIGHT_INCLUSION_SAMPLE_QUERIES_DIR="${TIGHT_INCLUSION_SAMPLE_QUERIES_DIR}/") |
| 160 | + endif() |
110 | 161 | endif() |
0 commit comments