forked from Tech-XCorp/scimake
-
Notifications
You must be signed in to change notification settings - Fork 1
/
SciInit.cmake
350 lines (304 loc) · 10.8 KB
/
SciInit.cmake
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
######################################################################
#
# SciInit: Do the startup stuff for any package
#
# $Rev$ $Date$
#
# Copyright 2012-2017, Tech-X Corporation, Boulder, CO.
# See LICENSE file (EclipseLicense.txt) for conditions of use.
#
#
######################################################################
string(TOUPPER ${PROJECT_NAME} PROJECT_NAMEUC)
set(HAVE_CMAKE 1 CACHE STRING "Whether built with CMake")
set(${PROJECT_NAMEUC}_HAVE_CMAKE TRUE)
#####################################################################
#
# Pull in useful macros
#
#####################################################################
if (NOT DEFINED SCIMAKE_DIR)
message(STATUS "[SciInit]: CMAKE_CURRENT_LIST_DIR = ${CMAKE_CURRENT_LIST_DIR}.")
set(SCIMAKE_DIR ${CMAKE_CURRENT_LIST_DIR})
endif ()
include(${SCIMAKE_DIR}/SciFuncsMacros.cmake)
include(${SCIMAKE_DIR}/SciGetDepsFromInstall.cmake)
include(GenerateExportHeader)
#####################################################################
#
# Clean out config.summary
#
#####################################################################
set(CONFIG_SUMMARY ${PROJECT_BINARY_DIR}/config.summary)
file(REMOVE ${CONFIG_SUMMARY})
SciPrintString(
"CONFIGURING ${CMAKE_PROJECT_NAME} with scimake in ${PROJECT_BINARY_DIR}.")
#####################################################################
#
# Set some vars to upper case for case-free comparisons
#
#####################################################################
if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif ()
message(STATUS "[SciInit]: CMAKE_BUILD_TYPE = ${CMAKE_BUILD_TYPE}.")
string(TOUPPER "${CMAKE_BUILD_TYPE}" CMAKE_BUILD_TYPE_UC)
#####################################################################
#
# Set group write installation perm
# May need to be different on different machines
#
#####################################################################
if (NOT DEFINED SCI_GROUP_WRITE)
set(SCI_GROUP_WRITE ""
CACHE STRING "Value of group write permissions")
endif ()
if (NOT DEFINED SCI_WORLD_PERMS)
set(SCI_WORLD_PERMS ""
CACHE STRING "Value of world permissions")
endif ()
#####################################################################
#
# Set OS-specific flags
#
#####################################################################
message(STATUS "[SciInit]: CMAKE_SYSTEM_NAME is ${CMAKE_SYSTEM_NAME}")
if ("${CMAKE_SYSTEM_NAME}" MATCHES "Darwin")
set(MACX TRUE CACHE BOOL "True if compiled on Mac OS X")
message(STATUS "[SciInit]: Compiling on MAC, CMAKE_SYSTEM = ${CMAKE_SYSTEM}.")
elseif ("${CMAKE_SYSTEM_NAME}" MATCHES "Linux")
set(LINUX TRUE CACHE BOOL "True if compiled on Linux")
message(STATUS "[SciInit]: Compiling on LINUX")
elseif (WIN32)
set(WINDOWS TRUE CACHE BOOL "True if compiled on Windows")
message(STATUS "[SciInit]: Compiling on WINDOWS")
else ()
message(FATAL_ERROR "[SciInit.cmake] Unrecognized OS!")
endif ()
SciPrintString("CMAKE_SYSTEM_PROCESSOR = ${CMAKE_SYSTEM_PROCESSOR}.")
set(HOST_PROCESSOR ${CMAKE_SYSTEM_PROCESSOR})
if (${CMAKE_SYSTEM_PROCESSOR} STREQUAL x86_64)
set(HAVE_X86_64 TRUE)
endif ()
######################################################################
#
# Set up standard paths
#
######################################################################
cmake_policy(SET CMP0017 OLD) # Use our modules over theirs
set(CMAKE_MODULE_PATH
${SCIMAKE_DIR}/Modules
)
if (DEBUG_CMAKE)
message(STATUS "[SciInit]: CMAKE_MODULE_PATH = ${CMAKE_MODULE_PATH}")
set(SCI_DEBUG_VAR DEBUG)
endif ()
# message("SUPRA_SEARCH_PATH = ${SUPRA_SEARCH_PATH}")
if (SUPRA_SEARCH_PATH)
set(SUPRA_SEARCH_PATH "${SUPRA_SEARCH_PATH}")
else ()
if (WIN32)
# According to JRC the following must be turned off to compile under
# Windows(AP)
# set(SUPRA_SEARCH_PATH $ENV{HOME}/software /winsame/internal /winsame/volatile /winsame/contrib /opt /usr/local)
else ()
# JRC: SUPRA_SEARCH_PATH should include only top directory
# also, system paths should not be needed due to cmake's system search
set(SUPRA_SEARCH_PATH $ENV{HOME}/software /internal /volatile /contrib /opt /usr/local)
endif ()
endif ()
SciPrintString("SUPRA_SEARCH_PATH = ${SUPRA_SEARCH_PATH}")
######################################################################
#
# Get system description
#
######################################################################
find_program(HOSTNAME_CMD NAMES hostname)
exec_program(${HOSTNAME_CMD} ARGS OUTPUT_VARIABLE HOSTNAME)
SciPrintString("scimake running on ${HOSTNAME}")
# This not always accurate
string(REGEX REPLACE "\\..*$" "" UQHOSTNAME "${HOSTNAME}")
SciPrintString("UQHOSTNAME = ${UQHOSTNAME}")
string(REGEX REPLACE "${UQHOSTNAME}\\." "" DOMAINNAME "${HOSTNAME}")
SciPrintString("DOMAINNAME = ${DOMAINNAME}")
find_program(UNAME NAMES uname)
macro(getuname name flag)
exec_program("${UNAME}" ARGS "${flag}" OUTPUT_VARIABLE "${name}")
endmacro(getuname)
if (UNAME)
getuname(osname -s)
getuname(osrel -r)
getuname(cpu -m)
set(HOSTTYPE "${osname}-${cpu}")
SciPrintString("HOSTTYPE = ${HOSTTYPE}")
site_name(HOSTNAME)
SciPrintString("hostname is ${HOSTNAME}")
else ()
message(WARNING "SciInit: find_program for 'uname' returned nothing")
endif ()
######################################################################
#
# Other useful provenance
#
######################################################################
# Calling it "ENV Var" + "NAME" to avoid conflicts elsewhere
set(HOMENAME $ENV{HOME})
set(USERNAME $ENV{USER})
set(SCRATCHNAME $ENV{SCRATCH})
######################################################################
#
# Get revisions
#
######################################################################
include(${SCIMAKE_DIR}/SciSvnInfo.cmake)
######################################################################
#
# config.h
#
######################################################################
if (NOT NO_CONFIG_H)
if (WIN32)
add_definitions(/DHAVE_CONFIG_H)
else ()
add_definitions(-DHAVE_CONFIG_H)
endif ()
endif ()
######################################################################
#
# Fix shared flags on windows
#
######################################################################
include(${SCIMAKE_DIR}/SciWinFlags.cmake)
######################################################################
#
# Load Find Package (also contains code for computing static libraries)
#
######################################################################
include(${SCIMAKE_DIR}/Modules/SciFindPackage.cmake)
######################################################################
#
# C, CXX, Fortran Checks
#
######################################################################
include(${SCIMAKE_DIR}/SciCChecks.cmake)
if (NOT NOCXX)
include(${SCIMAKE_DIR}/SciCxxChecks.cmake)
endif ()
if (NOT NOFORTRAN)
message("")
message("--------- SciFortranChecking ---------")
# Enable Fortran to all those variables
enable_language(Fortran)
include(${CMAKE_ROOT}/Modules/CMakeDetermineFortranCompiler.cmake)
include(${SCIMAKE_DIR}/SciFortranChecks.cmake)
else ()
message(STATUS "[SciInit]: No Fortran, so no implicit fortran link libraries known.")
endif ()
######################################################################
#
# OpenMP, SSE, AVX, OpenCL
#
######################################################################
# option(CHECK_OMP_SSE_AVX "Whether to check for OpenMP, SSE or AVX" TRUE)
if (NOT DEFINED CHECK_OMP_SSE_AVX)
set(CHECK_OMP_SSE_AVX TRUE)
endif ()
if (C_COMPILER AND CHECK_OMP_SSE_AVX)
include(${SCIMAKE_DIR}/SciOmpSseAvx.cmake)
option(ENABLE_OPENCL "Whether to enable OpenCL" OFF)
if (ENABLE_OPENCL)
include(${SCIMAKE_DIR}/Modules/FindSciOpenCL.cmake)
endif ()
include(${SCIMAKE_DIR}/SciMultiArchKernels.cmake)
endif ()
######################################################################
#
# Link checks
#
######################################################################
if (C_COMPILER)
include(${SCIMAKE_DIR}/SciLinkChecks.cmake)
endif ()
######################################################################
#
# Search for static or shared libs?
#
######################################################################
if (C_COMPILER AND ENABLE_SHARED)
message(WARNING "ENABLE_SHARED is deprecated. Use BUILD_SHARED_LIBS.")
if (NOT DEFINED BUILD_SHARED_LIBS)
set(BUILD_SHARED_LIBS TRUE)
endif ()
endif ()
if (C_COMPILER AND BUILD_SHARED_LIBS AND NOT DEFINED USE_SHARED_LIBS)
set(USE_SHARED_LIBS TRUE)
endif ()
######################################################################
#
# For MinGW set libraries to Windows style
#
######################################################################
if (USING_MINGW)
message(STATUS "
")
message("--------- Setting MinGW library prefix and suffix to windows style ---------")
set(CMAKE_STATIC_LIBRARY_PREFIX "")
set(CMAKE_STATIC_LIBRARY_SUFFIX .lib)
message(STATUS "[SciInit]: CMAKE_STATIC_LIBRARY_PREFIX = ${CMAKE_STATIC_LIBRARY_PREFIX}.")
message(STATUS "[SciInit]: CMAKE_STATIC_LIBRARY_SUFFIX = ${CMAKE_STATIC_LIBRARY_SUFFIX}.")
endif ()
######################################################################
#
# Look for MPI
#
######################################################################
option(ENABLE_PARALLEL "Enable parallel build" OFF)
message("")
if (ENABLE_PARALLEL)
message(STATUS "[SciInit]: ENABLE_PARALLEL requested. Will search for MPI.")
elseif (INSTALL_PARALLEL)
message(STATUS "[SciInit]: INSTALL_PARALLEL requested. Will search for MPI.")
else ()
message(STATUS "[SciInit]: Not searching for MPI because ENABLE_PARALLEL or INSTALL_PARALLEL not set.")
endif ()
if (ENABLE_PARALLEL OR INSTALL_PARALLEL)
find_package(SciMpi REQUIRED)
endif ()
######################################################################
#
# Any needed results
#
######################################################################
message(STATUS "
")
cmake_host_system_information(RESULT SCIHOSTNAME QUERY HOSTNAME)
if (NOT RESULTS_DIR)
message(STATUS "[SciInit]: RESULTS_DIR not specified.")
endif ()
if (RESULTS_DIR_BASE AND NOT RESULTS_DIR)
message(STATUS "[SciInit]: Looking for results starting with ${RESULTS_DIR_BASE}.")
# Get potential files
file(GLOB resultsdirs RELATIVE ${CMAKE_SOURCE_DIR}
"${RESULTS_DIR_BASE}-*" "${RESULTS_DIR_BASE}"
)
message(STATUS "[SciInit]: resultsdirs = ${resultsdirs}.")
# Looks for first that is a directory
foreach (resdir ${resultsdirs})
if (IS_DIRECTORY ${CMAKE_SOURCE_DIR}/${resdir})
set(RESULTS_DIR ${CMAKE_SOURCE_DIR}/${resdir})
break()
endif ()
endforeach ()
if (NOT RESULTS_DIR)
message(STATUS "[SciInit]: RESULTS_DIR not found.")
endif ()
endif ()
if (RESULTS_DIR)
message(STATUS "[SciInit]: RESULTS_DIR = ${RESULTS_DIR}.")
endif ()
######################################################################
#
# Testing macros
#
######################################################################
include(${SCIMAKE_DIR}/SciUnitTestMacros.cmake)