[poppler] 3 commits - CMakeLists.txt cmake/modules
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Mon Aug 30 12:20:03 UTC 2021
CMakeLists.txt | 15 +++++-
cmake/modules/PopplerMacros.cmake | 87 ++++++++++++++++++++++----------------
2 files changed, 65 insertions(+), 37 deletions(-)
New commits:
commit f8bcfde24f52e66dd98b8ae62057742bd3add35e
Author: Alex Richardson <Alexander.Richardson at cl.cam.ac.uk>
Date: Tue Jul 13 15:16:31 2021 +0100
cmake: correctly forward user-provided flags to try_compile()
Poppler overrides the user-provided CMAKE_{C,CXX}_FLAGS and appends them
to the per-configuration variables instead. This behaviour currently
causes cross-compilation checks to fail since a CMake issue means these
these per-configuration flags are no passed to try_compile() commands.
In my case the flags specified in the toolchain file (as part of
CMAKE_{C,CXX}_FLAGS_INIT) are absolutely required to compile successfully
since a missing `-mabi=/-march=` flag will result in a linker error due to
trying to link incompatible libraries. If CMAKE_TRY_COMPILE_CONFIGURATION
is empty CMake will no propagate the per-configuration flags to
try_compile() so we have to to set the value explicitly.
This is an upstream CMake issue:
See https://gitlab.kitware.com/cmake/cmake/-/issues/22414 and
https://gitlab.kitware.com/cmake/cmake/-/issues/19512.
diff --git a/CMakeLists.txt b/CMakeLists.txt
index edf63819..f1785286 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -2,11 +2,21 @@ cmake_minimum_required(VERSION 3.10.0 FATAL_ERROR)
project(poppler)
-
set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/modules)
include(PopplerDefaults)
include(PopplerMacros)
+# Ensure that the user-provided C_FLAGS are used for try_compile() calls.
+# This is needed since PopplerMacros.cmake clears CMAKE_C_FLAGS and if
+# CMAKE_TRY_COMPILE_CONFIGURATION is empty CMake only uses the flags
+# specified in CMAKE_C_FLAGS (https://gitlab.kitware.com/cmake/cmake/-/issues/22414
+# and https://gitlab.kitware.com/cmake/cmake/-/issues/19512).
+# We therefore have to explicitly set CMAKE_TRY_COMPILE_CONFIGURATION until we
+# depend on a CMake release that includes a fix for those issues.
+# This is set after including PopplerMacros since that sets the default
+# CMAKE_BUILD_TYPE and also sets _CMAKE_BUILD_TYPE_UPPER.
+set(CMAKE_TRY_COMPILE_CONFIGURATION "${_CMAKE_BUILD_TYPE_UPPER}")
+
include(MacroOptionalFindPackage)
find_package(PkgConfig)
if (WIN32)
commit 53ecbfc9af7a490ad49353b1e2b5011a66c0f100
Author: Alex Richardson <Alexander.Richardson at cl.cam.ac.uk>
Date: Tue Jul 13 15:04:36 2021 +0100
Always append to CMAKE_{C,CXX}_FLAGS_${CMAKE_BUILD_TYPE}
Currently the user/toolchain-provided CMAKE_{C,CXX}_FLAGS can be lost
if the user selects a CMAKE_BUILD_TYPE that is not handled by
PopplerMacros.cmake. To avoid this problem use a foreach() loop over
all known build types plus the current CMAKE_BUILD_TYPE that appends
to the per-configuration flags.
diff --git a/cmake/modules/PopplerMacros.cmake b/cmake/modules/PopplerMacros.cmake
index fe1182da..2aed0284 100644
--- a/cmake/modules/PopplerMacros.cmake
+++ b/cmake/modules/PopplerMacros.cmake
@@ -79,6 +79,20 @@ if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
set(CMAKE_BUILD_TYPE RelWithDebInfo)
endif(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
+string(TOUPPER "${CMAKE_BUILD_TYPE}" _CMAKE_BUILD_TYPE_UPPER)
+set(_known_build_types RELWITHDEBINFO;RELEASE;DEBUG;DEBUGFULL;PROFILE)
+# We override CMAKE_CXX_FLAGS_${_CMAKE_BUILD_TYPE_UPPER} below. If the user
+# selects a CMAKE_BUILD_TYPE that is not handled by the logic below, we will
+# end up dropping the previous flags (e.g. those set in a cross-compilation
+# CMake toolchain file). To avoid surprising compilation errors, we emit an
+# error in that case, so that the user can handle the passed CMAKE_BUILD_TYPE
+# in the compiler flags logic below.
+if (NOT "${_CMAKE_BUILD_TYPE_UPPER}" IN_LIST _known_build_types)
+ message(FATAL_ERROR "Unsupported CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}")
+endif()
+set(_save_cflags "${CMAKE_C_FLAGS}")
+set(_save_cxxflags "${CMAKE_CXX_FLAGS}")
+
if(CMAKE_COMPILER_IS_GNUCXX)
# set the default compile warnings
set(_warn "-Wall -Wextra -Wpedantic")
@@ -103,20 +117,18 @@ if(CMAKE_COMPILER_IS_GNUCXX)
set(DEFAULT_COMPILE_WARNINGS "${_warn}")
set(DEFAULT_COMPILE_WARNINGS_EXTRA "${_warn} ${_warnx}")
- set(_save_cxxflags "${CMAKE_CXX_FLAGS}")
set(CMAKE_CXX_FLAGS "-fno-exceptions -fno-check-new -fno-common -fno-operator-names -D_DEFAULT_SOURCE")
- set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g ${_save_cxxflags}")
- set(CMAKE_CXX_FLAGS_RELEASE "-O2 -DNDEBUG ${_save_cxxflags}")
- set(CMAKE_CXX_FLAGS_DEBUG "-g -O2 -fno-reorder-blocks -fno-schedule-insns -fno-inline ${_save_cxxflags}")
- set(CMAKE_CXX_FLAGS_DEBUGFULL "-g3 -fno-inline ${_save_cxxflags}")
- set(CMAKE_CXX_FLAGS_PROFILE "-g3 -fno-inline -ftest-coverage -fprofile-arcs ${_save_cxxflags}")
- set(_save_cflags "${CMAKE_C_FLAGS}")
+ set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g")
+ set(CMAKE_CXX_FLAGS_RELEASE "-O2 -DNDEBUG")
+ set(CMAKE_CXX_FLAGS_DEBUG "-g -O2 -fno-reorder-blocks -fno-schedule-insns -fno-inline")
+ set(CMAKE_CXX_FLAGS_DEBUGFULL "-g3 -fno-inline")
+ set(CMAKE_CXX_FLAGS_PROFILE "-g3 -fno-inline -ftest-coverage -fprofile-arcs")
set(CMAKE_C_FLAGS "-std=c99 -D_DEFAULT_SOURCE")
- set(CMAKE_C_FLAGS_RELWITHDEBINFO "-O2 -g ${_save_cflags}")
- set(CMAKE_C_FLAGS_RELEASE "-O2 -DNDEBUG ${_save_cflags}")
- set(CMAKE_C_FLAGS_DEBUG "-g -O2 -fno-reorder-blocks -fno-schedule-insns -fno-inline ${_save_cflags}")
- set(CMAKE_C_FLAGS_DEBUGFULL "-g3 -fno-inline ${_save_cflags}")
- set(CMAKE_C_FLAGS_PROFILE "-g3 -fno-inline -ftest-coverage -fprofile-arcs ${_save_cflags}")
+ set(CMAKE_C_FLAGS_RELWITHDEBINFO "-O2 -g")
+ set(CMAKE_C_FLAGS_RELEASE "-O2 -DNDEBUG")
+ set(CMAKE_C_FLAGS_DEBUG "-g -O2 -fno-reorder-blocks -fno-schedule-insns -fno-inline")
+ set(CMAKE_C_FLAGS_DEBUGFULL "-g3 -fno-inline")
+ set(CMAKE_C_FLAGS_PROFILE "-g3 -fno-inline -ftest-coverage -fprofile-arcs")
poppler_check_link_flag("-Wl,--as-needed" GCC_HAS_AS_NEEDED)
if(GCC_HAS_AS_NEEDED)
@@ -124,6 +136,7 @@ if(CMAKE_COMPILER_IS_GNUCXX)
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -Wl,--as-needed")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--as-needed")
endif(GCC_HAS_AS_NEEDED)
+ set(_compiler_flags_changed 1)
endif (CMAKE_COMPILER_IS_GNUCXX)
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
@@ -148,35 +161,39 @@ if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
set(DEFAULT_COMPILE_WARNINGS "${_warn}")
set(DEFAULT_COMPILE_WARNINGS_EXTRA "${_warn} ${_warnx}")
- set(_save_cxxflags "${CMAKE_CXX_FLAGS}")
set(CMAKE_CXX_FLAGS "-fno-exceptions -fno-check-new -fno-common -D_DEFAULT_SOURCE")
- set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g ${_save_cxxflags}")
- set(CMAKE_CXX_FLAGS_RELEASE "-O2 -DNDEBUG ${_save_cxxflags}")
+ set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g")
+ set(CMAKE_CXX_FLAGS_RELEASE "-O2 -DNDEBUG")
# clang does not support -fno-reorder-blocks -fno-schedule-insns, so do not use -O2
- set(CMAKE_CXX_FLAGS_DEBUG "-g ${_save_cxxflags}")
- set(CMAKE_CXX_FLAGS_DEBUGFULL "-g3 -fno-inline ${_save_cxxflags}")
- set(CMAKE_CXX_FLAGS_PROFILE "-g3 -fno-inline -ftest-coverage -fprofile-arcs ${_save_cxxflags}")
- set(_save_cflags "${CMAKE_C_FLAGS}")
+ set(CMAKE_CXX_FLAGS_DEBUG "-g")
+ set(CMAKE_CXX_FLAGS_DEBUGFULL "-g3 -fno-inline")
+ set(CMAKE_CXX_FLAGS_PROFILE "-g3 -fno-inline -ftest-coverage -fprofile-arcs")
set(CMAKE_C_FLAGS "-std=c99 -D_DEFAULT_SOURCE")
- set(CMAKE_C_FLAGS_RELWITHDEBINFO "-O2 -g ${_save_cflags}")
- set(CMAKE_C_FLAGS_RELEASE "-O2 -DNDEBUG ${_save_cflags}")
+ set(CMAKE_C_FLAGS_RELWITHDEBINFO "-O2 -g")
+ set(CMAKE_C_FLAGS_RELEASE "-O2 -DNDEBUG")
# clang does not support -fno-reorder-blocks -fno-schedule-insns, so do not use -O2
- set(CMAKE_C_FLAGS_DEBUG "-g ${_save_cflags}")
- set(CMAKE_C_FLAGS_DEBUGFULL "-g3 -fno-inline ${_save_cflags}")
- set(CMAKE_C_FLAGS_PROFILE "-g3 -fno-inline -ftest-coverage -fprofile-arcs ${_save_cflags}")
-
+ set(CMAKE_C_FLAGS_DEBUG "-g")
+ set(CMAKE_C_FLAGS_DEBUGFULL "-g3 -fno-inline")
+ set(CMAKE_C_FLAGS_PROFILE "-g3 -fno-inline -ftest-coverage -fprofile-arcs")
+ set(_compiler_flags_changed 1)
endif()
if(CMAKE_C_COMPILER MATCHES "icc")
- set(_save_cxxflags "${CMAKE_CXX_FLAGS}")
- set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g ${_save_cxxflags}")
- set(CMAKE_CXX_FLAGS_RELEASE "-O2 -DNDEBUG ${_save_cxxflags}")
- set(CMAKE_CXX_FLAGS_DEBUG "-O2 -g -0b0 -noalign ${_save_cxxflags}")
- set(CMAKE_CXX_FLAGS_DEBUGFULL "-g -Ob0 -noalign ${_save_cxxflags}")
- set(_save_cflags "${CMAKE_C_FLAGS}")
- set(CMAKE_C_FLAGS_RELWITHDEBINFO "-O2 -g ${_save_cflags}")
- set(CMAKE_C_FLAGS_RELEASE "-O2 -DNDEBUG ${_save_cflags}")
- set(CMAKE_C_FLAGS_DEBUG "-O2 -g -Ob0 -noalign ${_save_cflags}")
- set(CMAKE_C_FLAGS_DEBUGFULL "-g -Ob0 -noalign ${_save_cflags}")
+ set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g")
+ set(CMAKE_CXX_FLAGS_RELEASE "-O2 -DNDEBUG")
+ set(CMAKE_CXX_FLAGS_DEBUG "-O2 -g -0b0 -noalign")
+ set(CMAKE_CXX_FLAGS_DEBUGFULL "-g -Ob0 -noalign")
+ set(CMAKE_C_FLAGS_RELWITHDEBINFO "-O2 -g")
+ set(CMAKE_C_FLAGS_RELEASE "-O2 -DNDEBUG")
+ set(CMAKE_C_FLAGS_DEBUG "-O2 -g -Ob0 -noalign")
+ set(CMAKE_C_FLAGS_DEBUGFULL "-g -Ob0 -noalign")
+ set(_compiler_flags_changed 1)
endif(CMAKE_C_COMPILER MATCHES "icc")
+if(_compiler_flags_changed)
+ # Ensure that the previous CMAKE_{C,CXX}_FLAGS are included in the current configuration flags.
+ foreach(_build_type ${_known_build_types})
+ set(CMAKE_CXX_FLAGS_${_build_type} "${CMAKE_CXX_FLAGS_${_build_type}} ${_save_cxxflags}")
+ set(CMAKE_C_FLAGS_${_build_type} "${CMAKE_C_FLAGS_${_build_type}} ${_save_cflags}")
+ endforeach()
+endif()
commit a1678b91e2d1b1b38ff38897bc1540f2b57a7ebc
Author: Alex Richardson <Alexander.Richardson at cl.cam.ac.uk>
Date: Mon Jul 12 17:44:07 2021 +0100
Call cmake_minium_required() before project()
See CMake documentation:
```
Call the cmake_minimum_required() command at the beginning of the top-level
CMakeLists.txt file even before calling the project() command. It is
important to establish version and policy settings before invoking other
commands whose behavior they may affect. See also policy CMP0000.
```
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 305256a2..edf63819 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,6 +1,7 @@
+cmake_minimum_required(VERSION 3.10.0 FATAL_ERROR)
+
project(poppler)
-cmake_minimum_required(VERSION 3.10.0 FATAL_ERROR)
set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/modules)
More information about the poppler
mailing list