-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathCMakeLists.txt
108 lines (82 loc) · 2.89 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
cmake_minimum_required( VERSION 3.17 ) # Require CMake 3.17+
# Set up project definition + version information
project( IntegratorXX VERSION 1.2.0 LANGUAGES CXX )
option(INTEGRATORXX_HEADER_ONLY "Force header-only build" OFF)
if(INTEGRATORXX_HEADER_ONLY)
add_library( integratorxx INTERFACE )
set(INTEGRATORXX_TARGET_TYPE INTERFACE)
else()
add_subdirectory(src)
set(INTEGRATORXX_TARGET_TYPE PUBLIC)
endif()
# Target features
target_compile_features( integratorxx ${INTEGRATORXX_TARGET_TYPE} cxx_std_17 )
target_include_directories( integratorxx
${INTEGRATORXX_TARGET_TYPE}
$<INSTALL_INTERFACE:include>
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
)
include(CheckCXXCompilerFlag)
check_cxx_compiler_flag("-Wno-missing-braces" INTEGRATORXX_HAS_NO_MISSING_BRACES )
if( INTEGRATORXX_HAS_NO_MISSING_BRACES )
target_compile_options( integratorxx INTERFACE $<$<COMPILE_LANGUAGE:CXX>: -Wno-missing-braces> )
endif()
# INSTALL rules
add_library( IntegratorXX::IntegratorXX ALIAS integratorxx )
include( GNUInstallDirs )
set( INSTALL_CONFIGDIR ${CMAKE_INSTALL_LIBDIR}/cmake/IntegratorXX )
# Targets
install(TARGETS integratorxx
EXPORT integratorxx-targets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
set_target_properties( integratorxx PROPERTIES EXPORT_NAME IntegratorXX )
# Install Headers
install(DIRECTORY ${PROJECT_SOURCE_DIR}/include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} )
# Export target to script
install(EXPORT integratorxx-targets
FILE
IntegratorXXTargets.cmake
NAMESPACE
IntegratorXX::
DESTINATION
${INSTALL_CONFIGDIR}
)
# Export build-tree targets also (e.g. to be usable by FetchContent)
export(EXPORT integratorxx-targets
NAMESPACE IntegratorXX::
FILE "${PROJECT_BINARY_DIR}/IntegratorXXTargets.cmake")
# Create a ConfigVersion.cmake file
include(CMakePackageConfigHelpers)
write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/IntegratorXXConfigVersion.cmake
VERSION ${PROJECT_VERSION}
COMPATIBILITY AnyNewerVersion
)
# Setup IntegratorXXConfig.cmake
configure_package_config_file(${PROJECT_SOURCE_DIR}/cmake/IntegratorXXConfig.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/IntegratorXXConfig.cmake
INSTALL_DESTINATION ${INSTALL_CONFIGDIR}
)
#Install the config, configversion and custom find modules
install(DIRECTORY
${PROJECT_SOURCE_DIR}/cmake/
DESTINATION ${INSTALL_CONFIGDIR}
FILES_MATCHING PATTERN "*.cmake"
)
install(FILES
${CMAKE_CURRENT_BINARY_DIR}/IntegratorXXConfig.cmake
${CMAKE_CURRENT_BINARY_DIR}/IntegratorXXConfigVersion.cmake
DESTINATION ${INSTALL_CONFIGDIR}
)
# Testing
if( NOT DEFINED INTEGRATORXX_ENABLE_TESTS )
set( INTEGRATORXX_ENABLE_TESTS ON )
endif()
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
include(CTest)
endif()
if( CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND INTEGRATORXX_ENABLE_TESTS AND BUILD_TESTING )
add_subdirectory( test )
endif()