ClhepVariables.cmake 22.3 KB
Newer Older
1
#
Lynn Garren's avatar
Lynn Garren committed
2
3
4
# clhep_set_compiler_flags() 
#    sets the default compiler flags
#    calls clhep_autoconf_variables
5
6
7
8
9
10
11
#
# clhep_autoconf_variables() defines global variables
#
# clhep_package_config():
#    defines ${PACKAGE}_LIBS
#    processes ${PACKAGE}-config.in
#    processes ${PACKAGE}-deps.in
Lynn Garren's avatar
Lynn Garren committed
12
#
13
14
15
# clhep_package_config_no_lib():
#    processes ${PACKAGE}-config.in
#
Lynn Garren's avatar
Lynn Garren committed
16
17
# clhep_config():
#    processes clhep-config.in
18
19
20
#
# clhep_lib_suffix();
#    check for -DLIB_SUFFIX=xxx and process intelligently
Lynn Garren's avatar
Lynn Garren committed
21
#
22

23
24
25
26
27
28
# CLHEP_SINGLE_THREAD is OFF (false) by default
option(CLHEP_SINGLE_THREAD "Build without multithreading" OFF)

# CLHEP_BUILD_DOCS is OFF (false) by default
option(CLHEP_BUILD_DOCS "Build and install CLHEP documentation" OFF)

29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
macro( clhep_check_variable_names )
  # useful if you need to check a variable
  message( STATUS "clhep_check_variable_names: CMAKE_SYSTEM_NAME is ${CMAKE_SYSTEM_NAME}" )
  message( STATUS "clhep_check_variable_names: CMAKE_BASE_NAME is ${CMAKE_BASE_NAME}" )
  message( STATUS "clhep_check_variable_names: CMAKE_CXX_COMPILER_ID is ${CMAKE_CXX_COMPILER_ID}" )
  message( STATUS "clhep_check_variable_names: CMAKE_COMPILER_IS_GNUCXX is ${CMAKE_COMPILER_IS_GNUCXX}" )
  message( STATUS "clhep_check_variable_names: CMAKE_COMPILER_IS_MINGW is ${CMAKE_COMPILER_IS_MINGW}" )
  message( STATUS "clhep_check_variable_names: CMAKE_COMPILER_IS_CYGWIN is ${CMAKE_COMPILER_IS_CYGWIN}" )
  message( STATUS "clhep_check_variable_names: CMAKE_AR is ${CMAKE_AR}" )
  message( STATUS "clhep_check_variable_names: CMAKE_RANLIB is ${CMAKE_RANLIB}" )
  message( STATUS "clhep_check_variable_names: CMAKE_CXX_OUTPUT_EXTENSION is ${CMAKE_CXX_OUTPUT_EXTENSION}" )
  message( STATUS "clhep_check_variable_names: CMAKE_SHARED_LIBRARY_CXX_FLAGS is ${CMAKE_SHARED_LIBRARY_CXX_FLAGS}" )
  message( STATUS "clhep_check_variable_names: CMAKE_SHARED_MODULE_CXX_FLAGS is ${CMAKE_SHARED_MODULE_CXX_FLAGS}" )
  message( STATUS "clhep_check_variable_names: CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS is ${CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS}" )
  message( STATUS "clhep_check_variable_names: CMAKE_CXX_FLAGS is ${CMAKE_CXX_FLAGS}" )
  message( STATUS "clhep_check_variable_names: CMAKE_CXX_FLAGS_DEBUG is ${CMAKE_CXX_FLAGS_DEBUG}" )
  message( STATUS "clhep_check_variable_names: CMAKE_CXX_FLAGS_RELEASE is ${CMAKE_CXX_FLAGS_RELEASE}" )
  message( STATUS "clhep_check_variable_names: CMAKE_CXX_FLAGS_RELWITHDEBINFO is ${CMAKE_CXX_FLAGS_RELWITHDEBINFO}" )
  message( STATUS "clhep_check_variable_names: CMAKE_CXX_STANDARD_LIBRARIES is ${CMAKE_CXX_STANDARD_LIBRARIES}" )
  message( STATUS "clhep_check_variable_names: CMAKE_CXX_LINK_FLAGS is ${CMAKE_CXX_LINK_FLAGS}" )
Lynn Garren's avatar
Lynn Garren committed
49
50
  message( STATUS "clhep_check_variable_names: CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS is ${CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS}" )
  message( STATUS "clhep_check_variable_names: CMAKE_SHARED_LINKER_FLAGS is ${CMAKE_SHARED_LINKER_FLAGS}" )
