-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
76 lines (61 loc) · 2.75 KB
/
CMakeLists.txt
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
cmake_minimum_required(VERSION 3.1)
project(psydapt)
set(PSYDAPT_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include)
file(STRINGS "${PSYDAPT_INCLUDE_DIR}/config.hpp" psydapt_version_defines
REGEX "#define PSYDAPT_VERSION_(MAJOR|MINOR|PATCH)")
foreach(ver ${psydapt_version_defines})
if(ver MATCHES "#define PSYDAPT_VERSION_(MAJOR|MINOR|PATCH) +([^ ]+)$")
set(PSYDAPT_VERSION_${CMAKE_MATCH_1} "${CMAKE_MATCH_2}" CACHE INTERNAL "")
endif()
endforeach()
set(${PROJECT_NAME}_VERSION
${PSYDAPT_VERSION_MAJOR}.${PSYDAPT_VERSION_MINOR}.${PSYDAPT_VERSION_PATCH})
message(STATUS "Building psydapt v${${PROJECT_NAME}_VERSION}")
set(CMAKE_CXX_STANDARD 17) # std::optional (and many other things)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
include_directories(${CMAKE_CURRENT_BINARY_DIR})
set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/modules/" ${CMAKE_MODULE_PATH})
add_subdirectory(submodules)
option(PSYDAPT_BUILD_TESTS "Build unit tests" OFF)
option(PSYDAPT_BUILD_SCRATCH "Build scratch files" OFF)
option(PSYDAPT_DISABLE_EXCEPTIONS "Disable use of C++ exceptions" OFF)
option(PSYDAPT_FAST_MATH "Use fast math" OFF)
if (PSYDAPT_DISABLE_EXCEPTIONS)
add_definitions(-DPSYDAPT_DISABLE_EXCEPTIONS)
endif()
add_library(psydapt INTERFACE)
target_link_libraries(psydapt INTERFACE xtensor)
#set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3 -mavx2 -ffast-math -funroll-loops")
# can't tell whether ffast-math actually makes a difference...
if (PSYDAPT_FAST_MATH)
if((CMAKE_CXX_COMPILER_ID MATCHES "Clang") OR (CMAKE_CXX_COMPILER_ID MATCHES "GNU"))
add_compile_options(-ffast-math)
elseif(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
add_compile_options(/fp:fast)
endif()
endif()
target_include_directories(psydapt
INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
${xtensor_INCLUDE_DIRS}
)
target_compile_features(${PROJECT_NAME} INTERFACE cxx_std_17)
# just temporary test files
set(PSYDAPT_SCRATCH_DIR "${PROJECT_SOURCE_DIR}/scratch/")
if (PSYDAPT_BUILD_SCRATCH)
add_executable(Test ${PSYDAPT_SCRATCH_DIR}/test.cpp)
target_link_libraries(Test PUBLIC psydapt)
add_executable(TestQP ${PSYDAPT_SCRATCH_DIR}/test_quest.cpp)
target_link_libraries(TestQP PUBLIC psydapt)
add_executable(XTensScratch ${PSYDAPT_SCRATCH_DIR}/xtensor_scratch.cpp)
target_link_libraries(XTensScratch PUBLIC psydapt)
add_executable(TestCSF ${PSYDAPT_SCRATCH_DIR}/test_csf.cpp)
target_link_libraries(TestCSF PUBLIC psydapt)
add_executable(XTensScratch ${PSYDAPT_SCRATCH_DIR}/xtensor_scratch.cpp)
target_link_libraries(XTensScratch PUBLIC psydapt)
endif()
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND PSYDAPT_BUILD_TESTS AND NOT EMSCRIPTEN)
enable_testing()
add_subdirectory(tests)
endif()