forked from EMsoft-org/EMsoft
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
386 lines (301 loc) · 14.3 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
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
if(${CMAKE_MAJOR_VERSION} VERSION_GREATER_EQUAL "3.1.0")
cmake_policy(SET CMP0002 NEW)
cmake_policy(SET CMP0054 NEW)
cmake_policy(SET CMP0048 NEW)
endif()
if(${CMAKE_MAJOR_VERSION} VERSION_GREATER_EQUAL "3.12.0")
cmake_policy(SET CMP0074 NEW)
endif()
if(${CMAKE_MAJOR_VERSION} VERSION_GREATER_EQUAL "3.13.0")
cmake_policy(SET CMP0079 NEW)
endif()
cmake_minimum_required(VERSION 3.14.5)
# use, i.e. don't skip the full RPATH for the build tree
SET(CMAKE_SKIP_BUILD_RPATH FALSE)
# when building, don't use the install RPATH already
# (but later on when installing)
SET(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
# the RPATH to be used when installing
SET(CMAKE_INSTALL_RPATH "${FCL_SOURCE_DIR}/libs")
# don't add the automatically determined parts of the RPATH
# which point to directories outside the build tree to the install RPATH
SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH FALSE)
if(NOT "${EMsoft_SDK}" STREQUAL "")
include("${EMsoft_SDK}/EMsoft_SDK.cmake")
get_property(EMsoft_SDK_STATUS_PRINTED GLOBAL PROPERTY EMsoft_SDK_STATUS_PRINTED)
if(NOT EMsoft_SDK_STATUS_PRINTED)
message(STATUS "********* STARTING EMsoft CONFIGURATION ***********************")
message(STATUS "EMsoft_SDK Location: ${EMsoft_SDK}")
set_property(GLOBAL PROPERTY EMsoft_SDK_STATUS_PRINTED TRUE)
endif()
else()
message(STATUS "You have elected to NOT set a EMsoft_SDK CMake variable. You will")
message(STATUS "need to point to the various dependecies that EMsoft requires for")
message(STATUS "building. Those that are undefined are listed next:")
if(NOT DEFINED bcls_DIR)
message(STATUS "Set bcls_DIR variable to the directory where bclsConfig.cmake is located.")
endif()
if(NOT DEFINED CLFORTRAN_DIR)
message(STATUS "Set CLFORTRAN_DIR variable to the directory where CLFortranConfig.cmake is located.")
endif()
if(NOT DEFINED EIGEN_INSTALL)
message(STATUS "Set EIGEN_INSTALL variable to the root directory of the Eigen installation.")
endif()
if(NOT DEFINED FFTW3_INSTALL)
message(STATUS "Set FFTW3_INSTALL variable to the root directory of the FFTW installation.")
endif()
if(NOT DEFINED HDF5_DIR)
message(STATUS "Set HDF5_DIR variable to the directory where the hdf5-config.cmake is located.")
endif()
if(NOT DEFINED JSONFORTRAN_DIR)
message(STATUS "Set JSONFORTRAN_DIR variable to the directory where the jsonfortran-*-config.cmake is located.")
endif()
if(NOT DEFINED Qt5_DIR)
message(STATUS "Set Qt5_DIR variable to the directory where the Qt5Config.cmake is located.")
endif()
if(NOT DEFINED TBB_DIR)
message(STATUS "Set TBB_DIR variable to the directory where TBBConfig.cmake is located.")
endif()
endif()
# Request C++11 standard, using new CMake variables.
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED True)
set(CMAKE_CXX_EXTENSIONS False)
#------------------------------------------------------------------------------
# There are several different Release Types that we are going to use.
# Official: This is an official release
# Beta: This is a Beta release that has is getting ready to be officially released.
# Development: This is currently in development and probably has bugs.
get_property(EMsoft_RELEASE_TYPE GLOBAL PROPERTY PACKAGE_RELEASE_TYPE)
if("${EMsoft_RELEASE_TYPE}" STREQUAL "")
set(EMsoft_RELEASE_TYPE "Development") # <============ SET THIS FOR RELEASE
set_property(GLOBAL PROPERTY PACKAGE_RELEASE_TYPE "${EMsoft_RELEASE_TYPE}")
endif()
if (NOT DEFINED CMP_SOURCE_DIR)
set(CMP_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/Support/cmp)
endif()
include (${CMP_SOURCE_DIR}/cmpCMakeMacros.cmake )
# Next up, Set the version of EMsoft that is used through out the project.
set(EMsoft_VER_MAJOR "5")
set(EMsoft_VER_MINOR "0")
set(EMsoft_VER_PATCH "2")
project (EMsoft LANGUAGES C CXX Fortran VERSION ${EMsoft_VER_MAJOR}.${EMsoft_VER_MINOR}.${EMsoft_VER_PATCH}.0)
include(CMakeParseArguments)
cmpGenerateBuildDate(PROJECT_NAME EMsoft)
if(NOT "${EMsoft_RELEASE_TYPE}" STREQUAL "Official")
string(REPLACE "/" "" EMsoft_VER_PATCH ${EMsoft_BUILD_DATE})
endif()
# --------------------------------------------------------------------
# Print out the current Git Infomation. This is useful to help debug the dashboards
execute_process(COMMAND ${GIT_EXECUTABLE} rev-parse --verify HEAD
OUTPUT_VARIABLE EMsoft_GIT_HASH
RESULT_VARIABLE did_run
ERROR_VARIABLE git_error
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
OUTPUT_STRIP_TRAILING_WHITESPACE
)
string(REPLACE "\n" "" EMsoft_GIT_HASH "${EMsoft_GIT_HASH}")
execute_process( # get abbreviated hash
COMMAND ${GIT_EXECUTABLE} rev-parse --short HEAD
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE EMsoft_SHORT_GIT_HASH
OUTPUT_STRIP_TRAILING_WHITESPACE
)
execute_process(COMMAND ${GIT_EXECUTABLE} log -1 --pretty='%cd' --date=format:%Y-%m-%d-%H:%M:%S
OUTPUT_VARIABLE GVS_GIT_COMMIT_DATE
RESULT_VARIABLE did_run
ERROR_VARIABLE git_error
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
)
string(REPLACE "\n" "" GVS_GIT_COMMIT_DATE "${GVS_GIT_COMMIT_DATE}")
message(STATUS "${PROJECT_NAME} Git Hash:${EMsoft_GIT_HASH} committed on ${GVS_GIT_COMMIT_DATE}")
#message(STATUS "EMsoft_BUILD_DATE: ${EMsoft_BUILD_DATE}")
#------------------------------------------------------------------------------
set(EMsoft_TEST_DIR "EMsofttmp")
# ---------- Setup output Directories -------------------------
if(NOT DEFINED CMAKE_LIBRARY_OUTPUT_DIRECTORY)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY
${EMsoft_BINARY_DIR}/Bin
CACHE PATH
"Single Directory for all Libraries"
)
endif()
# --------- Setup the Executable output Directory -------------
if(NOT DEFINED CMAKE_RUNTIME_OUTPUT_DIRECTORY)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY
${EMsoft_BINARY_DIR}/Bin
CACHE PATH
"Single Directory for all Executables."
)
endif()
# --------- Setup the Executable output Directory -------------
if(NOT DEFINED CMAKE_ARCHIVE_OUTPUT_DIRECTORY)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY
${EMsoft_BINARY_DIR}/Bin
CACHE PATH
"Single Directory for all static libraries."
)
endif()
#Enable use of Solution Folders
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
# Build shared libraries
OPTION(BUILD_SHARED_LIBS "Build Shared Libraries" OFF)
if(WIN32)
#set(BUILD_SHARED_LIBS ON CACHE BOOL "" FORCE)
endif()
set(LIB_TYPE STATIC)
if(BUILD_SHARED_LIBS)
set(LIB_TYPE SHARED)
list(APPEND CMP_LIB_SEARCH_DIRS ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} )
if(MSVC)
list(APPEND CMP_LIB_SEARCH_DIRS ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/Debug
${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/Release )
endif()
endif(BUILD_SHARED_LIBS)
get_property(EMsoftBinaryDir GLOBAL PROPERTY EMsoftBinaryDir)
if("${EMsoftBinaryDir}" STREQUAL "")
set(EMsoftBinaryDir "${EMsoftPublic_BINARY_DIR}")
set_property(GLOBAL PROPERTY EMsoftBinaryDir "${EMsoftPublic_BINARY_DIR}")
endif()
get_property(EMsoftSearchDirs GLOBAL PROPERTY EMsoftSearchDirs)
if("${EMsoftSearchDirs}" STREQUAL "")
set_property(GLOBAL PROPERTY EMsoftSearchDirs "${EMsoft_BINARY_DIR}/LibSearchDirs.txt")
get_property(EMsoftSearchDirs GLOBAL PROPERTY EMsoftSearchDirs)
file(WRITE "${EMsoftSearchDirs}" "${CMAKE_LIBRARY_OUTPUT_DIRECTORY};")
file(APPEND "${EMsoftSearchDirs}" "${CMAKE_RUNTIME_OUTPUT_DIRECTORY};")
if(MSVC)
file(APPEND "${EMsoftSearchDirs}" "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/Debug;${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/Release;")
endif()
endif()
#------------------------------------------------------------------------------
# Download (During CMake Time) the SHTfile project from GitHub.com
# This will configure the "sht_file.hpp" file that is included in several of the
# libraries and executables.
include(FetchContent)
set(FETCHCONTENT_BASE_DIR ${EMsoft_BINARY_DIR}/SHTfile)
FetchContent_Declare(
SHTfile
GIT_REPOSITORY "https://github.com/EMsoft-org/SHTfile"
GIT_TAG "cd75885" # just get the most 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)
# Set the Application Name to with the correct icons and badges
set(CMP_HEADER_DIR ${EMsoft_BINARY_DIR})
set(PROJECT_RESOURCES_DIR "${EMsoft_SOURCE_DIR}/resources")
set(EMsoft_APPLICATION_NAME "EMsoft")
set(EMsoft_VERSION_HDR_FILE "EMsoftVersion.h")
set(EMsoft_VERSION_SRC_FILE "EMsoftVersion.cpp")
set(EXE_DEBUG_EXTENSION "_debug")
include(${CMP_SOURCE_DIR}/cmpProject.cmake)
include (${CMP_SOURCE_DIR}/cmpCMakeMacros.cmake)
#------------------------------------------------------------------------------
# Find the Git Package for Versioning. It should be ok if Git is NOT found
Find_package(Git)
# -----------------------------------------------------------------------
# Generate a set of Version Cpp/H files that will be used by SIMPLView to
# get and display the proper version numbers.
cmpRevisionString( GENERATED_HEADER_FILE_PATH "${EMsoft_VERSION_HDR_FILE}"
GENERATED_SOURCE_FILE_PATH "${EMsoft_VERSION_SRC_FILE}"
NAMESPACE "EMsoft"
PROJECT_NAME "${PROJECT_NAME}"
EXPORT_MACRO "EMsoft_EXPORT")
string(TIMESTAMP EMsoft_BUILD_TIMESTAMP "%Y-%m-%d %H:%M:%SZ" UTC)
include (${CMP_SOURCE_DIR}/cmpProject.cmake)
# --------------------------------------------------------------------
# Over ride CMake's built in module directory by prepending cmp's module
# directory first
set(CMAKE_MODULE_PATH ${EMsoft_SOURCE_DIR}/Support/CMakeModules ${CMAKE_MODULE_PATH})
# set(EXE_DEBUG_EXTENSION "_debug")
set(EXE_DEBUG_EXTENSION "")
# Get the name of the Fortran compiler for easier decisions
get_filename_component (Fortran_COMPILER_NAME ${CMAKE_Fortran_COMPILER} NAME)
if (Fortran_COMPILER_NAME MATCHES "gfortran.*")
# These have been moved to the EMsoftLib library declaration as target_compile_options
get_filename_component (Fortran_COMPILER_PATH ${CMAKE_Fortran_COMPILER} DIRECTORY)
set(GFortran_LIB_DIR "${Fortran_COMPILER_PATH}/../lib")
elseif (Fortran_COMPILER_NAME MATCHES "ifort.*")
if(WIN32)
set (CMAKE_SHARED_LINKER_FLAGS "/ignore:4217 /ignore:4049")
else()
# These have been moved to the EMsoftLib library declaration as target_compile_options
endif()
else ()
message (STATUS "CMAKE_Fortran_COMPILER full path: " ${CMAKE_Fortran_COMPILER})
message (STATUS "Fortran compiler: " ${Fortran_COMPILER_NAME})
message (STATUS "No optimized Fortran compiler flags are known.")
endif()
# --------------------------------------------------------------------
# This should all be for macOS RPath Handling.
# use, i.e. don't skip the full RPATH for the build tree
SET(CMAKE_SKIP_BUILD_RPATH FALSE)
# when building, don't use the install RPATH already
# (but later on when installing)
SET(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
# add the automatically determined parts of the RPATH
# which point to directories outside the build tree to the install RPATH
SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
# the RPATH to be used when installing, but only if it's not a system directory
LIST(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_PREFIX}/lib" isSystemDir)
IF("${isSystemDir}" STREQUAL "-1")
SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
ENDIF("${isSystemDir}" STREQUAL "-1")
include (${PROJECT_SOURCE_DIR}/Support/ExtLib/ExtLibraries.cmake)
OPTION(EMsoft_ENABLE_TESTING "Compile the test programs" ON)
set(EMsoft_TESTING_DIR "${EMsoft_BINARY_DIR}/Testing")
# -----------------------------------------------------------------------
# Build SHTfile Project
# -----------------------------------------------------------------------
add_subdirectory(${SHTfile_SOURCE_DIR} ${EMsoft_BINARY_DIR}/SHTfile)
# -----------------------------------------------------------------------
# Set a Global Prefix where everthing is going to get intalled. For OS X we are
# going to try to install everything into the .app package
# -----------------------------------------------------------------------
set_property(GLOBAL PROPERTY EMsoft_PACKAGE_DEST_PREFIX ".")
include(${PROJECT_SOURCE_DIR}/Source/Source.cmake)
# --------------------------------------------------------------------
# Package the needed examples
include(${PROJECT_SOURCE_DIR}/manuals/examples/SourceList.cmake)
# # --------------------------------------------------------------------
# # Package the needed IDL Files
# if(APPLE)
# include(${PROJECT_SOURCE_DIR}/IDL/SourceList.cmake)
# endif()
# --------------------------------------------------------------------
# Package the needed PDF Manuals
include(${PROJECT_SOURCE_DIR}/manuals/CMakeLists.txt)
# --------------------------------------------------------------------
# Package the OpenCL files
include(${PROJECT_SOURCE_DIR}/opencl/SourceList.cmake)
# --------------------------------------------------------------------
# Package the needed resources
include(${PROJECT_SOURCE_DIR}/resources/SourceList.cmake)
# --------------------------------------------------------------------
# Package the needed template files
include(${PROJECT_SOURCE_DIR}/NamelistTemplates/SourceList.cmake)
# --------------------------------------------------------------------
# Generate our ReadMe and License Files
configure_file(${PROJECT_SOURCE_DIR}/License.txt
${PROJECT_BINARY_DIR}/License.txt )
configure_file(${PROJECT_SOURCE_DIR}/ReadMe.md
${PROJECT_BINARY_DIR}/ReadMe.md )
#---------------------------------------------------------------------
# This sets up the two variables install_dir and lib_install_dir
EMsoft_SetupInstallDirs()
install(FILES ${PROJECT_SOURCE_DIR}/ReadMe.md ${PROJECT_SOURCE_DIR}/License.txt
DESTINATION ${install_dir}/Documentation
COMPONENT Applications)
# --------------------------------------------------------------------
# Include the CPack specific code
include(${EMsoft_SOURCE_DIR}/Support/CPack/PackageProject.cmake)
# --------------------------------------------------------------------
# This should be the last line in this file as it includes CTest for
# nightly testing.
if(EMsoft_ENABLE_TESTING)
ENABLE_TESTING()
include(CTest)
add_subdirectory(${EMsoft_SOURCE_DIR}/Source/Test ${PROJECT_BINARY_DIR}/Test)
endif()