-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
224 lines (187 loc) · 6.87 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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
cmake_minimum_required(VERSION 3.14 FATAL_ERROR)
project(Rag VERSION 0.1 LANGUAGES CXX)
set(PROJECT_NAME_L rag)
# -----------------------------------------------------------------------------
# Build settings
# -----------------------------------------------------------------------------
# Set the C standard
# ------------------
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_C_EXTENSIONS OFF)
# Set the C++ standard
# --------------------
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
# Options
# -------
OPTION(BUILD_SHARED_LIBS "Build shared libraries" OFF)
OPTION(USE_ONLY_STATIC_LIBS "Use only static library dependencies" OFF)
OPTION(BUILD_TESTING "Build the testing tree" ON)
OPTION(ENABLE_COVERAGE "Enable code coverage reporting. Also enables testing" OFF)
OPTION(BUILD_SAMPLES "Build sample applications" ON)
# Include additional cmake/ settings
set(CMAKE_MODULE_PATH
"${CMAKE_CURRENT_SOURCE_DIR}/cmake"
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules"
)
set(CMAKE_BINARY_DIR "${CMAKE_CURRENT_SOURCE_DIR}/build")
# Include CMake modules
include(BuildLocation)
include(BuildType)
include(ClangFormat)
include(CodeAnalysis)
include(CompilerFlags)
# -----------------------------------------------------------------------------
# Create and set target properties
# -----------------------------------------------------------------------------
message(STATUS "Setting target properties")
# Set the library sources
# -----------------------
set(libsrc
src/rag.cpp
)
# Add the library
# ---------------
# Build shared or static libraries
if(BUILD_SHARED_LIBS)
add_library(${PROJECT_NAME_L} OBJECT ${libsrc})
add_library(${PROJECT_NAME_L} SHARED $<TARGET_OBJECTS:objlib>)
else()
add_library(${PROJECT_NAME_L} STATIC ${libsrc})
endif()
# Create an alias
add_library(${PROJECT_NAME}::${PROJECT_NAME_L} ALIAS ${PROJECT_NAME_L})
# Include project directories in target
# -------------------------------------
target_include_directories(${PROJECT_NAME_L}
PUBLIC
$<INSTALL_INTERFACE:include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/src
)
add_target_compiler_flags(${PROJECT_NAME_L})
message(STATUS "Setting target properties - done")
# -----------------------------------------------------------------------------
# Locate and link external libraries
# -----------------------------------------------------------------------------
message(STATUS "Linking external libraries")
if(USE_ONLY_STATIC_LIBS) # Use only static libraries
if(UNIX)
set(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
elseif(WIN32)
set(CMAKE_FIND_LIBRARY_SUFFIXES ".lib")
endif()
endif()
# Hold the project's export targets
set(PROJECT_EXPORT_TARGETS ${PROJECT_NAME_L})
# Add include directories to the target
target_include_directories(${PROJECT_NAME_L}
PRIVATE
#${CMAKE_CURRENT_SOURCE_DIR}/libs/ExternalProj/include
)
# Add sub-directories to the build
#add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/libs/ExternalProj)
# Link libraries against the project
#target_link_libraries(${PROJECT_NAME_L}
# PRIVATE
# externalproj
#)
# Append library targets to export targets as necessary
#list(APPEND PROJECT_EXPORT_TARGETS externalproj)
message(STATUS "Linking external libraries - done")
# -----------------------------------------------------------------------------
# Installation instructions
# -----------------------------------------------------------------------------
# Generates installation rules used to implement 'make install' and packaging
# Installing makes a package generally available to the users of the system by
# installing its components into a well-known prefix (e.g. /usr, /usr/local)
include(GNUInstallDirs)
set(INSTALL_CONFIGDIR ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME})
# Create a a version file for the project from the cmake/ configversion file
include(CMakePackageConfigHelpers)
write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake # output
VERSION ${PROJECT_VERSION}
COMPATIBILITY AnyNewerVersion
)
# Create a config file for the project from the cmake/ config file
configure_package_config_file(
${CMAKE_CURRENT_LIST_DIR}/cmake/${PROJECT_NAME}Config.cmake.in # input
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake # output
INSTALL_DESTINATION # Where the config file will be installed
${INSTALL_CONFIGDIR}
)
# Install the <package>Config.cmake and <package>ConfigVersion.cmake files
install(
FILES
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
DESTINATION
${INSTALL_CONFIGDIR}
)
# Add the library to the "export-set"
# Specifies rules for installing targets from a project
install(
TARGETS
${PROJECT_EXPORT_TARGETS}
EXPORT # Associate installed target files with the export
${PROJECT_NAME_L}-targets
LIBRARY
DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE
DESTINATION ${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
set_target_properties(${PROJECT_NAME_L} PROPERTIES EXPORT_NAME ${PROJECT_NAME})
# Installs contents of include/ to the destination directory
install(
DIRECTORY
include/
DESTINATION
${CMAKE_INSTALL_INCLUDEDIR}
)
# Generates and installs a CMake file for importing targets from the install
# tree to other projects
# What is installed by 'make install'
install(
EXPORT # Install the export file itself
${PROJECT_NAME_L}-targets
FILE # Specify name of generated file
${PROJECT_NAME}Targets.cmake
NAMESPACE # Prepend to the target name
${PROJECT_NAME}:: # ${PROJECT_NAME}::${PROJECT_NAME_L}
DESTINATION # Where to install
${INSTALL_CONFIGDIR}
)
# -----------------------------------------------------------------------------
# Export from the build tree
# -----------------------------------------------------------------------------
# Allows use of find_package without the use of a find module
# Create a file that may be included by outside project to import targets from
# the current project's build tree
export(
EXPORT # Export file generated by install(TARGETS)
${PROJECT_NAME_L}-targets
FILE
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Targets.cmake
NAMESPACE
${PROJECT_NAME}
)
# Register package
export(PACKAGE ${PROJECT_NAME})
# -----------------------------------------------------------------------------
# Testing, samples, and code coverage
# -----------------------------------------------------------------------------
if(BUILD_TESTING OR ENABLE_COVERAGE) # Handles code coverage
# Enable construction of test target
include(CTest)
enable_testing()
add_subdirectory(tests)
endif()
if(BUILD_SAMPLES)
add_subdirectory(samples)
endif()