-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
121 lines (102 loc) · 3.33 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
cmake_minimum_required(VERSION 3.10)
project(moptimizer VERSION 0.1 LANGUAGES CXX)
set (CMAKE_CXX_STANDARD 17)
option(BUILD_TESTS "Build test programs" OFF)
option(BUILD_EXPERIMENTAL "Build experimental programs" OFF)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release" CACHE STRING
"Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel."
FORCE)
endif(NOT CMAKE_BUILD_TYPE)
find_package(Eigen3 REQUIRED)
find_package(TBB REQUIRED)
link_libraries(Eigen3::Eigen)
if(UNIX)
if(CMAKE_BUILD_TYPE STREQUAL "Release" AND NOT APPLE)
# TMP COMMENT
add_compile_options(-march=native)
endif()
elseif(MSVC)
add_compile_options(/bigobj)
add_compile_definitions(_USE_MATH_DEFINES)
endif()
set (CMAKE_EXPORT_COMPILE_COMMANDS ON)
# Library
add_library(${PROJECT_NAME} SHARED
src/levenberg_marquadt_dyn.cpp
src/cost_function_analytical_dyn.cpp
src/cost_function_numerical_dyn.cpp
src/delta.cpp
src/so3.cpp
src/exception.cpp
src/logger.cpp
src/linearization.cpp
)
target_link_libraries(${PROJECT_NAME} TBB::tbb)
include (GenerateExportHeader)
generate_export_header(${PROJECT_NAME}
EXPORT_FILE_NAME ${CMAKE_SOURCE_DIR}/include/moptimizer/moptimizer_exports.h)
if(BUILD_EXPERIMENTAL)
add_subdirectory(experimental EXCLUDE_FROM_ALL)
endif()
#gtest
if(BUILD_TESTS)
find_package(GTest REQUIRED)
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
enable_testing()
include(GoogleTest)
file (GLOB tests_srcs ${CMAKE_SOURCE_DIR}/tst/*.cpp)
list (FILTER tests_srcs EXCLUDE REGEX ".draft.cpp")
# Make test cases
add_executable(
optimizer_tests
${tests_srcs}
)
set(test_data_path ${CMAKE_SOURCE_DIR}/tst/data)
# cmake_path(GET some_path ROOT_PATH test_data_path)
message("TEST PATH: ${test_data_path}")
target_compile_definitions(optimizer_tests PRIVATE -DTEST_DATA_PATH="${test_data_path}" )
add_executable(draft
${CMAKE_SOURCE_DIR}/tst/draft.cpp)
target_link_libraries(draft ${PROJECT_NAME})
target_link_libraries(optimizer_tests ${PROJECT_NAME} GTest::gtest GTest::gmock)
gtest_discover_tests(optimizer_tests)
endif()
# Link library to headers, but does not install.
target_include_directories(${PROJECT_NAME} PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)
# --- Installation process --- #
include(GNUInstallDirs)
install(
DIRECTORY include/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
# set(CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_LIBDIR})
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
# Install
install(TARGETS ${PROJECT_NAME}
EXPORT ${PROJECT_NAME}-targets
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
# Targets file
install(
EXPORT ${PROJECT_NAME}-targets
NAMESPACE duna::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}
)
# Version
include(CMakePackageConfigHelpers)
write_basic_package_version_file(
${PROJECT_NAME}Version.cmake
VERSION 1.0.0
COMPATIBILITY SameMajorVersion)
# Config
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/${PROJECT_NAME}-config.cmake.in ${PROJECT_NAME}-config.cmake
@ONLY)
install(FILES
"${CMAKE_BINARY_DIR}/${PROJECT_NAME}-config.cmake"
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Version.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}
)