-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCMakeLists.txt
122 lines (100 loc) · 4.07 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
cmake_minimum_required(VERSION 3.14)
# Create the new project
project(Enumerator VERSION 0.1.3)
# Set the standards
set(CMAKE_CXX_STANDARD 17)
# Create the project
add_library(enumeratorLibrary SHARED)
# FetContent will allow downloading of other libraries
include(FetchContent)
# make cache variables for install destinations
include(GNUInstallDirs)
# Build a stand alone executable
add_executable(enumerator main.cpp)
target_link_libraries(enumerator PRIVATE enumeratorLibrary)
# Load in the source code
add_subdirectory(src)
# Allow public access to the header files in the directory
target_include_directories(enumeratorLibrary PUBLIC
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>/src"
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>")
# Get the CPP dependency
FetchContent_Declare(
cppParser
GIT_REPOSITORY https://github.com/UBCHREST/CppParser.git
GIT_TAG v0.2.3
)
FetchContent_MakeAvailable(cppParser)
# load in the build/compiler standards
FetchContent_Declare(
chrestCompilerFlags
GIT_REPOSITORY https://github.com/UBCHREST/chrestCompilerFlags.git
GIT_TAG main
)
FetchContent_MakeAvailable(chrestCompilerFlags)
# Link to the enumeratorLibrary
target_link_libraries(enumeratorLibrary PUBLIC yaml-cpp cppParserLibrary PRIVATE chrestCompilerFlags)
# Check if we should enable testing options
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
set_property(GLOBAL PROPERTY CTEST_TARGETS_ADDED 1)
include(CTest)
# Include the format command only if we are the main project
include(clangFormatter.cmake)
# Setup and configure testing
if(BUILD_TESTING)
enable_testing()
include(GoogleTest)
add_subdirectory(tests)
endif()
endif()
# install the enumerator (and others) target and create export-set
include(cmakeFunctions.cmake)
install(TARGETS enumerator enumeratorLibrary cppParserLibrary yaml-cpp chrestCompilerFlags
EXPORT enumeratorTargets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
set_target_properties(enumerator PROPERTIES INSTALL_RPATH_USE_LINK_PATH TRUE)
# install header file(s)
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/src/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} FILES_MATCHING PATTERN "*.hpp")
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/src/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} FILES_MATCHING PATTERN "*.h")
update_header_paths_for_install(enumeratorLibrary ${PROJECT_SOURCE_DIR}/src ${CMAKE_INSTALL_INCLUDEDIR})
# generate and install export file
install(EXPORT enumeratorTargets
FILE enumeratorTargets.cmake
NAMESPACE CHREST::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/enumerator
)
# generate the version file for the config file
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/enumeratorConfigVersion.cmake"
VERSION "${CMAKE_PROJECT_VERSION}"
COMPATIBILITY AnyNewerVersion
)
# create config file
configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/Config.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/enumeratorConfig.cmake"
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/enumerator
)
# install config files
install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/enumeratorConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/enumeratorConfigVersion.cmake"
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/enumerator
)
# generate the export targets for the build tree
export(EXPORT enumeratorTargets
FILE "${CMAKE_CURRENT_BINARY_DIR}/cmake/enumeratorTargets.cmake"
NAMESPACE CHREST::
)
## update the install rpaths
if (APPLE)
set(CMAKE_MACOSX_RPATH 1)
set_target_properties(enumerator PROPERTIES
INSTALL_RPATH "@loader_path;@loader_path/...;@executable_path;@executable_path/../${CMAKE_INSTALL_LIBDIR};@rpath")
elseif (UNIX)
set_target_properties(enumerator PROPERTIES
INSTALL_RPATH "$ORIGIN:$ORIGIN/../${CMAKE_INSTALL_LIBDIR}:$ORIGIN/...")
endif ()