From 8379cfaa0499fdc401671c16335f5c3bbdfea5fe Mon Sep 17 00:00:00 2001 From: Kevin Wheatley Date: Fri, 22 Sep 2023 16:16:01 +0100 Subject: [PATCH 1/6] Bump CMake minimum version to 3.15, allow support for PIE linker flags As per TSC discussion, we will bump minimum cmake version to 3.15, this matches OpenImageIO and ASWF template project. Strictly speaking CMake added this in 3.14, but matching the other ASWF users was seen as a sensible option. For correct support of PIE objects being linked correctly we need to trigger cmake to check for pie support see: https://cmake.org/cmake/help/latest/module/CheckPIESupported.html https://cmake.org/cmake/help/latest/policy/CMP0083.html Signed-off-by: Kevin Wheatley --- CMakeLists.txt | 2 +- share/cmake/utils/CompilerFlags.cmake | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 169d4a196f..82d2471a01 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} 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") From 5a4a6e59c6e3d576bc21e18879f883bf069591b0 Mon Sep 17 00:00:00 2001 From: Kevin Wheatley Date: Fri, 22 Sep 2023 16:35:03 +0100 Subject: [PATCH 2/6] Support CMake option for building all executables as position independent Signed-off-by: Kevin Wheatley --- CMakeLists.txt | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 82d2471a01..64d40a879e 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -341,8 +341,16 @@ 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 AND NOT CMAKE_C_LINK_PIE_SUPPORTED) + message(FATAL_ERROR "PIE is not supported at link time.\n") +else() + set(CMAKE_POSITION_INDEPENDENT_CODE ON) +endif() + ############################################################################### # External linking options From a0dc5f0f086406af9c2b582b8c9ccb54ce8cb9ba Mon Sep 17 00:00:00 2001 From: Kevin Wheatley Date: Fri, 22 Sep 2023 17:04:19 +0100 Subject: [PATCH 3/6] Add documentation note to build instructions for PIE generation Signed-off-by: Kevin Wheatley --- docs/quick_start/installation.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/quick_start/installation.rst b/docs/quick_start/installation.rst index a2e74f8175..5bda97b281 100644 --- a/docs/quick_start/installation.rst +++ b/docs/quick_start/installation.rst @@ -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 Acheive this code generated needs to be position independent. +To support thie please add ``-DOCIO_BUILD_POSITION_INDEPENDENT_EXECUTABLES=ON`` to your cmake +configuration step. Documentation +++++++++++++ From 9d67a78f54b656a08717ecd27a86567e325f4e07 Mon Sep 17 00:00:00 2001 From: Kevin Wheatley Date: Mon, 25 Sep 2023 10:46:58 +0100 Subject: [PATCH 4/6] Fix logic error when PIE code generation is not available Signed-off-by: Kevin Wheatley --- CMakeLists.txt | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 64d40a879e..108833e1d4 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -345,9 +345,11 @@ option(OCIO_BUILD_POSITION_INDEPENDENT_EXECUTABLES "Set to ON to build executabl include(CompilerFlags) -if(OCIO_BUILD_POSITION_INDEPENDENT_EXECUTABLES AND NOT CMAKE_C_LINK_PIE_SUPPORTED) - message(FATAL_ERROR "PIE is not supported at link time.\n") -else() +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() From 0f95d4c0fea425a72ad6f898553c26bab3260691 Mon Sep 17 00:00:00 2001 From: Kevin Wheatley Date: Mon, 25 Sep 2023 14:30:53 +0100 Subject: [PATCH 5/6] fix some minor typos in documentation. Signed-off-by: Kevin Wheatley --- docs/quick_start/installation.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/quick_start/installation.rst b/docs/quick_start/installation.rst index 5bda97b281..3882cd9000 100644 --- a/docs/quick_start/installation.rst +++ b/docs/quick_start/installation.rst @@ -317,8 +317,8 @@ The CMake output prints information regarding which image library will be used f 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 Acheive this code generated needs to be position independent. -To support thie please add ``-DOCIO_BUILD_POSITION_INDEPENDENT_EXECUTABLES=ON`` to your cmake +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 From f9685f7b55ce1b454260ab2bf89ab6b07cda941e Mon Sep 17 00:00:00 2001 From: Kevin Wheatley Date: Mon, 25 Sep 2023 14:35:47 +0100 Subject: [PATCH 6/6] Change documentation to refer to CMake 3.15 requirement for building Signed-off-by: Kevin Wheatley --- docs/quick_start/installation.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/quick_start/installation.rst b/docs/quick_start/installation.rst index 3882cd9000..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)