-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
129 lines (105 loc) · 3.64 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
122
123
124
125
126
127
128
129
cmake_minimum_required(VERSION 3.15)
project(SVGDCpp)
add_compile_options(-Wall -Wextra -Wpedantic)
set(CMAKE_CXX_STANDARD 17)
# Define current version
set(SVGDCPP_VERSION "1.0.0")
# Define variables
set(SVGDCPP_CMAKE_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/share/${PROJECT_NAME}/cmake")
set(SVGDCPP_INCLUDE_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/include/${PROJECT_NAME}") # assign include destination to variable
set(API_DOCUMENTATION_DIR ${CMAKE_INSTALL_PREFIX}/doc/${PROJECT_NAME})
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "" FORCE)
endif()
# Define Release build options
if(CMAKE_BUILD_TYPE MATCHES Release OR CMAKE_CONFIGURATION_TYPES MATCHES Release)
# Check to build documentation
if(BUILD_DOCUMENTATION)
find_package(Doxygen)
if(DOXYGEN_FOUND)
set(DOXYGEN_IN doc/Doxyfile.in)
set(DOXYGEN_OUT ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile)
# Configure the file
configure_file(${DOXYGEN_IN} ${DOXYGEN_OUT} @ONLY)
message(STATUS "Doxygen build started")
# Build doxygen documentation
add_custom_target(Doxygen_documentation ALL
COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYGEN_OUT}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Generating API documentation with Doxygen" VERBATIM
)
# Install built documentation
install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/doc/html DESTINATION ${API_DOCUMENTATION_DIR})
else()
message(WARNING "Doxygen need to be installed to generate the doxygen documentation")
endif()
endif()
endif()
if(CMAKE_BUILD_TYPE MATCHES Debug OR CMAKE_CONFIGURATION_TYPES MATCHES Debug)
# Build tests
enable_testing()
add_subdirectory(tests)
endif()
# Check to build examples
if(BUILD_EXAMPLES)
add_subdirectory(examples)
endif()
# Find dependencies
find_package(Eigen3 CONFIG REQUIRED)
find_package(OpenMP)
find_library(CPPAD_LIB cppad_lib REQUIRED)
# Build library
add_library(${PROJECT_NAME}
INTERFACE
)
target_include_directories(${PROJECT_NAME}
INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include/>
)
if(OpenMP_CXX_FOUND)
target_link_libraries(${PROJECT_NAME}
INTERFACE
${CPPAD_LIB}
Eigen3::Eigen
OpenMP::OpenMP_CXX
)
else()
target_link_libraries(${PROJECT_NAME}
INTERFACE
${CPPAD_LIB}
Eigen3::Eigen
)
endif()
# Install library header files
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/
DESTINATION ${SVGDCPP_INCLUDE_INSTALL_DIR}
)
# Associate library target with an export target
install(TARGETS ${PROJECT_NAME}
EXPORT ${PROJECT_NAME}Targets
)
# Install export target
install(EXPORT ${PROJECT_NAME}Targets
DESTINATION "${SVGDCPP_CMAKE_INSTALL_DIR}" # creates ${CMAKE_INSTALL_PREFIX}/lib/cmake/${PROJECT_NAME}Targets.cmake
NAMESPACE SVGDCpp::
)
# Configure config file
include(CMakePackageConfigHelpers)
configure_package_config_file(cmake/SVGDCppConfig.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
INSTALL_DESTINATION "${SVGDCPP_CMAKE_INSTALL_DIR}"
PATH_VARS SVGDCPP_INCLUDE_INSTALL_DIR
)
# Create config files
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}"
COMPATIBILITY AnyNewerVersion
)
# Install config files
install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
DESTINATION "${SVGDCPP_CMAKE_INSTALL_DIR}"
)