diff --git a/CMakeLists.txt b/CMakeLists.txt index 169d4a196f..108833e1d4 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,7 +5,7 @@ ############################################################################### # CMake definition. -cmake_minimum_required(VERSION 3.13) +cmake_minimum_required(VERSION 3.15) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} @@ -341,8 +341,18 @@ endif() ############################################################################### # Define compilation and link flags +option(OCIO_BUILD_POSITION_INDEPENDENT_EXECUTABLES "Set to ON to build executables as PIE" OFF) + include(CompilerFlags) +if(OCIO_BUILD_POSITION_INDEPENDENT_EXECUTABLES) + if(NOT CMAKE_C_LINK_PIE_SUPPORTED) + message(FATAL_ERROR "PIE is not supported at link time.\n") + endif() + message(STATUS "Enabling PIE generation.\n") + set(CMAKE_POSITION_INDEPENDENT_CODE ON) +endif() + ############################################################################### # External linking options diff --git a/docs/quick_start/installation.rst b/docs/quick_start/installation.rst index a2e74f8175..07b023fe06 100644 --- a/docs/quick_start/installation.rst +++ b/docs/quick_start/installation.rst @@ -123,7 +123,7 @@ items manually: Required components: - C++ 11-17 compiler (gcc, clang, msvc) -- CMake >= 3.13 +- CMake >= 3.15 - \*Expat >= 2.4.1 (XML parser for CDL/CLF/CTF) - \*yaml-cpp >= 0.7.0 (YAML parser for Configs) - \*Imath >= 3.0 (for half domain LUTs) @@ -316,6 +316,10 @@ build chains.) The CMake output prints information regarding which image library will be used for the command-line tools (as well as a lot of other info about the build configuration). +Some OS distributions may require executables to be able to be executed using address space +layout randomisation (ASLR). To achieve this code generated needs to be position independent. +To support this please add ``-DOCIO_BUILD_POSITION_INDEPENDENT_EXECUTABLES=ON`` to your CMake +configuration step. Documentation +++++++++++++ diff --git a/share/cmake/utils/CompilerFlags.cmake b/share/cmake/utils/CompilerFlags.cmake index b53d6bb35a..9e78112360 100644 --- a/share/cmake/utils/CompilerFlags.cmake +++ b/share/cmake/utils/CompilerFlags.cmake @@ -48,6 +48,9 @@ endif() ############################################################################### # Compile flags +include(CheckPIESupported) +check_pie_supported() + if(USE_MSVC) set(PLATFORM_COMPILE_OPTIONS "${PLATFORM_COMPILE_OPTIONS};/DUSE_MSVC")