Skip to content

Commit

Permalink
[FIXUP] cmake: Rework PIC/PIE logic
Browse files Browse the repository at this point in the history
Must be squashed with the commit 91f28a6
"cmake: Add root `CMakeLists.txt` file".
  • Loading branch information
hebasto committed Mar 24, 2023
1 parent a8917ab commit b0351e3
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,6 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

set(configure_warnings)
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.14)
include(CheckPIESupported)
check_pie_supported(OUTPUT_VARIABLE check_pie_output LANGUAGES CXX)
if(NOT CMAKE_CXX_LINK_PIE_SUPPORTED)
list(APPEND configure_warnings "PIE link options are not supported for executable targets: ${check_pie_output}.")
endif()
else()
list(APPEND configure_warnings "No PIE options will be passed to a linker for executable targets.")
endif()
set(CMAKE_POSITION_INDEPENDENT_CODE ON)

if(WIN32)
#[=[
Expand Down Expand Up @@ -123,6 +113,19 @@ include(cmake/secp256k1.cmake)
include(CheckStdFilesystem)
check_std_filesystem()

if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.14)
include(CheckPIESupported)
check_pie_supported(OUTPUT_VARIABLE check_pie_output LANGUAGES CXX)
if(CMAKE_CXX_LINK_PIE_SUPPORTED)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
endif()
else()
check_cxx_source_links_with_flags(-fPIE "int main(){}" COMPILER_SUPPORTS_PIE)
if(COMPILER_SUPPORTS_PIE)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
endif()
endif()

add_subdirectory(src)

message("\n")
Expand Down

0 comments on commit b0351e3

Please sign in to comment.