Skip to content

Commit

Permalink
cmake: globally enable POSITION_INDEPENDENT_CODE
Browse files Browse the repository at this point in the history
Instead of setting the POSITION_INDEPENDENT_CODE flag on individual
targets, we simply enable it for everything in core/
Also, by utilizing PIE (Position Independent Executable) support in
CMake we make sure all our executables are build with PIE enabled if the
toolchain supports it.
  • Loading branch information
arogge committed Jan 23, 2023
1 parent c73b1a1 commit 5243294
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 9 deletions.
7 changes: 6 additions & 1 deletion core/CMakeLists.txt
@@ -1,6 +1,6 @@
# BAREOS® - Backup Archiving REcovery Open Sourced
#
# Copyright (C) 2017-2022 Bareos GmbH & Co. KG
# Copyright (C) 2017-2023 Bareos GmbH & Co. KG
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of version three of the GNU Affero General Public
Expand Down Expand Up @@ -46,6 +46,11 @@ endif(CCACHE_FOUND)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# enable PIC/PIE by default
include(CheckPIESupported)
check_pie_supported()
set(CMAKE_POSITION_INDEPENDENT_CODE ON)

option(ENABLE_SANITIZERS "Build with ASan/LSan/UBSan enabled" OFF)
if(ENABLE_SANITIZERS)
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
Expand Down
3 changes: 1 addition & 2 deletions core/src/droplet/libdroplet/CMakeLists.txt
@@ -1,6 +1,6 @@
# BAREOS® - Backup Archiving REcovery Open Sourced
#
# Copyright (C) 2020-2022 Bareos GmbH & Co. KG
# Copyright (C) 2020-2023 Bareos GmbH & Co. KG
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of version three of the GNU Affero General Public
Expand Down Expand Up @@ -110,7 +110,6 @@ bareos_disable_warnings(
C_ONLY
ADD_FOR_LTO
)
set_property(TARGET droplet PROPERTY POSITION_INDEPENDENT_CODE ON)

target_include_directories(
droplet PUBLIC include ${LIBXML2_INCLUDE_DIR} ${JSONC_INCLUDE_DIRS}
Expand Down
3 changes: 1 addition & 2 deletions core/src/lib/CMakeLists.txt
@@ -1,6 +1,6 @@
# BAREOS® - Backup Archiving REcovery Open Sourced
#
# Copyright (C) 2017-2022 Bareos GmbH & Co. KG
# Copyright (C) 2017-2023 Bareos GmbH & Co. KG
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of version three of the GNU Affero General Public
Expand Down Expand Up @@ -151,7 +151,6 @@ target_compile_definitions(
-DBAREOS_PROG_DATE_TIME="${BAREOS_PROG_DATE_TIME}"
-DBAREOS_YEAR="${BAREOS_YEAR}"
)
set_target_properties(version-obj PROPERTIES POSITION_INDEPENDENT_CODE ON)

target_link_libraries(
bareos
Expand Down
4 changes: 0 additions & 4 deletions core/src/stored/backends/CMakeLists.txt
Expand Up @@ -29,7 +29,6 @@ macro(add_sd_backend backend_name)
add_library(${backend_name} OBJECT)
target_link_libraries(bareossd PRIVATE ${backend_name})
endif()
set_property(TARGET ${backend_name} PROPERTY POSITION_INDEPENDENT_CODE ON)
endmacro()

if(${HAVE_GLUSTERFS})
Expand Down Expand Up @@ -70,9 +69,6 @@ endif()

if(HAVE_DYNAMIC_SD_BACKENDS)
add_library(bareossd-autochanger_test MODULE)
set_property(
TARGET bareossd-autochanger_test PROPERTY POSITION_INDEPENDENT_CODE ON
)
target_sources(
bareossd-autochanger_test PRIVATE autochanger_test_device.cc
unix_file_device.cc
Expand Down

0 comments on commit 5243294

Please sign in to comment.