https://github.com/qgis/QGIS/issues/61855

chunk2 : try to fix the build with llvm22, cf https://github.com/qgis/QGIS/issues/66293

set SKIP_PRECOMPILED_HEADERS ON on qgsexpression_texts.cpp otherwise clang complains about mismatching optimization levels:
error: OptimizationLevel differs in precompiled file '/usr/obj/ports/qgis-4.0.3/build-amd64/src/core/CMakeFiles/qgis_core.dir/cmake_pch.hxx.pch' vs. current file

use -O0 on textrenderer/qgsfontmanager.cpp otherwise c++ spins forever
Index: src/core/CMakeLists.txt
--- src/core/CMakeLists.txt.orig
+++ src/core/CMakeLists.txt
@@ -11,7 +11,7 @@ BISON_TARGET(QgsMeshCalcParser mesh/qgsmeshcalcparser.
 FLEX_TARGET(QgsMeshCalcLexer mesh/qgsmeshcalclexer.ll ${CMAKE_CURRENT_BINARY_DIR}/qgsmeshcalclexer.cpp)
 ADD_FLEX_BISON_DEPENDENCY(QgsMeshCalcLexer QgsMeshCalcParser)
 
-if (WITH_PDF4QT)
+if (WITH_INTERNAL_PDF4QT)
   SET(PDF4QT_BUILD_ONLY_CORE_LIBRARY TRUE)
   SET(PDF4QT_ENABLE_OPENGL FALSE)
   SUBDIRS(${CMAKE_SOURCE_DIR}/external/PDF4QT)
@@ -2294,7 +2294,8 @@ if(MSVC)
   )
 else()
   if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" AND (CMAKE_BUILD_TYPE MATCHES Release OR CMAKE_BUILD_TYPE MATCHES RelWithDebInfo))
-    set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/qgsexpression_texts.cpp PROPERTIES COMPILE_FLAGS "-O1")
+    set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/qgsexpression_texts.cpp PROPERTIES COMPILE_FLAGS "-O1" SKIP_PRECOMPILE_HEADERS ON)
+    set_source_files_properties(textrenderer/qgsfontmanager.cpp PROPERTIES COMPILE_FLAGS "-O0" SKIP_PRECOMPILE_HEADERS ON)
     set_source_files_properties(proj/qgscoordinatereferencesystem.cpp PROPERTIES COMPILE_FLAGS "-mllvm -inline-threshold=128")
   endif()
 endif()
@@ -2675,10 +2676,15 @@ target_include_directories(qgis_core PUBLIC
   ${CMAKE_SOURCE_DIR}/external/earcut
 )
 
-if (WITH_PDF4QT)
+if (WITH_INTERNAL_PDF4QT)
   target_include_directories(qgis_core PRIVATE
     ${CMAKE_SOURCE_DIR}/external/PDF4QT/Pdf4QtLibCore/sources)
-    target_link_libraries(qgis_core Pdf4QtLibCore)
+endif()
+
+if (WITH_PDF4QT)
+  target_include_directories(qgis_core PUBLIC /usr/local/include/Pdf4QtLibCore)
+  find_library(PDF4QT_LIBRARY NAMES Pdf4QtLibCore PATHS /usr/local/lib /usr/lib)
+  target_link_libraries(qgis_core ${PDF4QT_LIBRARY})
 endif()
 
 if (WITH_EPT)
