ClhepVariables.cmake 11.8 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
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

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
  ##get_filename_component( CXX ${CMAKE_CXX_COMPILER} NAME )
  ##if( ${CXX} MATCHES "c\\+\\+" )
  ##   set( CXX g++ )
  ##endif()
  set( CXX ${CMAKE_BASE_NAME} )
  ##get_filename_component( AR ${CMAKE_AR} NAME )
  ##get_filename_component( RANLIB ${CMAKE_RANLIB} 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" )

  ### useful if you need to check a variable
Lynn Garren's avatar
tweaks    
Lynn Garren committed
67
68
69
  ##message( STATUS "CMAKE_SYSTEM_NAME is ${CMAKE_SYSTEM_NAME}" )
  ##message( STATUS "CMAKE_BASE_NAME is ${CMAKE_BASE_NAME}" )
  ##message( STATUS "CMAKE_CXX_COMPILER_ID is ${CMAKE_CXX_COMPILER_ID}" )
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
  ##message( STATUS "CMAKE_COMPILER_IS_GNUCXX is ${CMAKE_COMPILER_IS_GNUCXX}" )
  ##message( STATUS "CMAKE_COMPILER_IS_MINGW is ${CMAKE_COMPILER_IS_MINGW}" )
  ##message( STATUS "CMAKE_COMPILER_IS_CYGWIN is ${CMAKE_COMPILER_IS_CYGWIN}" )
  ##message( STATUS "CMAKE_AR is ${CMAKE_AR}" )
  ##message( STATUS "CMAKE_RANLIB is ${CMAKE_RANLIB}" )
  ##message( STATUS "CMAKE_CXX_OUTPUT_EXTENSION is ${CMAKE_CXX_OUTPUT_EXTENSION}" )
  ##message( STATUS "CMAKE_SHARED_LIBRARY_CXX_FLAGS is ${CMAKE_SHARED_LIBRARY_CXX_FLAGS}" )
  ##message( STATUS "CMAKE_SHARED_MODULE_CXX_FLAGS is ${CMAKE_SHARED_MODULE_CXX_FLAGS}" )
  ##message( STATUS "CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS is ${CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS}" )
  ##message( STATUS "CMAKE_CXX_FLAGS is ${CMAKE_CXX_FLAGS}" )
  ##message( STATUS "CMAKE_CXX_FLAGS_DEBUG is ${CMAKE_CXX_FLAGS_DEBUG}" )
  ##message( STATUS "CMAKE_CXX_FLAGS_RELEASE is ${CMAKE_CXX_FLAGS_RELEASE}" )
  ##message( STATUS "CMAKE_CXX_FLAGS_RELWITHDEBINFO is ${CMAKE_CXX_FLAGS_RELWITHDEBINFO}" )
  ##message( STATUS "CMAKE_CXX_STANDARD_LIBRARIES is ${CMAKE_CXX_STANDARD_LIBRARIES}" )
  ##message( STATUS "CMAKE_CXX_LINK_FLAGS is ${CMAKE_CXX_LINK_FLAGS}" )

endmacro( clhep_autoconf_variables )

Lynn Garren's avatar
Lynn Garren committed
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
macro( _clhep_check_cxxstd )
  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}")
  get_filename_component(clhep_cxx_compiler ${CMAKE_CXX_COMPILER} NAME)
  if( ${clhep_cxx_compiler} STREQUAL "clang++" )
    if( CMAKE_CXX_COMPILER_VERSION VERSION_LESS 2.9 )
      message( FATAL_ERROR "c++11 extensions are not available for ${CMAKE_CXX_COMPILER_ID}${CMAKE_CXX_COMPILER_VERSION}")
    else()
      set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -ftls-model=initial-exec -pthread -Wno-deprecated-declarations" )
    endif()
  elseif(CMAKE_COMPILER_IS_GNUCXX)
    if( CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.3 )
      message( FATAL_ERROR "c++11 extensions are not available for ${CMAKE_CXX_COMPILER_ID}${CMAKE_CXX_COMPILER_VERSION}")
    elseif( CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.7 )
      set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x  -ftls-model=initial-exec -pthread -Wno-deprecated-declarations" )
    else()
      set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -ftls-model=initial-exec -pthread -Wno-deprecated-declarations" )
    endif()
  endif()
endmacro( _clhep_check_cxxstd )

Lynn Garren's avatar
Lynn Garren committed
110
111
112
113
114
115
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()
  message(STATUS "cmake build type is ${CMAKE_BUILD_TYPE}")
Lynn Garren's avatar
Lynn Garren committed
116
117
118
119
  if( CLHEP_BUILD_CXXSTD )
     _clhep_check_cxxstd()
     message(STATUS "enable c++11 extensions: ${CMAKE_CXX_FLAGS}")
  endif()
Lynn Garren's avatar
Lynn Garren committed
120
121
122
123
124
125
126
  #message(STATUS "cmake compilers ${CMAKE_CXX_COMPILER} ${CMAKE_C_COMPILER}")
  get_filename_component(clhep_cxx_compiler ${CMAKE_CXX_COMPILER} NAME)
  get_filename_component(clhep_c_compiler ${CMAKE_C_COMPILER} NAME)
  #message(STATUS "using compilers ${clhep_cxx_compiler} ${clhep_c_compiler}")
  if( ${clhep_c_compiler} STREQUAL "clang" )
    set(CMAKE_C_FLAGS "-O -pedantic -Wall ${CMAKE_C_FLAGS}")
  elseif( CMAKE_COMPILER_IS_GNUCC )
Lynn Garren's avatar
Lynn Garren committed
127
    set(CMAKE_C_FLAGS "-O -ansi -pedantic -Wall -D_GNU_SOURCE ${CMAKE_C_FLAGS}")
