forked from EMsoft-org/EMSphInx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
297 lines (258 loc) · 12.2 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
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# #
# Copyright (c) 2019, De Graef Group, Carnegie Mellon University #
# All rights reserved. #
# #
# Author: William C. Lenthe #
# #
# This package is free software; you can redistribute it and/or #
# modify it under the terms of the GNU General Public License as #
# published by the Free Software Foundation; either version 2 of the #
# License, or (at your option) any later version. #
# #
# This program is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU General Public License for more details. #
# #
# You should have received a copy of the GNU General Public License #
# along with this program; if not, check the Free Software Foundation #
# website: <https://www.gnu.org/licenses/old-licenses/gpl-2.0.html> #
# #
# #
# Interested in a commercial license? Contact: #
# #
# Center for Technology Transfer and Enterprise Creation #
# 4615 Forbes Avenue, Suite 302 #
# Pittsburgh, PA 15213 #
# #
# phone. : 412.268.7393 #
# email : [email protected] #
# website: https://www.cmu.edu/cttec/ #
# #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
project(EMSphInx)
# cmake_minimum_required(VERSION 3.12) # 3.12 for the parallel option for cmake --build
cmake_minimum_required(VERSION 3.14) # for FetchContent_MakeAvailable (could fall back to 3.12 with alternate pattern but it is now deprecated)
set(CMAKE_CXX_STANDARD 11) # apparently you still need to explicitly request 2011 conformance in 2019...
################################
# package options #
################################
option(EMSPHINX_BUILD_SHARED "should shared or static libraries be preferred" OFF)
option(EMSPHINX_FFTW_F "enable float templates by linking against fftw_f" OFF)
option(EMSPHINX_FFTW_D "enable double templates by linking against fftw" ON )
option(EMSPHINX_FFTW_L "enable long double templates by linking against fftw_l" OFF)
option(EMSPHINX_BUILD_FFTW "fetch and build FFTW instead of using an existing system installation" ON )
option(EMSPHINX_FFTW_SIMD "should SSE/SSE2/AVX instructions be enabled for fftw build (faster run, slower compiler)" ON )
option(EMSPHINX_FFTW_AVX2 "should AVX2 instructions be enabled for fftw build (not supported on all processors) " OFF)
option(EMSPHINX_BUILD_HDF5 "fetch and build HDF5 instead of using an existing system installation" ON )
option(EMSPHINX_BUILD_TESTS "should test programs (/test/*) be built" ON )
option(EMSPHINX_BUILD_GUIS "should the GUI programs be built (experimental)" OFF)
if(EMSPHINX_BUILD_GUIS)
option(EMSPHINX_BUILD_wxWidgets "should wxWidgets be built from source" ON)
endif()
################################
# multicore compiling #
################################
include(ProcessorCount)
ProcessorCount(NCORES)
if(NOT NCORES EQUAL 0)
set(CMAKE_BUILD_PARALLEL_LEVEL NCORES)
endif()
################################
# compiler specific adjustment #
################################
# visual studio
if(MSVC)
add_definitions(-D_SCL_SECURE_NO_WARNINGS) # these warnings are annoying and not critical
add_definitions(-D_CRT_SECURE_NO_WARNINGS) # these warnings are annoying and not critical
# add_compile_options($<$<CXX_COMPILER_ID:MSVC>:/MP>) # use multi core compiling
add_compile_options(/MP) # the generator expression version breaks wxWidgets
endif()
# gcc
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} "-pthread" )# std::thread requires pthreads on gcc
endif()
# non clang osx
# if(APPLE AND NOT "${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang") # only for gcc, not clang
# set(CMAKE_INSTALL_RPATH_USE_LINK_PATH OFF) # there seems to be an rpath issue on apple + GCC
# endif()
set(MACOSX_RPATH ON) # still haven't fully resolved this...
################################
# dynamic library copying #
################################
# get prefix/extension for built libraries
if(EMSPHINX_BUILD_SHARED)
set(LIB_PRE ${CMAKE_SHARED_LIBRARY_PREFIX})
set(LIB_EXT ${CMAKE_SHARED_LIBRARY_SUFFIX})
else()
set(LIB_PRE ${CMAKE_STATIC_LIBRARY_PREFIX})
set(LIB_EXT ${CMAKE_STATIC_LIBRARY_SUFFIX})
endif()
# determine name of files to link against (windows makes .dll for runtime but also keeps .lib for linking) and copy into build directory
if(MSVC)
set(LNK_EXT ${CMAKE_STATIC_LIBRARY_SUFFIX}) # link against the .lib
set(CPY_DIR bin) # location to copy shared libraries from
else()
set(LNK_EXT ${LIB_EXT}) # link against static or dynamic as appropriate
set(CPY_DIR lib) # location to copy shared libraries from
endif()
################################
# git versioning #
################################
find_package(Git REQUIRED)
execute_process( # get branch name
COMMAND ${GIT_EXECUTABLE} rev-parse --abbrev-ref HEAD
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE EMSPHINX_GIT_BRANCH
OUTPUT_STRIP_TRAILING_WHITESPACE
)
execute_process( # get abbreviated hash
COMMAND ${GIT_EXECUTABLE} rev-parse --short HEAD
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE EMSPHINX_GIT_HASH
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if("${EMSPHINX_GIT_BRANCH}" STREQUAL "")
message(FATAL_ERROR "failed to determine git branch)")
endif()
if("${EMSPHINX_GIT_HASH}" STREQUAL "")
message(FATAL_ERROR "failed to determine git hash)")
endif()
add_definitions("-DEMSPHINX_GIT_HASH=${EMSPHINX_GIT_HASH}")
add_definitions("-DEMSPHINX_GIT_BRANCH=${EMSPHINX_GIT_BRANCH}")
################################
# dependencies #
################################
# fetch SHT file format content
# this could be done with a git submodule but the user would have to call:
# git submodule update
# git clone --recursive
# which is a bit annoying
include(FetchContent)
FetchContent_Declare(
SHTfile
GIT_REPOSITORY "https://github.com/EMsoft-org/SHTfile"
GIT_TAG "e49ad6b"
# GIT_TAG "v3.1.2" # just get a recent version for now
# GIT_PROGRESS TRUE # its currently only 1 file, we probably don't need to print out progress
)
# set(FETCHCONTENT_QUIET NO) # again only 1 file
FetchContent_MakeAvailable(SHTfile)
FetchContent_GetProperties(SHTfile BINARY_DIR SHTfile_BINARY_DIR)
include_directories(${SHTfile_BINARY_DIR})
# compiled dependencies
include(${CMAKE_CURRENT_LIST_DIR}/depends/FFTW.cmake) # build or find existing FFTW
include(${CMAKE_CURRENT_LIST_DIR}/depends/HDF5.cmake) # build or find existing HDF5
if(EMSPHINX_BUILD_GUIS)
include(${CMAKE_CURRENT_LIST_DIR}/depends/wxWidgets.cmake) # build or find existing HDF5
endif()
# png support, for now I've included these files directly due to download issues on some versions of cmake (if libcurl doesn't support https)
set(BuildMiniZ OFF)
if(BuildMiniZ)
set(MINIZ_VERSION "2.0.8")
ExternalProject_Add(
miniz PREFIX "miniz"
URL https://github.com/richgel999/miniz/releases/download/${MINIZ_VERSION}/miniz-${MINIZ_VERSION}.zip
URL_HASH MD5=0692c3f080267b24419ab67c1eefc881 # make sure the download wasn't corrupted (/ someone hasn't injected a different version)
CONFIGURE_COMMAND "" ${CMAKE_COMMAND} -E copy_directory ${CMAKE_BINARY_DIR}/miniz/src/miniz/ ${CMAKE_SOURCE_DIR}/include/miniz # copy everything (source + license are most critical)
BUILD_COMMAND "" INSTALL_COMMAND ""
)
endif(BuildMiniZ)
################################
# add actual components #
################################
# include headers
include_directories(${CMAKE_CURRENT_LIST_DIR}/include)
include_directories(${CMAKE_CURRENT_LIST_DIR}/icons)
# add test programs if needed
if(EMSPHINX_BUILD_TESTS)
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/test ${CMAKE_BINARY_DIR}/test) # don't put in /cpp/test
endif()
# add actual programs
include(${CMAKE_CURRENT_LIST_DIR}/programs/CMakeLists.txt) # include instead of add_subdirectory so we don't get a subfolder in the build
################################
# build installer #
################################
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "spherical harmonic based indexing of diffraction patterns https://github.com/emsoft-org/EMSphInx/")
set(CPACK_PACKAGE_NAME "emsphinx")
set(CPACK_PACKAGE_VERSION "${EMSPHINX_GIT_HASH}")
set(CPACK_PACKAGE_VENDOR "emsoft-org")
#CPACK_PACKAGE_DESCRIPTION_FILE
if(WIN32 OR MSVC)
# windows
set(CPACK_GENERATOR "ZIP") # we could also use NSIS if things get more complicated
elseif(APPLE)
# osx
set(CPACK_GENERATOR "DragNDrop") # we could also use PackageMaker, OSXX11, or Bundle
elseif(UNIX)
# linux, try to determine best package type
# start by searching for common package builders
find_program(rpmbuild NAMES rpmbuild)
find_program(dpkg NAMES dpkg)
if(rpmbuild)
# red hat based systems are more likely to have a deb builder than vice versa
set(CPACK_GENERATOR "RPM")
# CPACK_RPM_PACKAGE_ARCHITECTURE
# CPACK_RPM_PACKAGE_RELEASE
# CPACK_RPM_PACKAGE_LICENSE
# CPACK_RPM_PACKAGE_GROUP
# CPACK_RPM_PACKAGE_PROVIDES
# rpm dependencies
if(NOT EMSPHINX_BUILD_FFTW)
if(NOT CPACK_RPM_PACKAGE_REQUIRES)
set(CPACK_RPM_PACKAGE_REQUIRES "fftw >= 3.3.7")
else()
set(CPACK_RPM_PACKAGE_REQUIRES "${CPACK_RPM_PACKAGE_REQUIRES}, fftw >= 3.3.7")
endif()
endif()
if(NOT EMSPHINX_BUILD_HDF5)
if(NOT CPACK_RPM_PACKAGE_REQUIRES)
set(CPACK_RPM_PACKAGE_REQUIRES "hdf5 >= 1.8.20")
else()
set(CPACK_RPM_PACKAGE_REQUIRES "${CPACK_RPM_PACKAGE_REQUIRES}, hdf5 >= 1.8.20")
endif()
endif()
if(EMSPHINX_BUILD_GUIS AND NOT EMSPHINX_BUILD_wxWidgets)
if(NOT CPACK_RPM_PACKAGE_REQUIRES)
set(CPACK_RPM_PACKAGE_REQUIRES "libwx >= 3.1.2")
else()
set(CPACK_RPM_PACKAGE_REQUIRES "${CPACK_RPM_PACKAGE_REQUIRES}, libwx >= 3.1.2")
endif()
endif()
elseif(dpkg)
# debian type system
set(CPACK_GENERATOR "DEB")
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "wlenthe") # required
set(CPACK_DEBIAN_PACKAGE_VERSION "${EMSPHINX_GIT_HASH}") # required for control (default is CPACK_PACKAGE_VERSION)
# apt dependencies
if(NOT EMSPHINX_BUILD_FFTW)
if(NOT CPACK_DEBIAN_PACKAGE_DEPENDS)
set(CPACK_DEBIAN_PACKAGE_DEPENDS "libfftw3-3 (>= 3.3.7)")
else()
set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS}, libfftw3-3 (>= 3.3.7)")
endif()
endif()
if(NOT EMSPHINX_BUILD_HDF5)
if(NOT CPACK_DEBIAN_PACKAGE_DEPENDS)
set(CPACK_DEBIAN_PACKAGE_DEPENDS "libhdf5-cpp-100 (>= 1.8.20)")
else()
set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS}, libhdf5-cpp-100 (>= 1.8.20)")
endif()
endif()
# 3.1 isn't actually packaged so this won't work right now...
if(EMSPHINX_BUILD_GUIS AND NOT EMSPHINX_BUILD_wxWidgets)
if(NOT CPACK_DEBIAN_PACKAGE_DEPENDS)
set(CPACK_DEBIAN_PACKAGE_DEPENDS "libwxgtk3.1 (>= 3.1.2)")
else()
set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS}, libwxgtk3.1 (>= 3.1.2)")
endif()
endif()
else()
# some other linux flavor
set(CPACK_GENERATOR "TZ")
endif()
else()
message(FATAL_ERROR "couldn't determine OS for package building")
endif()
include(CPack)