Andrew Geissler | c5535c9 | 2023-01-27 16:10:19 -0600 | [diff] [blame^] | 1 | From 51a2a1e4d8ca4040a6a7eac398cb704da35f39e5 Mon Sep 17 00:00:00 2001 |
| 2 | From: Khem Raj <raj.khem@gmail.com> |
| 3 | Date: Sat, 21 Jan 2023 03:09:08 -0800 |
| 4 | Subject: [PATCH] cmake: Do not use -isystem |
| 5 | |
| 6 | isystem dirs are searched before the regular system dirs |
| 7 | this exposes an interesting include ordering problem when using |
| 8 | clang + libc++, when including C++ headers like <cstdlib> |
| 9 | |
| 10 | cstdlib includes stdlib.h and in case of libc++, this should be coming |
| 11 | from libc++ as well, which is then eventually including system stdlib.h |
| 12 | |
| 13 | libc++ has added a check for checking this order recently, which means |
| 14 | if cstlib ends up including system stdlib.h before libc++ provided |
| 15 | stdlib.h it errors out |
| 16 | |
| 17 | /mnt/b/yoe/master/build/tmp/work/riscv64-yoe-linux/thrift/0.17.0-r0/recipe-sysroot/usr/include/c++/v1/cstdlib:90:5: error: <cstdlib> tried including <stdlib.h> but didn't find libc++'s <stdlib.h> header. This usually means that your header search paths are not configured properly. The header search paths should contain the C++ Standard Library headers before any C Standard Library, and you are probably using compiler flags that make that not be the case. |
| 18 | ^ |
| 19 | |
| 20 | The reason is that include_directories with SYSTEM property adds the |
| 21 | directory via -system and some of these directories point to sysroot |
| 22 | e.g. OPENSSL_INCLUDE_DIR which ends up adding -isystem |
| 23 | <sysroot>/usr/include and causes the system stdlib.h to included before |
| 24 | libc++ stdlib.h |
| 25 | |
| 26 | A fix is to use -idirafter which preserved the effects of system headers |
| 27 | but instead of prepending, it will append to system headers and the |
| 28 | issue is addressed |
| 29 | |
| 30 | Signed-off-by: Khem Raj <raj.khem@gmail.com> |
| 31 | --- |
| 32 | CMakeLists.txt | 4 ++-- |
| 33 | glib/CMakeLists.txt | 4 ++-- |
| 34 | qt5/src/CMakeLists.txt | 4 ++-- |
| 35 | qt6/src/CMakeLists.txt | 4 ++-- |
| 36 | test/CMakeLists.txt | 6 +++--- |
| 37 | utils/CMakeLists.txt | 10 +++++----- |
| 38 | 6 files changed, 16 insertions(+), 16 deletions(-) |
| 39 | |
| 40 | diff --git a/CMakeLists.txt b/CMakeLists.txt |
| 41 | index 4768ac8..cdc014d 100644 |
| 42 | --- a/CMakeLists.txt |
| 43 | +++ b/CMakeLists.txt |
| 44 | @@ -603,10 +603,10 @@ add_library(poppler ${poppler_SRCS}) |
| 45 | if (OpenJPEG_FOUND) |
| 46 | # check if we can remove this when we depend on newer openjpeg versions, 2.5 seems fixed |
| 47 | # target openjp2 may lack interface include directories |
| 48 | - target_include_directories(poppler SYSTEM PRIVATE ${OPENJPEG_INCLUDE_DIRS}) |
| 49 | + target_include_directories(poppler PRIVATE ${OPENJPEG_INCLUDE_DIRS}) |
| 50 | endif() |
| 51 | if(USE_CMS) |
| 52 | - target_include_directories(poppler SYSTEM PRIVATE ${LCMS2_INCLUDE_DIR}) |
| 53 | + target_include_directories(poppler PRIVATE ${LCMS2_INCLUDE_DIR}) |
| 54 | endif() |
| 55 | generate_export_header(poppler BASE_NAME poppler-private EXPORT_FILE_NAME "${CMAKE_CURRENT_BINARY_DIR}/poppler_private_export.h") |
| 56 | set_target_properties(poppler PROPERTIES VERSION 126.0.0 SOVERSION 126) |
| 57 | diff --git a/glib/CMakeLists.txt b/glib/CMakeLists.txt |
| 58 | index 52e8687..08ab39a 100644 |
| 59 | --- a/glib/CMakeLists.txt |
| 60 | +++ b/glib/CMakeLists.txt |
| 61 | @@ -4,7 +4,7 @@ include_directories( |
| 62 | ) |
| 63 | |
| 64 | include_directories( |
| 65 | - SYSTEM |
| 66 | + |
| 67 | ${GLIB2_INCLUDE_DIRS} |
| 68 | ${CAIRO_INCLUDE_DIRS} |
| 69 | ) |
| 70 | @@ -96,7 +96,7 @@ if(MINGW AND BUILD_SHARED_LIBS) |
| 71 | set_target_properties(poppler-glib PROPERTIES SUFFIX "-${POPPLER_GLIB_SOVERSION}${CMAKE_SHARED_LIBRARY_SUFFIX}") |
| 72 | endif() |
| 73 | target_link_libraries(poppler-glib poppler PkgConfig::GLIB2 ${CAIRO_LIBRARIES} Freetype::Freetype) |
| 74 | -target_include_directories(poppler-glib SYSTEM PRIVATE ${CAIRO_INCLUDE_DIRS}) |
| 75 | +target_include_directories(poppler-glib PRIVATE ${CAIRO_INCLUDE_DIRS}) |
| 76 | install(TARGETS poppler-glib RUNTIME DESTINATION bin LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) |
| 77 | |
| 78 | install(FILES |
| 79 | diff --git a/qt5/src/CMakeLists.txt b/qt5/src/CMakeLists.txt |
| 80 | index 5db3a6c..f242d29 100644 |
| 81 | --- a/qt5/src/CMakeLists.txt |
| 82 | +++ b/qt5/src/CMakeLists.txt |
| 83 | @@ -45,11 +45,11 @@ if(MINGW AND BUILD_SHARED_LIBS) |
| 84 | endif() |
| 85 | target_link_libraries(poppler-qt5 poppler Qt5::Core Qt5::Gui Qt5::Xml Freetype::Freetype) |
| 86 | if (ENABLE_NSS3) |
| 87 | - target_include_directories(poppler-qt5 SYSTEM PRIVATE ${NSS3_INCLUDE_DIRS}) |
| 88 | + target_include_directories(poppler-qt5 PRIVATE ${NSS3_INCLUDE_DIRS}) |
| 89 | endif() |
| 90 | if(USE_CMS) |
| 91 | target_link_libraries(poppler-qt5 poppler ${LCMS2_LIBRARIES}) |
| 92 | - target_include_directories(poppler-qt5 SYSTEM PRIVATE ${LCMS2_INCLUDE_DIR}) |
| 93 | + target_include_directories(poppler-qt5 PRIVATE ${LCMS2_INCLUDE_DIR}) |
| 94 | endif() |
| 95 | install(TARGETS poppler-qt5 RUNTIME DESTINATION bin LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) |
| 96 | |
| 97 | diff --git a/qt6/src/CMakeLists.txt b/qt6/src/CMakeLists.txt |
| 98 | index cd91975..6c42e12 100644 |
| 99 | --- a/qt6/src/CMakeLists.txt |
| 100 | +++ b/qt6/src/CMakeLists.txt |
| 101 | @@ -45,11 +45,11 @@ if(MINGW AND BUILD_SHARED_LIBS) |
| 102 | endif() |
| 103 | target_link_libraries(poppler-qt6 poppler Qt6::Core Qt6::Gui Freetype::Freetype) |
| 104 | if (ENABLE_NSS3) |
| 105 | - target_include_directories(poppler-qt6 SYSTEM PRIVATE ${NSS3_INCLUDE_DIRS}) |
| 106 | + target_include_directories(poppler-qt6 PRIVATE ${NSS3_INCLUDE_DIRS}) |
| 107 | endif() |
| 108 | if(USE_CMS) |
| 109 | target_link_libraries(poppler-qt6 poppler ${LCMS2_LIBRARIES}) |
| 110 | - target_include_directories(poppler-qt6 SYSTEM PRIVATE ${LCMS2_INCLUDE_DIR}) |
| 111 | + target_include_directories(poppler-qt6 PRIVATE ${LCMS2_INCLUDE_DIR}) |
| 112 | endif() |
| 113 | install(TARGETS poppler-qt6 RUNTIME DESTINATION bin LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) |
| 114 | |
| 115 | diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt |
| 116 | index afa1352..9bd3b9a 100644 |
| 117 | --- a/test/CMakeLists.txt |
| 118 | +++ b/test/CMakeLists.txt |
| 119 | @@ -23,7 +23,7 @@ if (GTK_FOUND) |
| 120 | ) |
| 121 | poppler_add_test(gtk-test BUILD_GTK_TESTS ${gtk_splash_test_SRCS}) |
| 122 | target_link_libraries(gtk-test ${CAIRO_LIBRARIES} poppler-glib PkgConfig::GTK3) |
| 123 | - target_include_directories(gtk-test SYSTEM PRIVATE ${CAIRO_INCLUDE_DIRS}) |
| 124 | + target_include_directories(gtk-test PRIVATE ${CAIRO_INCLUDE_DIRS}) |
| 125 | |
| 126 | if (HAVE_CAIRO) |
| 127 | |
| 128 | @@ -35,7 +35,7 @@ if (GTK_FOUND) |
| 129 | ) |
| 130 | poppler_add_test(pdf-inspector BUILD_GTK_TESTS ${pdf_inspector_SRCS}) |
| 131 | target_link_libraries(pdf-inspector ${CAIRO_LIBRARIES} Freetype::Freetype ${common_libs} PkgConfig::GTK3 poppler) |
| 132 | - target_include_directories(pdf-inspector SYSTEM PRIVATE ${CAIRO_INCLUDE_DIRS}) |
| 133 | + target_include_directories(pdf-inspector PRIVATE ${CAIRO_INCLUDE_DIRS}) |
| 134 | target_compile_definitions(pdf-inspector PRIVATE -DSRC_DIR="${CMAKE_CURRENT_SOURCE_DIR}") |
| 135 | endif () |
| 136 | |
| 137 | @@ -59,7 +59,7 @@ if (HAVE_CAIRO) |
| 138 | ) |
| 139 | add_executable(cairo-thread-test ${cairo_thread_test_SRCS}) |
| 140 | target_link_libraries(cairo-thread-test ${CAIRO_LIBRARIES} Freetype::Freetype Threads::Threads poppler) |
| 141 | - target_include_directories(cairo-thread-test SYSTEM PRIVATE ${CAIRO_INCLUDE_DIRS}) |
| 142 | + target_include_directories(cairo-thread-test PRIVATE ${CAIRO_INCLUDE_DIRS}) |
| 143 | endif () |
| 144 | endif () |
| 145 | |
| 146 | diff --git a/utils/CMakeLists.txt b/utils/CMakeLists.txt |
| 147 | index 1c3ebcb..bc1840a 100644 |
| 148 | --- a/utils/CMakeLists.txt |
| 149 | +++ b/utils/CMakeLists.txt |
| 150 | @@ -16,7 +16,7 @@ add_executable(pdftoppm ${pdftoppm_SOURCES}) |
| 151 | target_link_libraries(pdftoppm ${common_libs}) |
| 152 | if(LCMS2_FOUND) |
| 153 | target_link_libraries(pdftoppm ${LCMS2_LIBRARIES}) |
| 154 | - target_include_directories(pdftoppm SYSTEM PRIVATE ${LCMS2_INCLUDE_DIR}) |
| 155 | + target_include_directories(pdftoppm PRIVATE ${LCMS2_INCLUDE_DIR}) |
| 156 | endif() |
| 157 | install(TARGETS pdftoppm DESTINATION bin) |
| 158 | install(FILES pdftoppm.1 DESTINATION ${CMAKE_INSTALL_MANDIR}/man1) |
| 159 | @@ -37,10 +37,10 @@ if (HAVE_CAIRO) |
| 160 | add_definitions(${CAIRO_CFLAGS}) |
| 161 | add_executable(pdftocairo ${pdftocairo_SOURCES}) |
| 162 | target_link_libraries(pdftocairo ${CAIRO_LIBRARIES} Freetype::Freetype ${common_libs}) |
| 163 | - target_include_directories(pdftocairo SYSTEM PRIVATE ${CAIRO_INCLUDE_DIRS}) |
| 164 | + target_include_directories(pdftocairo PRIVATE ${CAIRO_INCLUDE_DIRS}) |
| 165 | if(LCMS2_FOUND) |
| 166 | target_link_libraries(pdftocairo ${LCMS2_LIBRARIES}) |
| 167 | - target_include_directories(pdftocairo SYSTEM PRIVATE ${LCMS2_INCLUDE_DIR}) |
| 168 | + target_include_directories(pdftocairo PRIVATE ${LCMS2_INCLUDE_DIR}) |
| 169 | endif() |
| 170 | install(TARGETS pdftocairo DESTINATION bin) |
| 171 | install(FILES pdftocairo.1 DESTINATION ${CMAKE_INSTALL_MANDIR}/man1) |
| 172 | @@ -99,7 +99,7 @@ if (ENABLE_NSS3) |
| 173 | pdfsig.cc |
| 174 | ) |
| 175 | add_executable(pdfsig ${pdfsig_SOURCES}) |
| 176 | - target_include_directories(pdfsig SYSTEM PRIVATE ${NSS3_INCLUDE_DIRS}) |
| 177 | + target_include_directories(pdfsig PRIVATE ${NSS3_INCLUDE_DIRS}) |
| 178 | target_link_libraries(pdfsig ${common_libs}) |
| 179 | install(TARGETS pdfsig DESTINATION bin) |
| 180 | install(FILES pdfsig.1 DESTINATION ${CMAKE_INSTALL_MANDIR}/man1) |
| 181 | @@ -114,7 +114,7 @@ add_executable(pdftops ${pdftops_SOURCES}) |
| 182 | target_link_libraries(pdftops ${common_libs}) |
| 183 | if(LCMS2_FOUND) |
| 184 | target_link_libraries(pdftops ${LCMS2_LIBRARIES}) |
| 185 | - target_include_directories(pdftops SYSTEM PRIVATE ${LCMS2_INCLUDE_DIR}) |
| 186 | + target_include_directories(pdftops PRIVATE ${LCMS2_INCLUDE_DIR}) |
| 187 | endif() |
| 188 | install(TARGETS pdftops DESTINATION bin) |
| 189 | install(FILES pdftops.1 DESTINATION ${CMAKE_INSTALL_MANDIR}/man1) |
| 190 | -- |
| 191 | 2.39.1 |
| 192 | |