Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Linker #121

Merged
merged 2 commits into from
Nov 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ configure_file (

LIST( APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake )

option(LCIO_SET_RPATH "Link libraries with built-in RPATH (run-time search path)" ON)

#FIND_PACKAGE( ILCUTIL COMPONENTS ILCSOFT_CMAKE_MODULES REQUIRED )

# load default settings from ILCSOFT_CMAKE_MODULES
Expand Down
52 changes: 30 additions & 22 deletions cmake/ilcsoft_default_cxx_flags.cmake
Original file line number Diff line number Diff line change
@@ -1,35 +1,43 @@
## Set the default compiler flags for all projects picking up default ilcutil settings
## This runs checks if compilers support the flag and sets them, if they do
## this will create a humongous amount of warnings when compiling :)
include(CheckCXXCompilerFlag)

INCLUDE(CheckCXXCompilerFlag)
SET(COMPILER_FLAGS -Wall -Wdeprecated -Weffc++ -Wextra -Wformat-security -Wno-long-long -Wno-non-virtual-dtor -Wshadow -Wuninitialized -pedantic -fdiagnostics-color=auto)

SET(COMPILER_FLAGS -Wall -Wextra -Wshadow -Weffc++ -pedantic -Wno-long-long -Wuninitialized -Wno-non-virtual-dtor -Wheader-hygiene)
# 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()

IF( "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" )
LIST( APPEND COMPILER_FLAGS -Wl,-no-undefined )
ENDIF()


MESSAGE( STATUS "FLAGS ${COMPILER_FLAGS}" )
FOREACH( FLAG ${COMPILER_FLAGS} )

## 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" )
### We prepend the flag, so they are overwritten by whatever the user sets in his own configuration
SET ( CMAKE_CXX_FLAGS "${FLAG} ${CMAKE_CXX_FLAGS}")
MESSAGE("Adding ${FLAG} to CXX_FLAGS" )
SET ( CMAKE_CXX_FLAGS "${FLAG} ${CMAKE_CXX_FLAGS} ")
ELSE()
MESSAGE ( STATUS "NOT Adding ${FLAG} to CXX_FLAGS" )
MESSAGE("NOT Adding ${FLAG} to CXX_FLAGS" )
ENDIF()
ENDFOREACH()

IF( "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.9 )
SET( CMAKE_CXX_FLAGS "-fdiagnostics-color=auto ${CMAKE_CXX_FLAGS}" )
ENDIF()
# resolve which linker we use
execute_process(COMMAND ${CMAKE_CXX_COMPILER} -Wl,--version OUTPUT_VARIABLE stdout ERROR_QUIET)
if("${stdout}" MATCHES "GNU ")
set(LINKER_TYPE "GNU")
else()
execute_process(COMMAND ${CMAKE_CXX_COMPILER} -Wl,-v ERROR_VARIABLE stderr )
if(("${stderr}" MATCHES "PROGRAM:ld") AND ("${stderr}" MATCHES "PROJECT:ld64"))
set(LINKER_TYPE "APPLE")
else()
set(LINKER_TYPE "unknown")
MESSAGE("Detected unknown linker: ${stdout} ${stderr}" )
endif()
endif()

if("${LINKER_TYPE}" STREQUAL "APPLE")
SET ( CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-undefined,error")
elseif("${LINKER_TYPE}" STREQUAL "GNU")
SET ( CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--no-undefined")
else()
MESSAGE( WARNING "No known linker (GNU or Apple) has been detected, pass no flags to linker" )
endif()
19 changes: 16 additions & 3 deletions cmake/ilcsoft_default_rpath_settings.cmake
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@
#---RPATH options-------------------------------------------------------------------------------
# When building, don't use the install RPATH already (but later on when installing)
set(CMAKE_SKIP_BUILD_RPATH FALSE) # don't skip the full RPATH for the build tree
set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE) # use always the build RPATH for the build tree
set(CMAKE_MACOSX_RPATH TRUE) # use RPATH for MacOSX
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) # point to directories outside the build tree to the install RPATH

set(CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_FULL_LIBDIR}) # install LIBDIR
set(CMAKE_SKIP_INSTALL_RPATH FALSE) # don't skip the full RPATH for the install tree
# Check whether to add RPATH to the installation (the build tree always has the RPATH enabled)
if(APPLE)
set(CMAKE_INSTALL_NAME_DIR "@rpath")
set(CMAKE_INSTALL_RPATH "@loader_path/../lib") # self relative LIBDIR
set(CMAKE_SKIP_INSTALL_RPATH FALSE) # don't skip the full RPATH for the install tree
# 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 "@loader_path/../lib")
endif("${isSystemDir}" STREQUAL "-1")
elseif(LCIO_SET_RPATH)
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib") # install LIBDIR
# 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")
else()
set(CMAKE_SKIP_INSTALL_RPATH TRUE) # skip the full RPATH for the install tree
endif()