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 26, 2023
1 parent ddbafc0 commit b58e1fc
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ project(
cmake_policy(SET CMP0015 NEW)
cmake_policy(SET CMP0048 NEW)
cmake_policy(SET CMP0053 NEW)
cmake_policy(SET CMP0063 NEW)
cmake_policy(SET CMP0054 NEW)
cmake_policy(SET CMP0058 NEW)
cmake_policy(SET CMP0063 NEW)
cmake_policy(SET CMP0083 NEW)

# Do not add warning flags for MSVC cmake_policy(SET CMP0092 NEW)

Expand Down Expand Up @@ -107,14 +108,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 +116,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 +153,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 +180,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 b58e1fc

Please sign in to comment.