-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathCMakeLists.txt
executable file
·91 lines (71 loc) · 3.06 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
cmake_minimum_required(VERSION 3.16)
set(LIB_NAME EventEMin)
project(${LIB_NAME} LANGUAGES CXX)
# C++ version
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/bin)
set(LIBRARY_OUTPUT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/lib)
set(${LIB_NAME}_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/include)
set(${LIB_NAME}_SOURCE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/src)
set(${LIB_NAME}_TEST_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/test)
# CXX flags
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wpedantic -march=native -mtune=native")
# Default to Release
set(DEFAULT_BUILD_TYPE "Release")
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
message(STATUS "Setting build type to '${DEFAULT_BUILD_TYPE}' as none was specified.")
set(CMAKE_BUILD_TYPE "${DEFAULT_BUILD_TYPE}" CACHE STRING "Choose the type of build." FORCE)
# Set the possible values of build type for cmake-gui
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS
"Debug" "Release" "MinSizeRel" "RelWithDebInfo")
endif()
# Dependencies
# OpenMP
option(${LIB_NAME}_USE_OPENMP "If available, use OpenMP for parallelization." ON)
if(${LIB_NAME}_USE_OPENMP)
find_package(OpenMP)
endif()
if(OPENMP_FOUND)
message("OpenMP found")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unknown-pragmas")
endif()
# Eigen
find_package(Eigen3 3.3 REQUIRED NO_MODULE)
# OpenCV
find_package(OpenCV REQUIRED)
# Build library
add_library(${LIB_NAME} INTERFACE)
# Build batch mode
option(${LIB_NAME}_BATCH_MODE "Use batch mode." OFF)
if(${LIB_NAME}_BATCH_MODE)
# gsl
find_package(GSL REQUIRED)
# interface batch lib
add_library(${LIB_NAME}_BATCH_LIB INTERFACE)
target_include_directories(${LIB_NAME}_BATCH_LIB INTERFACE ${${LIB_NAME}_INCLUDE_DIRS} ${GSL_INCLUDE_DIRS} ${OpenCV_INCLUDE_DIRS})
target_link_libraries(${LIB_NAME}_BATCH_LIB INTERFACE ${GSL_LIBRARIES} Eigen3::Eigen ${OpenCV_LIBS})
target_compile_definitions(${LIB_NAME} INTERFACE ${LIB_NAME}_BATCH_MODE)
target_link_libraries(${LIB_NAME} INTERFACE ${LIB_NAME}_BATCH_LIB)
endif()
# Build incremental mode
option(${LIB_NAME}_INCREMENTAL_MODE "Use incremental mode." OFF)
if(${LIB_NAME}_INCREMENTAL_MODE)
# interface incremental lib
add_library(${LIB_NAME}_INCREMENTAL_LIB INTERFACE)
target_include_directories(${LIB_NAME}_INCREMENTAL_LIB INTERFACE ${${LIB_NAME}_INCLUDE_DIRS} ${OpenCV_INCLUDE_DIRS})
target_link_libraries(${LIB_NAME}_INCREMENTAL_LIB INTERFACE Eigen3::Eigen ${OpenCV_LIBS})
target_compile_definitions(${LIB_NAME} INTERFACE ${LIB_NAME}_INCREMENTAL_MODE)
target_link_libraries(${LIB_NAME} INTERFACE ${LIB_NAME}_INCREMENTAL_LIB)
endif()
# Option for fast exp computation
option(${LIB_NAME}_FAST_EXP "Enable fast exp" ON)
if(${LIB_NAME}_FAST_EXP)
target_compile_definitions(${LIB_NAME} INTERFACE ${LIB_NAME}_FAST_EXP)
endif()
add_subdirectory(${${LIB_NAME}_SOURCE_DIRS})
add_subdirectory(${${LIB_NAME}_TEST_DIRS})