Lynn Garren's avatar
Lynn Garren committed
128
129
130
131
  endif()
  if( ${clhep_cxx_compiler} STREQUAL "clang++" )
    set(CMAKE_CXX_FLAGS "-O -pedantic -Wall ${CMAKE_CXX_FLAGS}")
  elseif(CMAKE_COMPILER_IS_GNUCXX)
Lynn Garren's avatar
Lynn Garren committed
132
    set(CMAKE_CXX_FLAGS "-O -ansi -pedantic -Wall -D_GNU_SOURCE ${CMAKE_CXX_FLAGS}")
Lynn Garren's avatar
Lynn Garren committed
133
  endif()
Lynn Garren's avatar
Lynn Garren committed
134
135
136
137
138
139
  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}")
140
141
      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
142
143
144
    endif()
  endif()
  clhep_autoconf_variables()
Lynn Garren's avatar
Lynn Garren committed
145
  message( STATUS "compiling with ${clhep_cxx_compiler} ${CMAKE_CXX_FLAGS} ${CXXFLAGS}")
Lynn Garren's avatar
Lynn Garren committed
146
147
endmacro( clhep_set_compiler_flags )

148
149
150
151
152
153
154
155
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" )
156
    install ( PROGRAMS ${CLHEP_BINARY_DIR}/${PACKAGE}/${PACKAGE}-config
157
158
159
160
161
              DESTINATION bin
	    )
  endif()
endmacro( clhep_package_config_no_lib )

162
163
macro( clhep_package_config )
  set( ${PACKAGE}_CPPFLAGS "-I${includedir}" )
Lynn Garren's avatar
Lynn Garren committed
164
  set( ${PACKAGE}_LDFLAGS  "-L\${exec_prefix}/lib${LIB_SUFFIX}" )
165
166
167
168
169
170
171
172
173
174
175
  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
176
177
  ## don't install <package>-config on Windows
  if( NOT ${CMAKE_SYSTEM_NAME} MATCHES "Windows" )
178
    install ( PROGRAMS ${CLHEP_BINARY_DIR}/${PACKAGE}/${PACKAGE}-config
179
180
              DESTINATION bin
	    )
Lynn Garren's avatar
Lynn Garren committed
181
  endif()
182
endmacro( clhep_package_config )
Lynn Garren's avatar
Lynn Garren committed
183

Lynn Garren's avatar
Lynn Garren committed
184
185
186
187
188
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" )
189
    install ( PROGRAMS ${CLHEP_BINARY_DIR}/clhep-config
190
191
              DESTINATION bin
	    )
Lynn Garren's avatar
Lynn Garren committed
192
193
  endif()
endmacro( clhep_config )
194

Lynn Garren's avatar
Lynn Garren committed
195
macro( _clhep_lib_suffix_64 )
Lynn Garren's avatar
Lynn Garren committed
196
197
198
199
200
201
202
203
204
205
  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
206
      else()
Lynn Garren's avatar
Lynn Garren committed
207
208
        message(STATUS "WARNING: LIB_SUFFIX ${LIB_SUFFIX} inappropriate for this build")
	set(LIB_SUFFIX "")
Lynn Garren's avatar
Lynn Garren committed
209
      endif()
Lynn Garren's avatar
Lynn Garren committed
210
211
    elseif(_number_of_arches GREATER 1)
      # - Universal
Lynn Garren's avatar
Lynn Garren committed
212
    else()
Lynn Garren's avatar
Lynn Garren committed
213
214
215
      # - Use what the user specified
      if (${CMAKE_OSX_ARCHITECTURES} STREQUAL "x86_64")
        # building for 64bit
216
      else()
Lynn Garren's avatar
Lynn Garren committed
217
218
        message(STATUS "WARNING: LIB_SUFFIX ${LIB_SUFFIX} inappropriate for this build")
	set(LIB_SUFFIX "")
219
      endif()
Lynn Garren's avatar
Lynn Garren committed
220
    endif()
Lynn Garren's avatar
Lynn Garren committed
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
  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
238
239
240
endmacro( _clhep_lib_suffix_64 )

macro( _clhep_lib_suffix_32 )
Lynn Garren's avatar
Lynn Garren committed
241
242
243
244
245
246
247
248
249
250
  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
251
      else()
Lynn Garren's avatar
Lynn Garren committed
252
253
        message(STATUS "WARNING: LIB_SUFFIX ${LIB_SUFFIX} inappropriate for this build")
	set(LIB_SUFFIX "")
Lynn Garren's avatar
Lynn Garren committed
254
      endif()
Lynn Garren's avatar
Lynn Garren committed
255
256
    elseif(_number_of_arches GREATER 1)
      # - Universal
Lynn Garren's avatar
Lynn Garren committed
257
    else()
Lynn Garren's avatar
Lynn Garren committed
258
259
260
      # - Use what the user specified
      if (${CMAKE_OSX_ARCHITECTURES} STREQUAL "i386")
        # building for 32bit
261
      else()
Lynn Garren's avatar
Lynn Garren committed
262
263
        message(STATUS "WARNING: LIB_SUFFIX ${LIB_SUFFIX} inappropriate for this build")
	set(LIB_SUFFIX "")
264
      endif()
Lynn Garren's avatar
Lynn Garren committed
265
    endif()
Lynn Garren's avatar
Lynn Garren committed
266
267
268
269
270
271
272
273
274
275
276
  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
277
278
279
280
281
282
283
284
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()
285
286
    endif()
  endif()
Lynn Garren's avatar
Lynn Garren committed
287
  message(STATUS "libraries will be installed in $ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}")
288
endmacro( clhep_lib_suffix )