Skip to content

Commit

Permalink
Update position independent code settings
Browse files Browse the repository at this point in the history
The position independent code settings are since CMake 3.14 handled with
the POSITION_INDEPENDENT_CODE target property. This automatically sets
the proper linker flags to achieve this objective for all supported
toolchains.
  • Loading branch information
folmos-at-orange committed Oct 4, 2023
1 parent ff6de69 commit 16c5fc9
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,6 @@ message(STATUS "Libraries will be stored in ${CMAKE_BINARY_DIR}/lib/")
# Set module path for the project
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/packaging")

# Use "-fPIC" / "-fPIE" for all targets by default, including static libs
set(CMAKE_POSITION_INDEPENDENT_CODE ON)

# CMake doesn't add "-pie" by default for executables (CMake issue #14983)
if(NOT MSVC OR NOT APPLE)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pie")
endif()

set(CMAKE_CXX_VISIBILITY_PRESET hidden)
set(CMAKE_VISIBILITY_INLINES_HIDDEN 1)

Expand All @@ -123,7 +115,7 @@ if(CMAKE_BUILD_TYPE EQUAL "Debug")
set(LLVM_REQUIRES_RTTI 1)
endif()

# Process dependencies Find MPI if required
# Process dependencies: Find MPI if required
if(MPI)
find_package(MPI 2.0 REQUIRED)
message(
Expand Down Expand Up @@ -160,6 +152,10 @@ if(BUILD_JARS)
# - find_package(Java 1.8 EXACT REQUIRED COMPONENTS Development)
endif()

# Check for support of position independent code/executable
include(CheckPIESupported)
check_pie_supported()

# Message the current C++ configuration
message(STATUS "CMake generator is: ${CMAKE_GENERATOR}")
message(STATUS "CMake compiler is: ${CMAKE_CXX_COMPILER_ID}")
Expand All @@ -183,15 +179,16 @@ function(set_khiops_options target)
get_target_property(target_type ${target} TYPE)
message(STATUS "Setting up ${target_type} ${target}")

# General compiler definitions
# General compiler properties and definitions
set_property(TARGET ${target} PROPERTY POSITION_INDEPENDENT_CODE TRUE)
target_compile_definitions(${target} PRIVATE UNICODE _UNICODE)
if(MPI)
target_compile_definitions(${target} PRIVATE USE_MPI)
endif()

target_compile_definitions(${target} PRIVATE $<$<CONFIG:RELEASE,RELWITHDEBINFO>:NOALL>)
target_compile_definitions(${target} PRIVATE $<$<CONFIG:RELWITHDEBINFO>:__ALPHA__>)

# Delegate to specialized function for Windows and Unix-like
if(MSVC)
set_msvc_khiops_options(${target})
else()
Expand Down

0 comments on commit 16c5fc9

Please sign in to comment.