|
1 | 1 | cmake_minimum_required(VERSION 3.22) |
2 | 2 |
|
3 | | -project(highmap-root) |
| 3 | +# ----------------------------------------------------------------------------- |
| 4 | +# Optional: force clang Usage: cmake -B build -DCMAKE_C_COMPILER=clang |
| 5 | +# -DCMAKE_CXX_COMPILER=clang++ |
| 6 | +# ----------------------------------------------------------------------------- |
| 7 | + |
| 8 | +project(highmap-root LANGUAGES C CXX) |
| 9 | + |
| 10 | +# ----------------------------------------------------------------------------- |
| 11 | +# Options |
| 12 | +# ----------------------------------------------------------------------------- |
4 | 13 |
|
5 | 14 | option(HIGHMAP_ENABLE_OPENCL "" ON) |
6 | 15 | option(HIGHMAP_ENABLE_EXAMPLES "" ON) |
7 | 16 | option(HIGHMAP_ENABLE_TESTS "" ON) |
| 17 | +option(HIGHMAP_ENABLE_BENCHMARKS "" ON) |
| 18 | + |
| 19 | +# ----------------------------------------------------------------------------- |
| 20 | +# C++ |
| 21 | +# ----------------------------------------------------------------------------- |
8 | 22 |
|
9 | 23 | set(CMAKE_CXX_STANDARD 20) |
| 24 | +set(CMAKE_CXX_STANDARD_REQUIRED ON) |
| 25 | +set(CMAKE_CXX_EXTENSIONS OFF) |
| 26 | + |
| 27 | +# ----------------------------------------------------------------------------- |
| 28 | +# Compiler flags |
| 29 | +# ----------------------------------------------------------------------------- |
| 30 | + |
| 31 | +if(MSVC) |
| 32 | + |
| 33 | + message(STATUS "Compiler: MSVC") |
| 34 | + |
| 35 | + add_definitions(-DHMAP_MSVC) |
| 36 | + |
| 37 | + add_compile_options(/W4 /Od) |
| 38 | + |
| 39 | + add_compile_definitions(M_PI=3.14159265358979323846) |
| 40 | + |
| 41 | +elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") |
| 42 | + |
| 43 | + message(STATUS "Compiler: Clang") |
| 44 | + |
| 45 | + add_compile_options( |
| 46 | + -Wall |
| 47 | + -Wextra |
| 48 | + -Wpedantic |
| 49 | + -O3 |
| 50 | + -Ofast |
| 51 | + -ffast-math |
| 52 | + -pthread |
| 53 | + -fPIC |
| 54 | + -Wno-deprecated-enum-enum-conversion) |
| 55 | + |
| 56 | + add_compile_definitions(LOG_LEVEL=3) |
| 57 | + |
| 58 | +elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") |
| 59 | + |
| 60 | + message(STATUS "Compiler: GCC") |
| 61 | + |
| 62 | + add_compile_options( |
| 63 | + -Wall |
| 64 | + -Wextra |
| 65 | + -O3 |
| 66 | + -Ofast |
| 67 | + -ffast-math |
| 68 | + -pthread |
| 69 | + -fPIC |
| 70 | + -Wno-free-nonheap-object |
| 71 | + -Wno-deprecated-enum-enum-conversion) |
| 72 | + |
| 73 | + add_compile_definitions(LOG_LEVEL=3) |
10 | 74 |
|
11 | | -if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") |
12 | | - # MSVC compiler options |
13 | | - set(CMAKE_CXX_FLAGS |
14 | | - "${CMAKE_CXX_FLAGS} /W4 /Od /D M_PI=3.14159265358979323846") |
15 | | - |
16 | | - message(STATUS "MSVC compiler...") |
17 | | - add_definitions("-DHMAP_MSVC") |
18 | | -else() |
19 | | - # GNU compiler options |
20 | | - set(CMAKE_CXX_FLAGS |
21 | | - "${CMAKE_CXX_FLAGS} -Wall -Wextra -O3 -Ofast -ffast-math -pthread -fPIC -DLOG_LEVEL=3 -Wno-free-nonheap-object -Wno-deprecated-enum-enum-conversion" |
22 | | - ) |
23 | 75 | endif() |
24 | 76 |
|
| 77 | +# ----------------------------------------------------------------------------- |
| 78 | +# Output |
| 79 | +# ----------------------------------------------------------------------------- |
| 80 | + |
25 | 81 | set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin) |
26 | 82 |
|
27 | | -# --- dependencies |
| 83 | +# ----------------------------------------------------------------------------- |
| 84 | +# Dependencies |
| 85 | +# ----------------------------------------------------------------------------- |
28 | 86 |
|
29 | 87 | find_package(GSL REQUIRED COMPONENTS gsl gslcblas) |
30 | 88 | find_package(assimp REQUIRED) |
31 | 89 | find_package(glm REQUIRED) |
32 | 90 | find_package(OpenMP REQUIRED) |
33 | 91 | find_package(OpenCV REQUIRED) |
34 | 92 | find_package(OpenCL REQUIRED) |
| 93 | + |
35 | 94 | include_directories(${OpenCV_INCLUDE_DIRS}) |
36 | 95 |
|
37 | | -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}") |
| 96 | +# OpenMP |
| 97 | +add_compile_options(${OpenMP_CXX_FLAGS}) |
38 | 98 |
|
| 99 | +# OpenCL |
39 | 100 | add_compile_definitions(CL_HPP_MINIMUM_OPENCL_VERSION=120 |
40 | 101 | CL_HPP_TARGET_OPENCL_VERSION=120) |
41 | 102 |
|
| 103 | +# ----------------------------------------------------------------------------- |
| 104 | +# External libs |
| 105 | +# ----------------------------------------------------------------------------- |
| 106 | + |
42 | 107 | add_subdirectory(external) |
43 | 108 |
|
44 | | -# --- library |
| 109 | +# ----------------------------------------------------------------------------- |
| 110 | +# Library |
| 111 | +# ----------------------------------------------------------------------------- |
45 | 112 |
|
46 | 113 | add_subdirectory(HighMap) |
47 | 114 |
|
48 | | -# --- everything else... |
| 115 | +# ----------------------------------------------------------------------------- |
| 116 | +# Examples |
| 117 | +# ----------------------------------------------------------------------------- |
49 | 118 |
|
50 | 119 | if(HIGHMAP_ENABLE_EXAMPLES) |
51 | | - add_subdirectory(${PROJECT_SOURCE_DIR}/examples) |
| 120 | + add_subdirectory(examples) |
52 | 121 | endif() |
53 | 122 |
|
| 123 | +# ----------------------------------------------------------------------------- |
| 124 | +# Tests |
| 125 | +# ----------------------------------------------------------------------------- |
| 126 | + |
54 | 127 | if(HIGHMAP_ENABLE_TESTS) |
55 | 128 | message(STATUS "HighMap tests enabled") |
56 | | - add_subdirectory(${PROJECT_SOURCE_DIR}/tests) |
| 129 | + add_subdirectory(tests) |
| 130 | +endif() |
| 131 | + |
| 132 | +# ----------------------------------------------------------------------------- |
| 133 | +# Benchmarks |
| 134 | +# ----------------------------------------------------------------------------- |
| 135 | + |
| 136 | +if(HIGHMAP_ENABLE_BENCHMARKS) |
| 137 | + message(STATUS "HighMap benchmarks enabled") |
| 138 | + add_subdirectory(benchmarks) |
57 | 139 | endif() |
0 commit comments