51
52
endmacro( clhep_check_variable_names )

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
macro( clhep_autoconf_variables )

  # these variables are used by <package>-config.in
  # typical values from autoconf:
  #   AM_CXXFLAGS = -O -ansi -pedantic -Wall -D_GNU_SOURCE
  #   CXXFLAGS = -g -O2
  #   CXX = g++
  #   CXXCPP = g++ -E
  #   CPPFLAGS = 
  #   CXXLD = $(CXX)
  #   AM_LDFLAGS = 
  #   LDFLAGS = 
  #   LIBS = 

  # automake/autoconf variables
  set( prefix      ${CMAKE_INSTALL_PREFIX} )
  set( exec_prefix "\${prefix}" )
  set( includedir  "\${prefix}/include" )
  set( configure_input "Generated by cmake" )

  ### autoconf variables typically do not have the path
  set( CXX ${CMAKE_BASE_NAME} )
  set( CXXCPP       "${CXX} -E" )
  if( ${CMAKE_BUILD_TYPE} MATCHES "Debug" )
     set( CXXFLAGS  ${CMAKE_CXX_FLAGS_DEBUG} )
  elseif( ${CMAKE_BUILD_TYPE} MATCHES "Release" )
     set( CXXFLAGS  ${CMAKE_CXX_FLAGS_RELEASE} )
  elseif( ${CMAKE_BUILD_TYPE} MATCHES "RelWithDebInfo" )
     set( CXXFLAGS  ${CMAKE_CXX_FLAGS_RELWITHDEBINFO} )
  elseif( ${CMAKE_BUILD_TYPE} MATCHES "MinSizeRel" )
     set( CXXFLAGS  ${CMAKE_CXX_FLAGS_MINSIZEREL} )
  endif()
  ##message( STATUS "build type ${CMAKE_BUILD_TYPE} has ${CXXFLAGS}")
  set( AM_CXXFLAGS  ${CMAKE_CXX_FLAGS} )
  set( LDFLAGS      ${CMAKE_MODULE_LINKER_FLAGS} )
  set( LIBS         "" )
  set( DIFF_Q       "diff -q -b" )

91
92
93
  if( CLHEP_DEBUG_MESSAGES )
    clhep_check_variable_names()
  endif()
94
95
96

endmacro( clhep_autoconf_variables )

