-
Notifications
You must be signed in to change notification settings - Fork 10
/
CMakeLists.txt
263 lines (210 loc) · 8.77 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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
#-----------------------------------------------------------------------------------
# d-SEAMS - Deferred Structural Elucidation Analysis for Molecular Simulations
#
# Copyright (c) 2018--present d-SEAMS core team
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the MIT License as published by
# the Open Source Initiative.
#
# A copy of the MIT License is included in the LICENSE file of this repository.
# You should have received a copy of the MIT License along with this program.
# If not, see <https://opensource.org/licenses/MIT>.
#-----------------------------------------------------------------------------------
# Build system contributed by Rohit Goswami (@HaoZeke)
# <rohit.goswami[at]aol.com>
#
# CMake options
#
# CMake version
cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
set(CMAKE_CXX_STANDARD 17)
# Some Defaults
if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR})
message(
FATAL_ERROR
"Do not build in-source.
Remove CMakeCache.txt and the CMakeFiles/ directory. Then build in a separate folder.
Refer to the docs if needed."
)
endif()
# If CMAKE_BUILD_TYPE is undefined, build the Debug version
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Debug")
endif()
# Use ccache if avaliable
find_program(CCACHE_FOUND ccache)
if(CCACHE_FOUND)
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache)
set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache)
endif(CCACHE_FOUND)
# For rtags
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
#
# Configure CMake environment
#
# Register general cmake commands
include(cmake/Custom.cmake)
# Set policies
set_policy(CMP0054 NEW) # ENABLE CMP0054: Only interpret if() arguments as variables or keywords when unquoted.
set_policy(CMP0042 NEW) # ENABLE CMP0042: MACOSX_RPATH is enabled by default.
set_policy(CMP0063 NEW) # ENABLE CMP0063: Honor visibility properties for all target types.
# Include cmake modules
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
include(GenerateExportHeader)
set(WriterCompilerDetectionHeaderFound NOTFOUND)
# This module is only available with CMake >=3.1, so check whether it could be found
# BUT in CMake 3.1 this module doesn't recognize AppleClang as compiler, so just use it as of CMake 3.2
if (${CMAKE_VERSION} VERSION_GREATER "3.2")
include(WriteCompilerDetectionHeader OPTIONAL RESULT_VARIABLE WriterCompilerDetectionHeaderFound)
endif()
# Include custom cmake modules
include(cmake/Coverage.cmake)
include(cmake/GenerateTemplateExportHeader.cmake)
include(cmake/GetGitRevisionDescription.cmake)
include(cmake/HealthCheck.cmake)
#
# Project description and (meta) information
#
# Get git revision
get_git_head_revision(GIT_REFSPEC GIT_SHA1)
string(SUBSTRING "${GIT_SHA1}" 0 12 GIT_REV)
if(NOT GIT_SHA1)
set(GIT_REV "0")
endif()
# Meta information about the project
set(META_PROJECT_NAME "yodaStruct")
set(META_PROJECT_DESCRIPTION "A molecular simulation analysis toolkit")
set(META_AUTHOR_ORGANIZATION "IIT Kanpur")
set(META_AUTHOR_DOMAIN "https://github.com/cginternals/cmake-init/")
set(META_AUTHOR_MAINTAINER "rohit.goswami[at]aol.com")
set(META_VERSION_MAJOR "0")
set(META_VERSION_MINOR "1")
set(META_VERSION_PATCH "0")
set(META_VERSION_REVISION "${GIT_REV}")
set(META_VERSION "${META_VERSION_MAJOR}.${META_VERSION_MINOR}.${META_VERSION_PATCH}")
set(META_NAME_VERSION "${META_PROJECT_NAME} v${META_VERSION} (${META_VERSION_REVISION})")
set(META_CMAKE_INIT_SHA "${GIT_REV}")
string(MAKE_C_IDENTIFIER ${META_PROJECT_NAME} META_PROJECT_ID)
string(TOUPPER ${META_PROJECT_ID} META_PROJECT_ID)
#
# Project configuration options
#
# Project options
option(BUILD_SHARED_LIBS "Build shared instead of static libraries." ON)
option(OPTION_SELF_CONTAINED "Create a self-contained install with all dependencies." OFF)
option(OPTION_BUILD_TESTS "Build tests." ON)
option(OPTION_BUILD_DOCS "Build documentation." OFF)
option(OPTION_BUILD_EXAMPLES "Build examples." OFF)
option(OPTION_ENABLE_COVERAGE "Add coverage information." OFF)
#
# Declare project
#
# Generate folders for IDE targets (e.g., VisualStudio solutions)
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
set(IDE_FOLDER "")
# Declare project
project(${META_PROJECT_NAME} LANGUAGES C CXX)
# Set output directories
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})
# Create version file
file(WRITE "${PROJECT_BINARY_DIR}/VERSION" "${META_NAME_VERSION}")
#
# Project Health Check Setup
#
# Add cmake-init template check cmake targets
add_check_template_target(${META_CMAKE_INIT_SHA})
# Configure health check tools
enable_cppcheck(ON)
enable_clang_tidy(ON)
enable_coverage(${OPTION_ENABLE_COVERAGE})
#
# Compiler settings and options
#
include(cmake/CompileOptions.cmake)
#
# Deployment/installation setup
#
# Get project name
set(project ${META_PROJECT_NAME})
# Check for system dir install
set(SYSTEM_DIR_INSTALL FALSE)
if("${CMAKE_INSTALL_PREFIX}" STREQUAL "/usr" OR "${CMAKE_INSTALL_PREFIX}" STREQUAL "/usr/local")
set(SYSTEM_DIR_INSTALL TRUE)
endif()
# Installation paths
if(UNIX AND SYSTEM_DIR_INSTALL)
# Install into the system (/usr/bin or /usr/local/bin)
set(INSTALL_ROOT "share/${project}") # /usr/[local]/share/<project>
set(INSTALL_CMAKE "share/${project}/cmake") # /usr/[local]/share/<project>/cmake
set(INSTALL_EXAMPLES "share/${project}") # /usr/[local]/share/<project>
set(INSTALL_DATA "share/${project}") # /usr/[local]/share/<project>
set(INSTALL_BIN "bin") # /usr/[local]/bin
set(INSTALL_SHARED "lib") # /usr/[local]/lib
set(INSTALL_LIB "lib") # /usr/[local]/lib
set(INSTALL_INCLUDE "include") # /usr/[local]/include
set(INSTALL_DOC "share/doc/${project}") # /usr/[local]/share/doc/<project>
set(INSTALL_SHORTCUTS "share/applications") # /usr/[local]/share/applications
set(INSTALL_ICONS "share/pixmaps") # /usr/[local]/share/pixmaps
set(INSTALL_INIT "/etc/init") # /etc/init (upstart init scripts)
else()
# Install into local directory
set(INSTALL_ROOT ".") # ./
set(INSTALL_CMAKE "cmake") # ./cmake
set(INSTALL_EXAMPLES ".") # ./
set(INSTALL_DATA ".") # ./
set(INSTALL_BIN "bin") # ./bin
set(INSTALL_SHARED "lib") # ./lib
set(INSTALL_LIB "lib") # ./lib
set(INSTALL_INCLUDE "include") # ./include
set(INSTALL_DOC "doc") # ./doc
set(INSTALL_SHORTCUTS "misc") # ./misc
set(INSTALL_ICONS "misc") # ./misc
set(INSTALL_INIT "misc") # ./misc
endif()
# Set runtime path
set(CMAKE_SKIP_BUILD_RPATH FALSE) # Add absolute path to all dependencies for BUILD
set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE) # Use CMAKE_INSTALL_RPATH for INSTALL
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH FALSE) # Do NOT add path to dependencies for INSTALL
if(NOT SYSTEM_DIR_INSTALL)
# Find libraries relative to binary
if(APPLE)
set(CMAKE_INSTALL_RPATH "@loader_path/../../../${INSTALL_LIB}")
else()
set(CMAKE_INSTALL_RPATH "$ORIGIN/${INSTALL_LIB}")
endif()
endif()
SET( EIGEN3_INCLUDE_DIR "$ENV{EIGEN3_INCLUDE_DIR}" )
IF( NOT EIGEN3_INCLUDE_DIR )
MESSAGE( FATAL_ERROR "Please point the environment variable EIGEN3_INCLUDE_DIR to the include directory of your Eigen3 installation.")
ENDIF()
INCLUDE_DIRECTORIES ( "${EIGEN3_INCLUDE_DIR}" )
#
# Project modules
#
add_subdirectory(src)
# add_subdirectory(source)
# add_subdirectory(docs)
# add_subdirectory(deploy)
#
# Deployment (global project files)
#
# Install version file
# install(FILES "${PROJECT_BINARY_DIR}/VERSION" DESTINATION ${INSTALL_ROOT} COMPONENT runtime)
# # Install cmake find script for the project
# install(FILES ${META_PROJECT_NAME}-config.cmake DESTINATION ${INSTALL_ROOT} COMPONENT dev)
# # Install the project meta files
# install(FILES AUTHORS DESTINATION ${INSTALL_ROOT} COMPONENT runtime)
# install(FILES LICENSE DESTINATION ${INSTALL_ROOT} COMPONENT runtime)
# install(FILES README.md DESTINATION ${INSTALL_ROOT} COMPONENT runtime)
# # Install runtime data
# install(DIRECTORY ${PROJECT_SOURCE_DIR}/data DESTINATION ${INSTALL_DATA} COMPONENT runtime)
#
# Dependency Management
#
# Catch
include(CTest)
add_subdirectory(tests)
enable_testing()