Skip to content

Commit 1326d81

Browse files
committed
cmake: use debian bullseye compatibility (again)
- use CMAKE_POSITION_INDEPENDENT_CODE instead of custom PIE var - specify -fPIE manually for cmake older than 3.14
1 parent 2ff7fc5 commit 1326d81

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

CMakeLists.txt

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
# SOFTWARE.
2424
#
2525

26-
cmake_minimum_required(VERSION 3.14)
26+
cmake_minimum_required(VERSION 3.13.4)
2727

2828
if(NOT CMAKE_BUILD_TYPE)
2929
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build, options are: Debug, Release, or MinSizeRel." FORCE)
@@ -70,7 +70,9 @@ option(LTO "Check for IPO/LTO support and enable, if supported. May require gold
7070
option(LINT_EGL_HEADERS "Set an define that'll make the egl.h only export the extension definitions, prototypes that are explicitly marked as required." OFF)
7171
option(DEBUG_DRM_PLANE_ALLOCATIONS "Add logging in modesetting.c for debugging the process of choosing a fitting DRM plane for a framebuffer layer." OFF)
7272
option(USE_LEGACY_KMS "Force the use of legacy KMS." OFF)
73-
option(PIE "Compile as position-independent executable." OFF)
73+
74+
# This is a CMake recognized variable, but we set it to off by default here.
75+
option(CMAKE_POSITION_INDEPENDENT_CODE "Enable/Disable Position Independent Code" OFF)
7476

7577
set(FILESYSTEM_LAYOUTS default meta-flutter)
7678
set(FILESYSTEM_LAYOUT "default" CACHE STRING "Where to look for the icudtl.dat, app.so/libapp.so, flutter asset bundle.")
@@ -82,7 +84,6 @@ option(SENTRY_PLUGIN_BUNDLE_CRASHPAD_HANDLER "Bundle the crashpad_handler with t
8284
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
8385

8486
include(CheckCCompilerFlag)
85-
include(CheckPIESupported)
8687

8788
# Those libraries we definitely need.
8889
include(FindPkgConfig)
@@ -103,14 +104,19 @@ add_executable(
103104
src/main.c
104105
)
105106

106-
# disable PIE for the main executable
107-
check_pie_supported(OUTPUT_VARIABLE CHECK_PIE_SUPPORTED_OUTPUT LANGUAGES CXX)
108-
set_property(TARGET flutter-pi PROPERTY POSITION_INDEPENDENT_CODE ${PIE})
109-
if(NOT CMAKE_CXX_LINK_PIE_SUPPORTED)
110-
message(WARNING "PIE is not supported at link time: ${CHECK_PIE_SUPPORTED_OUTPUT}.\n"
111-
"PIE link options will not be passed to linker.")
107+
# If position independent code is selected, set it for the executable.
108+
if(POLICY CMP0083)
109+
cmake_policy(SET CMP0083 NEW)
110+
111+
include(CheckPIESupported)
112+
check_pie_supported()
113+
else()
114+
if (CMAKE_POSITION_INDEPENDENT_CODE)
115+
target_link_options(flutter-pi PUBLIC -fPIE)
116+
endif()
112117
endif()
113-
message(STATUS "PIE .................... ${PIE}")
118+
119+
message(STATUS "PIE .................... ${CMAKE_POSITION_INDEPENDENT_CODE}")
114120

115121
# flutterpi_module
116122
# We separate the actual flutter-pi code into a separate object library
@@ -143,9 +149,6 @@ add_library(
143149
src/plugins/services.c
144150
)
145151

146-
# Disable PIC again just to make sure.
147-
set_property(TARGET flutterpi_module PROPERTY POSITION_INDEPENDENT_CODE ${PIE})
148-
149152
target_link_libraries(flutterpi_module PUBLIC
150153
PkgConfig::DRM
151154
PkgConfig::GBM
@@ -379,7 +382,7 @@ endif()
379382
# Sentry Plugin
380383
set(HAVE_BUNDLED_CRASHPAD_HANDLER OFF)
381384
if (BUILD_SENTRY_PLUGIN)
382-
set(SENTRY_PIC ${PIE})
385+
set(SENTRY_PIC ${CMAKE_POSITION_INDEPENDENT_CODE})
383386
add_subdirectory(third_party/sentry-native)
384387

385388
target_sources(flutterpi_module PRIVATE src/plugins/sentry/sentry.c)

0 commit comments

Comments
 (0)