97
98
macro( _clhep_verify_cxx11 )
  if( ${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang" )
99
100
    if( CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.5 )
      message( FATAL_ERROR "CLHEP now requires c++11 support with clang 3.5 or later")
101
102
103
    else()
      set( HAVE_STDCXX true )
    endif()
104
  elseif( ${CMAKE_CXX_COMPILER_ID} STREQUAL "AppleClang" )
105
106
    if( CMAKE_CXX_COMPILER_VERSION VERSION_LESS 6.0 )
      message( FATAL_ERROR "CLHEP now requires c++11 support with Apple Clang 6.0 or later")
107
108
109
    else()
      set( HAVE_STDCXX true )
    endif()
110
  elseif( ${CMAKE_CXX_COMPILER_ID} STREQUAL "Intel" )
Lynn Garren's avatar
Lynn Garren committed
111
    if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 14.0)
112
      message( FATAL_ERROR "c++11 extension is not available for ${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION}")
113
114
115
116
    else()
      set( HAVE_STDCXX true )
    endif()
  elseif(CMAKE_COMPILER_IS_GNUCXX)
Lynn Garren's avatar
Lynn Garren committed
117
118
    if( CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.8 )
      message( FATAL_ERROR "CLHEP now requires c++11 support with gcc 4.8 or later")
Lynn Garren's avatar
Lynn Garren committed
119
    else()
120
      set( HAVE_STDCXX true )
Lynn Garren's avatar
Lynn Garren committed
121
    endif()
122
123
  else()
    message(STATUS "clhep_set_compiler_flags: Do not know how to set c++11 extensions for ${CMAKE_CXX_COMPILER_ID}")
Lynn Garren's avatar
Lynn Garren committed
124
  endif()
125
126
127
128
129
130
131
132
133
endmacro( _clhep_verify_cxx11 )

macro( _clhep_verify_cxx1y )
  if( ${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang" )
    if( CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.5 )
      message( FATAL_ERROR "c++1y extension is not available for ${CMAKE_CXX_COMPILER_ID}${CMAKE_CXX_COMPILER_VERSION}")
    else()
      set( HAVE_STDCXX true )
    endif()
134
  elseif( ${CMAKE_CXX_COMPILER_ID} STREQUAL "AppleClang" )
135
    if( CMAKE_CXX_COMPILER_VERSION VERSION_LESS 6.0 )
136
137
138
139
      message( FATAL_ERROR "c++1y extension is not available for ${CMAKE_CXX_COMPILER_ID}${CMAKE_CXX_COMPILER_VERSION}")
    else()
      set( HAVE_STDCXX true )
    endif()
140
141
142
143
144
145
  elseif( ${CMAKE_CXX_COMPILER_ID} STREQUAL "Intel" )
    if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 15.0)
      message( FATAL_ERROR "c++11 extension is not available for ${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION}")
    else()
      set( HAVE_STDCXX true )
    endif()
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
  elseif(CMAKE_COMPILER_IS_GNUCXX)
    if( CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.9 )
      message( FATAL_ERROR "c++1y extension is not available for ${CMAKE_CXX_COMPILER}")
    else()
      set( HAVE_STDCXX true )
    endif()
  else()
    message(STATUS "clhep_set_compiler_flags: Do not know how to set c++1y extensions for ${CMAKE_CXX_COMPILER_ID}")
  endif()
endmacro( _clhep_verify_cxx1y )

macro( _clhep_verify_cxx14 )
  if( ${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang" )
    if( CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.5 )
      message( FATAL_ERROR "c++14 extension is not available for ${CMAKE_CXX_COMPILER_ID}${CMAKE_CXX_COMPILER_VERSION}")
    else()
      set( HAVE_STDCXX true )
    endif()
164
  elseif( ${CMAKE_CXX_COMPILER_ID} STREQUAL "AppleClang" )
165
    if( CMAKE_CXX_COMPILER_VERSION VERSION_LESS 6.0 )
166
167
168
169
      message( FATAL_ERROR "c++14 extension is not available for ${CMAKE_CXX_COMPILER_ID}${CMAKE_CXX_COMPILER_VERSION}")
    else()
      set( HAVE_STDCXX true )
    endif()
170
171
  elseif( ${CMAKE_CXX_COMPILER_ID} STREQUAL "Intel" )
    if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 16.0)
172
      message( FATAL_ERROR "c++14 extension is not available for ${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION}")
173
174
175
    else()
      set( HAVE_STDCXX true )
    endif()
176
177
178
179
180
181
182
183
184
185
186
  elseif(CMAKE_COMPILER_IS_GNUCXX)
    if( CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.9 )
      message( FATAL_ERROR "c++14 extension is not available for ${CMAKE_CXX_COMPILER}")
    else()
      set( HAVE_STDCXX true )
    endif()
  else()
    message(STATUS "clhep_set_compiler_flags: Do not know how to set c++14 extensions for ${CMAKE_CXX_COMPILER_ID}")
  endif()
endmacro( _clhep_verify_cxx14 )

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
macro( _clhep_verify_cxx1z )
  if( ${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang" )
    if( CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.0 )
      message( FATAL_ERROR "c++1z extension is not available for ${CMAKE_CXX_COMPILER_ID}${CMAKE_CXX_COMPILER_VERSION}")
    else()
      set( HAVE_STDCXX true )
    endif()
  elseif( ${CMAKE_CXX_COMPILER_ID} STREQUAL "AppleClang" )
    if( CMAKE_CXX_COMPILER_VERSION VERSION_LESS 8.0 )
      message( FATAL_ERROR "c++1z extension is not available for ${CMAKE_CXX_COMPILER_ID}${CMAKE_CXX_COMPILER_VERSION}")
    else()
      set( HAVE_STDCXX true )
    endif()
  elseif( ${CMAKE_CXX_COMPILER_ID} STREQUAL "Intel" )
    if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 17.0)
      message( FATAL_ERROR "c++1z extension is not available for ${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION}")
    else()
      set( HAVE_STDCXX true )
    endif()
  elseif(CMAKE_COMPILER_IS_GNUCXX)
    if( CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.0 )
      message( FATAL_ERROR "c++1z extension is not available for ${CMAKE_CXX_COMPILER}")
    else()
      set( HAVE_STDCXX true )
    endif()
  else()
    message(STATUS "clhep_set_compiler_flags: Do not know how to set c++1z extensions for ${CMAKE_CXX_COMPILER_ID}")
  endif()
endmacro( _clhep_verify_cxx1z )

macro( _clhep_verify_cxx17 )
  if( ${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang" )
    if( CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.0 )
      message( FATAL_ERROR "c++17 extension is not available for ${CMAKE_CXX_COMPILER_ID}${CMAKE_CXX_COMPILER_VERSION}")
    else()
      set( HAVE_STDCXX true )
    endif()
  elseif( ${CMAKE_CXX_COMPILER_ID} STREQUAL "AppleClang" )
    if( CMAKE_CXX_COMPILER_VERSION VERSION_LESS 9.0 )
      message( FATAL_ERROR "c++17 extension is not available for ${CMAKE_CXX_COMPILER_ID}${CMAKE_CXX_COMPILER_VERSION}")
    else()
      set( HAVE_STDCXX true )
    endif()
  elseif( ${CMAKE_CXX_COMPILER_ID} STREQUAL "Intel" )
    if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 18.0)
      message( FATAL_ERROR "c++17 extension is not available for ${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION}")
    else()
      set( HAVE_STDCXX true )
    endif()
  elseif(CMAKE_COMPILER_IS_GNUCXX)
    if( CMAKE_CXX_COMPILER_VERSION VERSION_LESS 6.4.0 )
      message( FATAL_ERROR "c++17 extension is not available for ${CMAKE_CXX_COMPILER}")
    else()
      set( HAVE_STDCXX true )
    endif()
  else()
    message(STATUS "clhep_set_compiler_flags: Do not know how to set c++17 extensions for ${CMAKE_CXX_COMPILER_ID}")
  endif()
endmacro( _clhep_verify_cxx17 )

247
macro( _clhep_check_cxxstd )
Lynn Garren's avatar
Lynn Garren committed
248
249
250
251
252
253
254
  if( CLHEP_DEBUG_MESSAGES )
    message(STATUS "_clhep_check_cxxstd debug: CMAKE_CXX_COMPILER: ${CMAKE_CXX_COMPILER}")
    message(STATUS "_clhep_check_cxxstd debug: CMAKE_CXX_COMPILER_ID: ${CMAKE_CXX_COMPILER_ID}")
    message(STATUS "_clhep_check_cxxstd debug: CMAKE_CXX_COMPILER_VERSION: ${CMAKE_CXX_COMPILER_VERSION}")
    message(STATUS "_clhep_check_cxxstd debug: CMAKE_CXX_FLAGS: ${CMAKE_CXX_FLAGS}")
    message(STATUS "_clhep_check_cxxstd debug: CLHEP_BUILD_CXXSTD: ${CLHEP_BUILD_CXXSTD}")
  endif( CLHEP_DEBUG_MESSAGES )
255
256
  set( HAVE_STDCXX )
  if( "${CLHEP_BUILD_CXXSTD}" STREQUAL "-std=c++0x" )
257
    message( FATAL_ERROR "The c++0x extension is no longer supported.  Please use c++11 or later.")
258
259
260
261
262
263
  elseif( "${CLHEP_BUILD_CXXSTD}" STREQUAL "-std=c++11" )
    _clhep_verify_cxx11()
  elseif( "${CLHEP_BUILD_CXXSTD}" STREQUAL "-std=c++1y" )
    _clhep_verify_cxx1y()
  elseif( "${CLHEP_BUILD_CXXSTD}" STREQUAL "-std=c++14" )
    _clhep_verify_cxx14()
264
265
266
267
  elseif( "${CLHEP_BUILD_CXXSTD}" STREQUAL "-std=c++1z" )
    _clhep_verify_cxx1z()
  elseif( "${CLHEP_BUILD_CXXSTD}" STREQUAL "-std=c++17" )
    _clhep_verify_cxx17()
268
269
  elseif( DEFINED CLHEP_BUILD_CXXSTD )
    message( FATAL_ERROR "${CLHEP_BUILD_CXXSTD} is not supported.  Supported extensions are c++11, c++1y, and c++14.")
270
271
272
273
274
275
276
277
  else()
    # presume -std=c++11
    set(CLHEP_BUILD_CXXSTD "-std=c++11")
    _clhep_verify_cxx11( )
  endif()
  ##message(STATUS "_clhep_check_cxxstd debug: CLHEP_BUILD_CXXSTD HAVE_STDCXX: ${CLHEP_BUILD_CXXSTD} ${HAVE_STDCXX}")
  if( DEFINED HAVE_STDCXX )
    if( ${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang" )
Lynn Garren's avatar
Lynn Garren committed
278
	set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CLHEP_BUILD_CXXSTD}" )
279
280
    elseif( ${CMAKE_CXX_COMPILER_ID} STREQUAL "AppleClang" )
	set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CLHEP_BUILD_CXXSTD}" )
281
    elseif( ${CMAKE_CXX_COMPILER_ID} STREQUAL "Intel" )
Lynn Garren's avatar
Lynn Garren committed
282
	set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CLHEP_BUILD_CXXSTD}" )
283
    elseif(CMAKE_COMPILER_IS_GNUCXX)
Lynn Garren's avatar
Lynn Garren committed
284
	set( CMAKE_CXX_FLAGS "${CLHEP_BUILD_CXXSTD} ${CMAKE_CXX_FLAGS} -D_GNU_SOURCE" )
285
    else()
Lynn Garren's avatar
Lynn Garren committed
286
      message(STATUS "clhep_set_compiler_flags: Do not know how to set ${CLHEP_BUILD_CXXSTD} extensions for ${CMAKE_CXX_COMPILER_ID}")
287
288
    endif()
  endif()
Lynn Garren's avatar
Lynn Garren committed
289
290
endmacro( _clhep_check_cxxstd )

291
macro( _clhep_use_pthread )
292
293
294
295
296
297
298
299
300
301
302
    set(CLHEP_THREAD_DEFINITION "#define CLHEP_THREAD_LOCAL thread_local")
    set(THREADS_PREFER_PTHREAD_FLAG ON)
    find_package(Threads)
    ##message(STATUS "clhep_set_compiler_flags debug: CMAKE_CXX_FLAGS: ${CMAKE_CXX_FLAGS}")
    message(STATUS "cmake build type is ${CMAKE_BUILD_TYPE}")
    if(THREADS_HAVE_PTHREAD_ARG) 
      set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread" )
    elseif(CMAKE_COMPILER_IS_GNUCXX)
      # needed when building with gcc on OSX
      set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread" )
    endif()
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
endmacro( _clhep_use_pthread )

macro( clhep_set_compiler_flags )
  ##message(STATUS "incoming cmake build type is ${CMAKE_BUILD_TYPE}")
  if(NOT CMAKE_BUILD_TYPE)
    set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "" FORCE)
  endif()
  _clhep_check_cxxstd()
  # find pthread
  if(CLHEP_SINGLE_THREAD)
    set(CLHEP_THREAD_DEFINITION "#define CLHEP_THREAD_LOCAL")
  elseif(CMAKE_COMPILER_IS_GNUCXX)
    _clhep_use_pthread()
  elseif( ${CMAKE_CXX_COMPILER_ID} STREQUAL "AppleClang" )
    if( CMAKE_CXX_COMPILER_VERSION VERSION_LESS 8.0 )
      set(CLHEP_THREAD_DEFINITION "#define CLHEP_THREAD_LOCAL")
    else()
      _clhep_use_pthread()
    endif()
322
323
324
325
326
327
  elseif( ${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang" )
    if( CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.5 )
      set(CLHEP_THREAD_DEFINITION "#define CLHEP_THREAD_LOCAL")
    else()
      _clhep_use_pthread()
    endif()
328
329
  elseif( ${CMAKE_CXX_COMPILER_ID} STREQUAL "Intel" )
    _clhep_use_pthread()
330
331
  else()
    set(CLHEP_THREAD_DEFINITION "#define CLHEP_THREAD_LOCAL")
332
333
334
  endif()
  if( CLHEP_DEBUG_MESSAGES )
    message(STATUS "enable c++11 extensions: ${CMAKE_CXX_FLAGS}")
Lynn Garren's avatar
Lynn Garren committed
335
  endif()
336
337
338
339
340
  if( CLHEP_DEBUG_MESSAGES )
    message(STATUS "clhep_set_compiler_flags debug: CMAKE_CXX_FLAGS: ${CMAKE_CXX_FLAGS}")
    message(STATUS "clhep_set_compiler_flags debug: cmake compilers ${CMAKE_CXX_COMPILER} ${CMAKE_C_COMPILER}")
  endif( CLHEP_DEBUG_MESSAGES )
  if( CLHEP_DEBUG_MESSAGES )
341
    message(STATUS "using compiler ${CMAKE_CXX_COMPILER_ID}")
342
  endif( CLHEP_DEBUG_MESSAGES )
343
  if( ${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang" )
Lynn Garren's avatar
Lynn Garren committed
344
    set(CMAKE_C_FLAGS "-O -pedantic -Wall ${CMAKE_C_FLAGS}")
345
346
  elseif( ${CMAKE_CXX_COMPILER_ID} STREQUAL "AppleClang" )
    set(CMAKE_C_FLAGS "-O -pedantic -Wall ${CMAKE_C_FLAGS}")
347
348
  elseif( ${CMAKE_CXX_COMPILER_ID} STREQUAL "Intel" )
    set(CMAKE_C_FLAGS "-O -ansi -pedantic -Wall {CMAKE_C_FLAGS}")
Lynn Garren's avatar
Lynn Garren committed
349
    set(CMAKE_CXX_FLAGS "-O -ansi -pedantic -Wall ${CMAKE_CXX_FLAGS}")
Lynn Garren's avatar
Lynn Garren committed
350
  elseif( CMAKE_COMPILER_IS_GNUCC )
Lynn Garren's avatar
Lynn Garren committed
351
    set(CMAKE_C_FLAGS "-O -ansi -pedantic -Wall -D_GNU_SOURCE ${CMAKE_C_FLAGS}")
Lynn Garren's avatar
Lynn Garren committed
352
  endif()
353
  if( ${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang" )
Lynn Garren's avatar
Lynn Garren committed
354
    set(CMAKE_CXX_FLAGS "-O -pedantic -Wall ${CMAKE_CXX_FLAGS}")
355
356
  elseif( ${CMAKE_CXX_COMPILER_ID} STREQUAL "AppleClang" )
    set(CMAKE_CXX_FLAGS "-O -pedantic -Wall ${CMAKE_CXX_FLAGS}")
Lynn Garren's avatar
Lynn Garren committed
357
  elseif(CMAKE_COMPILER_IS_GNUCXX)
Lynn Garren's avatar
Lynn Garren committed
358
    set(CMAKE_CXX_FLAGS "-O -ansi -pedantic -Wall -D_GNU_SOURCE ${CMAKE_CXX_FLAGS}")
Lynn Garren's avatar
Lynn Garren committed
359
  endif()
360
    message(STATUS "clhep_set_compiler_flags debug: CMAKE_CXX_FLAGS: ${CMAKE_CXX_FLAGS}")
Lynn Garren's avatar
Lynn Garren committed
361
362
363
364
365
366
367
368
  # linker flags
    if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
      set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-undefined,error")
    else()
      set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--no-undefined")
    endif()
  message(STATUS "setting CMAKE_SHARED_LINKER_FLAGS ${CMAKE_SHARED_LINKER_FLAGS}")
  # override flags for Windows cl
Lynn Garren's avatar
Lynn Garren committed
369
370
371
372
373
374
  if( ${CMAKE_SYSTEM_NAME} MATCHES "Windows" )
    ##message( STATUS "system is Windows" )
    ##message( STATUS "CMAKE_BASE_NAME is ${CMAKE_BASE_NAME}" )
    if( ${CMAKE_BASE_NAME} MATCHES "cl" )
      ##message( STATUS "compiler is MSVC" )
      ##message( STATUS "incoming basic compiler flags are ${CMAKE_CXX_FLAGS}")
375
376
      set(CMAKE_C_FLAGS "/EHsc /nologo /GR /MD /D USING_VISUAL")
      set(CMAKE_CXX_FLAGS "/EHsc /nologo /GR /MD /D USING_VISUAL")
Lynn Garren's avatar
Lynn Garren committed
377
      set(CMAKE_SHARED_LINKER_FLAGS "/EHsc /nologo /GR /MD /D USING_VISUAL")
Lynn Garren's avatar
Lynn Garren committed
378
379
380
    endif()
  endif()
  clhep_autoconf_variables()
381
  message( STATUS "compiling with ${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_FLAGS} ${CXXFLAGS}")
Lynn Garren's avatar
Lynn Garren committed
382
383
endmacro( clhep_set_compiler_flags )

384
385
386
387
388
389
390
391
macro( clhep_package_config_no_lib )
  set( ${PACKAGE}_CPPFLAGS "-I${includedir}" )
  set( ${PACKAGE}_LDFLAGS  " " )
  set( ${PACKAGE}_LIBS     " " )
  configure_file ( ${CLHEP_SOURCE_DIR}/${PACKAGE}/${PACKAGE}-config.in
                   ${CLHEP_BINARY_DIR}/${PACKAGE}/${PACKAGE}-config @ONLY )
  ## don't install <package>-config on Windows
  if( NOT ${CMAKE_SYSTEM_NAME} MATCHES "Windows" )
392
    install ( PROGRAMS ${CLHEP_BINARY_DIR}/${PACKAGE}/${PACKAGE}-config
393
394
395
396
397
              DESTINATION bin
	    )
  endif()
endmacro( clhep_package_config_no_lib )

398
399
macro( clhep_package_config )
  set( ${PACKAGE}_CPPFLAGS "-I${includedir}" )
Lynn Garren's avatar
Lynn Garren committed
400
  set( ${PACKAGE}_LDFLAGS  "-L\${exec_prefix}/lib${LIB_SUFFIX}" )
401
402
403
404
405
406
407
408
409
410
411
  set( ${PACKAGE}_LIBS     "-lCLHEP-${PACKAGE}-${VERSION}" )
  if( ${PACKAGE}_DEPS )
     foreach ( dep ${${PACKAGE}_DEPS} )
        message( STATUS "${PACKAGE} depends on ${dep}")
	set( ${PACKAGE}_LIBS     "${${PACKAGE}_LIBS} -lCLHEP-${dep}-${VERSION}" )
     endforeach()
  endif()
  configure_file ( ${CLHEP_SOURCE_DIR}/${PACKAGE}/${PACKAGE}-config.in
                   ${CLHEP_BINARY_DIR}/${PACKAGE}/${PACKAGE}-config @ONLY )
  configure_file ( ${CLHEP_SOURCE_DIR}/${PACKAGE}/${PACKAGE}-deps.in
                   ${CLHEP_BINARY_DIR}/${PACKAGE}/${PACKAGE}-deps @ONLY )
Lynn Garren's avatar
Lynn Garren committed
412
413
  ## don't install <package>-config on Windows
  if( NOT ${CMAKE_SYSTEM_NAME} MATCHES "Windows" )
414
    install ( PROGRAMS ${CLHEP_BINARY_DIR}/${PACKAGE}/${PACKAGE}-config
415
416
              DESTINATION bin
	    )
Lynn Garren's avatar
Lynn Garren committed
417
  endif()
418
endmacro( clhep_package_config )
Lynn Garren's avatar
Lynn Garren committed
419

Lynn Garren's avatar
Lynn Garren committed
420
421
422
423
424
macro( clhep_config )
  configure_file ( ${CLHEP_SOURCE_DIR}/clhep-config.in
                   ${CLHEP_BINARY_DIR}/clhep-config @ONLY )
  ## don't install clhep-config on Windows
  if( NOT ${CMAKE_SYSTEM_NAME} MATCHES "Windows" )
425
    install ( PROGRAMS ${CLHEP_BINARY_DIR}/clhep-config
426
427
              DESTINATION bin
	    )
Lynn Garren's avatar
Lynn Garren committed
428
429
  endif()
endmacro( clhep_config )
430

Lynn Garren's avatar
Lynn Garren committed
431
macro( _clhep_lib_suffix_64 )
Lynn Garren's avatar
Lynn Garren committed
432
433
434
435
436
437
438
439
440
441
  if( APPLE )
    #message(STATUS "checking LIB_SUFFIX ${LIB_SUFFIX} against ${CMAKE_SYSTEM_PROCESSOR} and ${CMAKE_OSX_ARCHITECTURES}")
    # On Mac, we use NAME-ARCH, but ARCH is 'Universal' if more than
    # one arch is built for. Note that falling back to use
    # CMAKE_SYSTEM_PROCESSOR may *not* be 100% reliable.
    list(LENGTH CMAKE_OSX_ARCHITECTURES _number_of_arches)
    if(NOT _number_of_arches)
      # - Default
      if (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86_64")
        # building for 64bit
Lynn Garren's avatar
Lynn Garren committed
442
      else()
Lynn Garren's avatar
Lynn Garren committed
443
444
        message(STATUS "WARNING: LIB_SUFFIX ${LIB_SUFFIX} inappropriate for this build")
	set(LIB_SUFFIX "")
Lynn Garren's avatar
Lynn Garren committed
445
      endif()
Lynn Garren's avatar
Lynn Garren committed
446
447
    elseif(_number_of_arches GREATER 1)
      # - Universal
Lynn Garren's avatar
Lynn Garren committed
448
    else()
Lynn Garren's avatar
Lynn Garren committed
449
450
451
      # - Use what the user specified
      if (${CMAKE_OSX_ARCHITECTURES} STREQUAL "x86_64")
        # building for 64bit
452
      else()
Lynn Garren's avatar
Lynn Garren committed
453
454
        message(STATUS "WARNING: LIB_SUFFIX ${LIB_SUFFIX} inappropriate for this build")
	set(LIB_SUFFIX "")
455
      endif()
Lynn Garren's avatar
Lynn Garren committed
456
    endif()
Lynn Garren's avatar
Lynn Garren committed
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
  elseif( ${CMAKE_SYSTEM_NAME} MATCHES "Windows" )
    #message(STATUS "checking LIB_SUFFIX ${LIB_SUFFIX} against ${CMAKE_SYSTEM_PROCESSOR} ")
    if (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86")
      # building for 64bit
    else()
      message(STATUS "WARNING: LIB_SUFFIX ${LIB_SUFFIX} inappropriate for this build")
      set(LIB_SUFFIX "")
    endif()
  else()
    #message(STATUS "checking LIB_SUFFIX ${LIB_SUFFIX} against ${CMAKE_SYSTEM_PROCESSOR} ")
    if (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86_64")
      # building for 64bit
    else()
      message(STATUS "WARNING: LIB_SUFFIX ${LIB_SUFFIX} inappropriate for this build")
      set(LIB_SUFFIX "")
    endif()
  endif()
Lynn Garren's avatar
Lynn Garren committed
474
475
476
endmacro( _clhep_lib_suffix_64 )

macro( _clhep_lib_suffix_32 )
Lynn Garren's avatar
Lynn Garren committed
477
478
479
480
481
482
483
484
485
486
  if( APPLE )
    #message(STATUS "checking LIB_SUFFIX ${LIB_SUFFIX} against ${CMAKE_SYSTEM_PROCESSOR} and ${CMAKE_OSX_ARCHITECTURES}")
    # On Mac, we use NAME-ARCH, but ARCH is 'Universal' if more than
    # one arch is built for. Note that falling back to use
    # CMAKE_SYSTEM_PROCESSOR may *not* be 100% reliable.
    list(LENGTH CMAKE_OSX_ARCHITECTURES _number_of_arches)
    if(NOT _number_of_arches)
      # - Default
      if (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "i386")
        # building for 32bit
Lynn Garren's avatar
Lynn Garren committed
487
      else()
Lynn Garren's avatar
Lynn Garren committed
488
489
        message(STATUS "WARNING: LIB_SUFFIX ${LIB_SUFFIX} inappropriate for this build")
	set(LIB_SUFFIX "")
Lynn Garren's avatar
Lynn Garren committed
490
      endif()
Lynn Garren's avatar
Lynn Garren committed
491
492
    elseif(_number_of_arches GREATER 1)
      # - Universal
Lynn Garren's avatar
Lynn Garren committed
493
    else()
Lynn Garren's avatar
Lynn Garren committed
494
495
496
      # - Use what the user specified
      if (${CMAKE_OSX_ARCHITECTURES} STREQUAL "i386")
        # building for 32bit
497
      else()
Lynn Garren's avatar
Lynn Garren committed
498
499
        message(STATUS "WARNING: LIB_SUFFIX ${LIB_SUFFIX} inappropriate for this build")
	set(LIB_SUFFIX "")
500
      endif()
Lynn Garren's avatar
Lynn Garren committed
501
    endif()
Lynn Garren's avatar
Lynn Garren committed
502
503
504
505
506
507
508
509
510
511
512
  else()
    #message(STATUS "checking LIB_SUFFIX ${LIB_SUFFIX} against ${CMAKE_SYSTEM_PROCESSOR} ")
    if (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "i686")
      # building for 32bit
    elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "i386")
      # building for 32bit
    else()
      message(STATUS "WARNING: LIB_SUFFIX ${LIB_SUFFIX} inappropriate for this build")
      set(LIB_SUFFIX "")
    endif()
  endif()
Lynn Garren's avatar
Lynn Garren committed
513
514
515
516
517
518
519
520
endmacro( _clhep_lib_suffix_32 )

macro( clhep_lib_suffix )
  if(LIB_SUFFIX)
    if ( ${LIB_SUFFIX} STREQUAL "64" )
      _clhep_lib_suffix_64()
    elseif( ${LIB_SUFFIX} STREQUAL "32" )
      _clhep_lib_suffix_32()
521
522
    endif()
  endif()
Lynn Garren's avatar
Lynn Garren committed
523
  message(STATUS "libraries will be installed in $ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}")
524
endmacro( clhep_lib_suffix )
Lynn Garren's avatar
Lynn Garren committed
525
526
527
528
529
530

macro( clhep_enable_asserts )
  string(REGEX REPLACE "-DNDEBUG" " " CXXFLAGS "${CXXFLAGS}" )
  string(TOUPPER ${CMAKE_BUILD_TYPE} BTYPE_UC )
  string(REGEX REPLACE "-DNDEBUG" " " CMAKE_CXX_FLAGS_${BTYPE_UC} "${CMAKE_CXX_FLAGS_${BTYPE_UC}}" )
endmacro( clhep_enable_asserts )