Skip to content

Commit b0351e3

Browse files
committed
[FIXUP] cmake: Rework PIC/PIE logic
Must be squashed with the commit 91f28a6 "cmake: Add root `CMakeLists.txt` file".
1 parent a8917ab commit b0351e3

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

CMakeLists.txt

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,6 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
5252
set(CMAKE_CXX_EXTENSIONS OFF)
5353

5454
set(configure_warnings)
55-
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.14)
56-
include(CheckPIESupported)
57-
check_pie_supported(OUTPUT_VARIABLE check_pie_output LANGUAGES CXX)
58-
if(NOT CMAKE_CXX_LINK_PIE_SUPPORTED)
59-
list(APPEND configure_warnings "PIE link options are not supported for executable targets: ${check_pie_output}.")
60-
endif()
61-
else()
62-
list(APPEND configure_warnings "No PIE options will be passed to a linker for executable targets.")
63-
endif()
64-
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
6555

6656
if(WIN32)
6757
#[=[
@@ -123,6 +113,19 @@ include(cmake/secp256k1.cmake)
123113
include(CheckStdFilesystem)
124114
check_std_filesystem()
125115

116+
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.14)
117+
include(CheckPIESupported)
118+
check_pie_supported(OUTPUT_VARIABLE check_pie_output LANGUAGES CXX)
119+
if(CMAKE_CXX_LINK_PIE_SUPPORTED)
120+
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
121+
endif()
122+
else()
123+
check_cxx_source_links_with_flags(-fPIE "int main(){}" COMPILER_SUPPORTS_PIE)
124+
if(COMPILER_SUPPORTS_PIE)
125+
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
126+
endif()
127+
endif()
128+
126129
add_subdirectory(src)
127130

128131
message("\n")

0 commit comments

Comments
 (0)