-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
115 lines (96 loc) · 4.04 KB
/
CMakeLists.txt
File metadata and controls
115 lines (96 loc) · 4.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
cmake_minimum_required(VERSION 3.24)
set(CMAKE_OSX_SYSROOT "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk")
project(dllib VERSION 1.0.0 LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# to link shared libs. TODO: can we get rid of this, as it may cost runtime?
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(PYTHON_MODULE_DIR "${CMAKE_SOURCE_DIR}/python_lib/dl_lib/_compiled")
# to enable find boost, see https://stackoverflow.com/a/79147222
if(POLICY CMP0167)
cmake_policy(SET CMP0167 NEW)
endif()
find_package(Boost REQUIRED COMPONENTS python3)
if(MINGW)
set(CMAKE_EXE_LINKER_FLAGS "-static -static-libgcc")
endif()
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif()
add_compile_options("$<$<C_COMPILER_ID:MSVC>:/utf-8>")
add_compile_options("$<$<CXX_COMPILER_ID:MSVC>:/utf-8>")
# TODO: add flag for double precision?
# include python libs
if(APPLE)
message("Getting PythonLibs on Apple (MacOSX) path")
set(CMAKE_FIND_FRAMEWORK NEVER)
find_package(Python 3 REQUIRED COMPONENTS Interpreter Development)
message("Python_VERSION:${Python_VERSION}")
message("Python_LIBRARIES:${Python_LIBRARIES}")
message("Python_INCLUDE_DIRS:${${Python_INCLUDE_DIRS}}")
set(PYTHON_LIBRARIES ${Python_LIBRARIES})
string(COMPARE EQUAL "${Python_LIBRARIES}" "" PYTHONLIBS_EMPTY)
if(PYTHONLIBS_EMPTY)
message(FATAL_ERROR "Problem: PYTHON_LIBRARIES not found. Do you have Python installed on your machine?")
endif()
string(COMPARE EQUAL "${Python_INCLUDE_DIRS}" "" PYTHONDIRS_EMPTY)
if(PYTHONDIRS_EMPTY)
message("Failed to automatically find Python_INCLUDE_DIRS. Setting the PYTHON_INCLUDE_DIRS variable manually. If this crashes please adjust the following
path to the path where Python.h resides (the one matching the found Python instance). Paths must be consistent iff multiple Python versions on machine.")
set(PYTHON_H_PATH "/usr/local/opt/python@3.13/Frameworks/Python.framework/Versions/3.13/include/python3.13")
set(PYTHON_INCLUDE_DIRS "${Python_H_PATH}")
else()
set(PYTHON_INCLUDE_DIRS ${Python_INCLUDE_DIRS})
endif()
#FindPython3()
message("Apple - Using Python:${Python_VERSION_MAJOR} - Libraries:${Python_LIBRARIES} - IncludeDirs: ${Python_INCLUDE_DIRS}")
else()
message("Getting PythonLibs on Linux or Windows path")
find_package(Python 3 REQUIRED COMPONENTS Interpreter Development)
endif()
include_directories(${Python_INCLUDE_DIRS})
message("Using Python:${Python_VERSION_MAJOR} - Libraries:${Python_LIBRARIES} - IncludeDirs: ${Python_INCLUDE_DIRS}")
#set(CMAKE_MESSAGE_LOG_LEVEL WARNING)
# Default compiler flags:
# Set type with: -DCMAKE_BUILD_TYPE=Debug
# Default is Release, set in line 9 of this file.
# Release:
# -O3 (Be fast)
# -DNDEBUG (Disable assert)
# Debug:
# -g (Debug symbols)
# https://stackoverflow.com/a/24767451/8477066
# Extra:
# -D_GLIBCXX_DEBUG Use safe STD (with bounds checking etc).
# -ggdb3 Add extra information for gdb debugger.
# -g Also for Release, it only makes binary bigger and is still useful in practise.
# -UDEBUG Removes #ifdef DEBUG SOME_DEBUG_CODE #endif for your own debug code.
if (MSVC)
add_compile_options("/W4" "$<$<CONFIG:RELEASE>:/O2>")
elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(
"$<$<CONFIG:RELEASE>:-g;-UDEBUG>"
"$<$<CONFIG:DEBUG>:-ggdb3;-D_GLIBCXX_DEBUG>")
else()
add_compile_options(
"$<$<CONFIG:RELEASE>:-g;-UDEBUG>"
"$<$<CONFIG:DEBUG>:-ggdb3;-D_GLIBCXX_DEBUG>"
"-fcompare-debug-second") # This flag is only for me, to suppress notes
endif()
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang|GNU")
add_compile_options(
-Wreturn-type # Specifically catch missing returns
)
endif()
include_directories("${PROJECT_SOURCE_DIR}/src"
"${PROJECT_SOURCE_DIR}/examples")
add_subdirectory(src)
option(BUILD_TESTS "Build tests" OFF)
if(BUILD_TESTS)
enable_testing()
add_subdirectory(tests)
endif()
option(BUILD_BENCHMARKS "Build benchmarks" OFF)
if(BUILD_BENCHMARKS)
add_subdirectory(benchmarks)
endif()