Newer
Older
#=================================================================================
#
#---------------------------------------------------------------------------------
# Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
# All rights reserved.
#
# For the licensing terms see $DD4hepINSTALL/LICENSE.
# For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
#
#=================================================================================
Andre Sailer
committed
message ( STATUS "INCLUDING DD4hepBuild.cmake" )
include ( CMakeParseArguments )
#---------------------------------------------------------------------------------------------------
macro(dd4hep_to_parent_scope val)
set ( ${val} ${${val}} PARENT_SCOPE )
endmacro(dd4hep_to_parent_scope)
#---------------------------------------------------------------------------------------------------
# MACRO: dd4hep_set_compiler_flags
#
# Set compiler flags
#
# \author M.Frank
# \version 1.0
#
#---------------------------------------------------------------------------------------------------
macro(dd4hep_set_compiler_flags)
SET(COMPILER_FLAGS -Wall -Wextra -pedantic -Wshadow -Wformat-security -Wno-long-long -Wdeprecated -fdiagnostics-color=auto)
# AppleClang/Clang specific warning flags
if(CMAKE_CXX_COMPILER_ID MATCHES "^(Apple)?Clang$")
set ( COMPILER_FLAGS ${COMPILER_FLAGS} -Winconsistent-missing-override -Wno-c++1z-extensions -Wheader-hygiene )
endif()
## meed to replace the minus or plus signs from the variables, because it is passed
## as a macro to g++ which causes a warning about no whitespace after macro
## definition
STRING(REPLACE "-" "_" FLAG_WORD ${FLAG} )
STRING(REPLACE "+" "P" FLAG_WORD ${FLAG_WORD} )
CHECK_CXX_COMPILER_FLAG( "${FLAG}" CXX_FLAG_WORKS_${FLAG_WORD} )
IF( ${CXX_FLAG_WORKS_${FLAG_WORD}} )
MESSAGE ( STATUS "Adding ${FLAG} to CXX_FLAGS" )
SET ( CMAKE_CXX_FLAGS "${FLAG} ${CMAKE_CXX_FLAGS} ")
ELSE()
MESSAGE ( STATUS "NOT Adding ${FLAG} to CXX_FLAGS" )
ENDIF()
ENDFOREACH()
CHECK_CXX_COMPILER_FLAG("-ftls-model=global-dynamic" CXX_FLAG_WORKS_FTLS_global_dynamic)
if (CXX_FLAG_WORKS_FTLS_global_dynamic)
set ( CMAKE_CXX_FLAGS "-ftls-model=global-dynamic ${CMAKE_CXX_FLAGS} ")
else()
message( FATAL_ERROR "The provided compiler does not support the flag -ftls-model=global-dynamic" )
endif()
find_package(Threads REQUIRED)
Marko Petric
committed
if ( THREADS_HAVE_PTHREAD_ARG OR CMAKE_USE_PTHREADS_INIT )
set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
SET ( CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -pthread")
elseif ( CMAKE_THREAD_LIBS_INIT )
SET ( CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${CMAKE_THREAD_LIBS_INIT}")
# Assume standard gcc and pthreads library
SET ( CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -pthread")
message( STATUS "Unknown thread library: CMAKE_SHARED_LINKER_FLAGS ${CMAKE_SHARED_LINKER_FLAGS}" )
Marko Petric
committed
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang")
SET ( CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-undefined,error")
elseif ( ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") OR ( "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" ))
SET ( CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--no-undefined")
else()
MESSAGE( WARNING "We do not test with the ${CMAKE_CXX_COMPILER_ID} compiler, use at your own discretion" )
# 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")
endmacro(dd4hep_set_compiler_flags)
#---------------------------------------------------------------------------------------------------
# dd4hep_debug
#
# Print messages if debug flag is enabled
#
# \author M.Frank
# \version 1.0
#
#---------------------------------------------------------------------------------------------------
function ( dd4hep_debug msg )
if( NOT "${DD4HEP_DEBUG_CMAKE}" STREQUAL "" )
get_property(pkg DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY PACKAGE_NAME)
string ( LENGTH "${msg}" lmsg )
if ( ${lmsg} GREATER 1024 )
string ( SUBSTRING "${msg}" 0 132 pmsg )
message( STATUS "D++> [${pkg}] ${pmsg}" )
else()
message( STATUS "D++> [${pkg}] ${msg}" )
endif()
endif()
endfunction( dd4hep_debug )
#---------------------------------------------------------------------------------------------------
# dd4hep_include_directories
#
# Same as include_directories but treat all external packages as SYSTEM -> no warnings
#
# \author A.Sailer
# \version 1.0
#
#---------------------------------------------------------------------------------------------------
function ( dd4hep_include_directories pkg_incs )
FOREACH( INCDIR ${pkg_incs} )
string(FIND "${INCDIR}" "${CMAKE_SOURCE_DIR}" out)
IF("${out}" EQUAL 0)
INCLUDE_DIRECTORIES( ${INCDIR} )
ELSE()
INCLUDE_DIRECTORIES( SYSTEM ${INCDIR} )
ENDIF()
ENDFOREACH()
endfunction( dd4hep_include_directories )
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
#---------------------------------------------------------------------------------------------------
# dd4hep_print
#
#
# \author M.Frank
# \version 1.0
#
#---------------------------------------------------------------------------------------------------
function ( dd4hep_print msg )
message ( STATUS ${msg} )
endfunction ( dd4hep_print )
function ( dd4hep_skipmsg msg )
message ( STATUS "SKIPPED !!!!!!!!!!!!!! ${msg}" )
endfunction ( dd4hep_skipmsg )
#---------------------------------------------------------------------------------------------------
# dd4hep_fatal
#
#
# \author M.Frank
# \version 1.0
#
#---------------------------------------------------------------------------------------------------
function ( dd4hep_fatal msg )
get_property(pkg DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY PACKAGE_NAME)
if ( "${pkg}" STREQUAL "" )
message ( FATAL_ERROR "++> ${msg}" )
else()
message ( FATAL_ERROR "++> [${pkg}] ${msg}" )
endif()
endfunction ( dd4hep_fatal )
#---------------------------------------------------------------------------------------------------
# dd4hep_set_version
#
# Set version structure for building the DD4hep software
#
# \author M.Frank
# \version 1.0
#
#---------------------------------------------------------------------------------------------------
function ( dd4hep_set_version packageName )
cmake_parse_arguments ( ARG "" "MAJOR;MINOR;PATCH" "" ${ARGN} )
if ( NOT "${packageName}" STREQUAL "" )
project ( ${packageName} )
else()
dd4hep_fatal ( "${packageName}: !!! Attempt to define a DD4hep project without a name !!!" )
Loading
Loading full blame...