Skip to content

Commit

Permalink
CMake: enable gdal_priv.h precompiled header if CMake USE_PRECOMPILED…
Browse files Browse the repository at this point in the history
…_HEADERS=ON

Can speed up cold builds by 30%

It is a bit experimental for now, so it isn't enabled by default, because:
- it currently causes linking issues with MSVC
- CLang Static Analyzer analysis has false positives with it
- Strange issue seen in the android CI configuration with a
  fatal error: file '/home/runner/work/gdal/gdal/build_android_cmake/CMakeFiles/gdal_priv_header.dir/cmake_pch.h' has been modified since the precompiled header '/home/runner/work/gdal/gdal/build_android_cmake/CMakeFiles/gdal_priv_header.dir/cmake_pch.h.pch' was built: mtime changed (https://github.com/rouault/gdal/actions/runs/12113235664/job/33767887119)
  • Loading branch information
rouault committed Dec 2, 2024
1 parent 297d465 commit 9b04b5a
Show file tree
Hide file tree
Showing 22 changed files with 152 additions and 23 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/benchmarks/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@

set -eu

# for precompiled headers
ccache --set-config sloppiness=pch_defines,time_macros,include_file_mtime,include_file_ctime

CMAKE_ARGS=(
"-DUSE_CCACHE=ON" \
"-DUSE_PRECOMPILED_HEADERS=ON" \
"-DCMAKE_BUILD_TYPE=Release" \
"-DCMAKE_INSTALL_PREFIX=/usr" \
"-DGDAL_USE_TIFF_INTERNAL=ON" \
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/cmake_builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,7 @@ jobs:
mkdir -p $GITHUB_WORKSPACE/build
export PKG_CONFIG_PATH=/opt/homebrew/Cellar/libxml2/lib/pkgconfig
# FIXME: remove -DBUILD_PYTHON_BINDINGS=OFF. Python tests fail with "ModuleNotFoundError: No module named '_gdal'" with macos-12
cmake -Werror=dev -DCMAKE_INSTALL_PREFIX=$GITHUB_WORKSPACE/install-gdal ${CMAKE_OPTIONS} -DCMAKE_C_FLAGS=-Werror -DCMAKE_CXX_FLAGS=-Werror -DUSE_CCACHE=ON -DCMAKE_UNITY_BUILD=${CMAKE_UNITY_BUILD} -S "$GITHUB_WORKSPACE" -B "$GITHUB_WORKSPACE/build" -DWERROR_DEV_FLAG="-Werror=dev" -DBUILD_PYTHON_BINDINGS=OFF
cmake -Werror=dev -DCMAKE_INSTALL_PREFIX=$GITHUB_WORKSPACE/install-gdal ${CMAKE_OPTIONS} -DCMAKE_C_FLAGS=-Werror -DCMAKE_CXX_FLAGS=-Werror -DUSE_CCACHE=ON -DCMAKE_UNITY_BUILD=${CMAKE_UNITY_BUILD} -S "$GITHUB_WORKSPACE" -B "$GITHUB_WORKSPACE/build" -DWERROR_DEV_FLAG="-Werror=dev" -DBUILD_PYTHON_BINDINGS=OFF "-DUSE_PRECOMPILED_HEADERS=ON"
#$(cat $GITHUB_WORKSPACE/build/python_executable.txt) -m pip install --user -r $GITHUB_WORKSPACE/autotest/requirements.txt
- name: Build
run: |
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/fedora_rawhide/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ cmake ${GDAL_SOURCE_DIR:=..} \
-DCMAKE_CXX_FLAGS="-std=c++20 -Werror -O1 -D_FORTIFY_SOURCE=2" \
-DCMAKE_SHARED_LINKER_FLAGS="-lstdc++" \
-DUSE_CCACHE=ON \
"-DUSE_PRECOMPILED_HEADERS=ON" \
-DEMBED_RESOURCE_FILES=ON \
-DCMAKE_INSTALL_PREFIX=/usr \
-DWERROR_DEV_FLAG="-Werror=dev"
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/icc/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@

set -eu

# for precompiled headers
ccache --set-config sloppiness=pch_defines,time_macros,include_file_mtime,include_file_ctime

cmake ${GDAL_SOURCE_DIR:=..} \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_C_COMPILER=icx \
-DCMAKE_CXX_COMPILER=icx \
"-DUSE_PRECOMPILED_HEADERS=ON" \
-DUSE_CCACHE=ON
make -j$(nproc)

4 changes: 4 additions & 0 deletions .github/workflows/ubuntu_20.04/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@ set -eu
export CXXFLAGS="-march=native -O2 -Wodr -flto-odr-type-merging -Werror"
export CFLAGS="-O2 -march=native -Werror"

# for precompiled headers
ccache --set-config sloppiness=pch_defines,time_macros,include_file_mtime,include_file_ctime

cmake "${GDAL_SOURCE_DIR:=..}" \
-DUSE_CCACHE=ON \
"-DUSE_PRECOMPILED_HEADERS=ON" \
-DCMAKE_INTERPROCEDURAL_OPTIMIZATION=ON \
-DCMAKE_INSTALL_PREFIX=/tmp/install-gdal \
-DGDAL_USE_TIFF_INTERNAL=OFF \
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/ubuntu_22.04/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@ set -e
LD_LIBRARY_PATH="/opt/instantclient_19_9:/opt/instantclient_19_9/lib:${LD_LIBRARY_PATH}"
export LD_LIBRARY_PATH

# for precompiled headers
ccache --set-config sloppiness=pch_defines,time_macros,include_file_mtime,include_file_ctime

cmake ${GDAL_SOURCE_DIR:=..} \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_C_FLAGS="-Werror" \
-DCMAKE_CXX_FLAGS="-Werror" \
-DUSE_CCACHE=ON \
"-DUSE_PRECOMPILED_HEADERS=ON" \
-DOracle_ROOT=/opt/instantclient_19_9 \
-DGDAL_USE_GEOTIFF_INTERNAL:BOOL=ON \
-DGDAL_USE_TIFF_INTERNAL:BOOL=ON
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/ubuntu_24.04/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ cmake ${GDAL_SOURCE_DIR:=..} \
-DCMAKE_C_FLAGS="-Werror" \
-DCMAKE_CXX_FLAGS="-Werror -DGDAL_BANDMAP_TYPE_CONST_SAFE" \
-DUSE_CCACHE=ON \
"-DUSE_PRECOMPILED_HEADERS=ON" \
-DOracle_ROOT=/opt/instantclient_19_9 \
-DGDAL_USE_GEOTIFF_INTERNAL:BOOL=ON \
-DGDAL_USE_TIFF_INTERNAL:BOOL=ON
Expand Down
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ define_property(
include(GdalCAndCXXStandards)
include(CheckCompilerMachineOption)
include(CheckCompilerSIMDFeature)

option(USE_PRECOMPILED_HEADERS "Use precompiled headers (does not work with MSVC)" OFF)
if (USE_PRECOMPILED_HEADERS AND MSVC)
message(FATAL_ERROR "USE_PRECOMPILED_HEADERS=ON does not currently work with Visual Studio C++ compiler")
endif()

include(Ccache)

#
Expand Down
21 changes: 17 additions & 4 deletions alg/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ target_compile_options(alg PRIVATE $<$<COMPILE_LANGUAGE:CXX>:${GDAL_CXX_WARNING_
${WFLAG_EFFCXX}>)
target_compile_options(alg PRIVATE $<$<COMPILE_LANGUAGE:C>:${GDAL_C_WARNING_FLAGS}>)

target_compile_definitions(alg PUBLIC $<$<CONFIG:DEBUG>:GDAL_DEBUG>)
if (USE_PRECOMPILED_HEADERS)
target_precompile_headers(alg REUSE_FROM gdal_priv_header)
endif()

target_include_directories(
alg PRIVATE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/marching_squares>
$<TARGET_PROPERTY:gdal_vrt,SOURCE_DIR> $<TARGET_PROPERTY:gdal_MEM,SOURCE_DIR>)
Expand Down Expand Up @@ -101,8 +106,12 @@ if (GDAL_ENABLE_ARM_NEON_OPTIMIZATIONS)
endif()

if (HAVE_SSE_AT_COMPILE_TIME)
target_sources(alg PRIVATE gdalgridsse.cpp)
target_compile_definitions(alg PRIVATE -DHAVE_SSE_AT_COMPILE_TIME)
add_library(alg_gdalgridsse OBJECT gdalgridsse.cpp)
add_dependencies(alg_gdalgridsse generate_gdal_version_h)
target_compile_definitions(alg_gdalgridsse PRIVATE -DHAVE_SSE_AT_COMPILE_TIME)
gdal_standard_includes(alg_gdalgridsse)
set_property(TARGET alg_gdalgridsse PROPERTY POSITION_INDEPENDENT_CODE ${GDAL_OBJECT_LIBRARIES_POSITION_INDEPENDENT_CODE})
target_sources(${GDAL_LIB_TARGET_NAME} PRIVATE $<TARGET_OBJECTS:alg_gdalgridsse>)
if (NOT "${GDAL_SSE_FLAG}" STREQUAL "")
set_property(
SOURCE gdalgridsse.cpp
Expand All @@ -111,8 +120,12 @@ if (HAVE_SSE_AT_COMPILE_TIME)
endif ()
endif ()
if (HAVE_AVX_AT_COMPILE_TIME)
target_sources(alg PRIVATE gdalgridavx.cpp)
target_compile_definitions(alg PRIVATE -DHAVE_AVX_AT_COMPILE_TIME)
add_library(alg_gdalgridavx OBJECT gdalgridavx.cpp)
add_dependencies(alg_gdalgridavx generate_gdal_version_h)
target_compile_definitions(alg_gdalgridavx PRIVATE -DHAVE_AVX_AT_COMPILE_TIME)
gdal_standard_includes(alg_gdalgridavx)
set_property(TARGET alg_gdalgridavx PROPERTY POSITION_INDEPENDENT_CODE ${GDAL_OBJECT_LIBRARIES_POSITION_INDEPENDENT_CODE})
target_sources(${GDAL_LIB_TARGET_NAME} PRIVATE $<TARGET_OBJECTS:alg_gdalgridavx>)
if (NOT "${GDAL_AVX_FLAG}" STREQUAL "")
set_property(
SOURCE gdalgridavx.cpp
Expand Down
1 change: 1 addition & 0 deletions ci/travis/osx/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ CFLAGS="-Wextra -Werror" CXXFLAGS="-Wextra -Werror" cmake .. \
-DGDAL_USE_POSTGRESQL=OFF \
-DGDAL_USE_WEBP=OFF \
-DBUILD_CSHARP_BINDINGS=OFF \
"-DUSE_PRECOMPILED_HEADERS=ON" \
-DCMAKE_UNITY_BUILD=ON

echo "Check that GDAL_ENABLE_ARM_NEON_OPTIMIZATIONS:BOOL=ON"
Expand Down
9 changes: 8 additions & 1 deletion cmake/helpers/GdalDriverHelper.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ function(_set_driver_core_sources _KEY _DRIVER_TARGET)
endfunction()

function(add_gdal_driver)
set(_options BUILTIN PLUGIN_CAPABLE NO_DEPS STRONG_CXX_WFLAGS CXX_WFLAGS_EFFCXX NO_CXX_WFLAGS NO_SHARED_SYMBOL_WITH_CORE)
set(_options BUILTIN PLUGIN_CAPABLE NO_DEPS STRONG_CXX_WFLAGS CXX_WFLAGS_EFFCXX NO_CXX_WFLAGS NO_SHARED_SYMBOL_WITH_CORE SKIP_GDAL_PRIV_HEADER)
set(_oneValueArgs TARGET DESCRIPTION DEF PLUGIN_CAPABLE_IF DRIVER_NAME_OPTION)
set(_multiValueArgs SOURCES CORE_SOURCES)
cmake_parse_arguments(_DRIVER "${_options}" "${_oneValueArgs}" "${_multiValueArgs}" ${ARGN})
Expand Down Expand Up @@ -323,6 +323,13 @@ function(add_gdal_driver)
endif ()
endif ()
endif ()

target_compile_definitions(${_DRIVER_TARGET} PUBLIC $<$<CONFIG:DEBUG>:GDAL_DEBUG>)

if (USE_PRECOMPILED_HEADERS AND NOT _DRIVER_SKIP_GDAL_PRIV_HEADER)
target_precompile_headers(${_DRIVER_TARGET} REUSE_FROM gdal_priv_header)
endif()

if (_DRIVER_CXX_WFLAGS_EFFCXX)
target_compile_options(${_DRIVER_TARGET} PRIVATE $<$<COMPILE_LANGUAGE:CXX>:${GDAL_CXX_WARNING_FLAGS} ${WFLAG_EFFCXX}>)
elseif (_DRIVER_STRONG_CXX_WFLAGS)
Expand Down
37 changes: 35 additions & 2 deletions cmake/modules/Ccache.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,42 @@ exec \"${CXX_LAUNCHER}\" \"${CMAKE_CXX_COMPILER}\" \"$@\"
set(CMAKE_C_COMPILER "${CCACHE_PROGRAM}")
set(CMAKE_CXX_COMPILER "${CCACHE_PROGRAM}")
else()
set(CCACHE_INVOCATION_COMMAND "${CCACHE_PROGRAM}")
if (USE_PRECOMPILED_HEADERS)
execute_process(COMMAND ccache --help OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE CCACHE_HELP)
execute_process(COMMAND ccache --get-config sloppiness OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE CCACHE_SLOPPINESS)
string(FIND "${CCACHE_SLOPPINESS}" "pch_defines" fpch_defines_found_index)
string(FIND "${CCACHE_SLOPPINESS}" "time_macros" time_macros_found_index)
string(FIND "${CCACHE_SLOPPINESS}" "include_file_mtime" include_file_mtime_found_index)
string(FIND "${CCACHE_SLOPPINESS}" "include_file_ctime" include_file_ctime_found_index)
# Detect if we have ccache >= 4.8 which accepts passing configuration settings when invoking the compiler
string(FIND "${CCACHE_HELP}" "ccache [KEY=VALUE ...] compiler" ccache_key_value_found_index)
if (fpch_defines_found_index EQUAL -1 OR time_macros_found_index EQUAL -1 OR
include_file_mtime_found_index EQUAL -1 OR include_file_ctime_found_index EQUAL -1)
set(CCACHE_SLOPPINESS_REQUIRED "pch_defines,time_macros,include_file_mtime,include_file_ctime")
else()
set(CCACHE_SLOPPINESS_REQUIRED "")
endif()
if (MSVC)
# CCache doesn't work yet with precompiled headers (cf https://github.com/ccache/ccache/issues/1383)
# so no need to set specific ccache configuration items
elseif (ccache_key_value_found_index EQUAL -1 )
if (CCACHE_SLOPPINESS_REQUIRED)
message(FATAL_ERROR "The use of precompiled headers only works if the ccache 'sloppiness' settings contains 'pch_defines' and 'time_macros'. Consider running 'ccache --set-config sloppiness=${CCACHE_SLOPPINESS_REQUIRED}' to define them")
endif()
else()
if (CCACHE_SLOPPINESS_REQUIRED)
string(APPEND CCACHE_INVOCATION_COMMAND " sloppiness=${CCACHE_SLOPPINESS_REQUIRED}")
endif()
endif()
endif()
# Most other generators (Unix Makefiles, Ninja, etc.)
set(CMAKE_C_COMPILER_LAUNCHER "${CCACHE_PROGRAM}")
set(CMAKE_CXX_COMPILER_LAUNCHER "${CCACHE_PROGRAM}")
if(CMAKE_C_COMPILER_LAUNCHER STREQUAL "ccache")
unset(CMAKE_C_COMPILER_LAUNCHER CACHE)
unset(CMAKE_CXX_COMPILER_LAUNCHER CACHE)
endif()
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CCACHE_INVOCATION_COMMAND}")
set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK "${CCACHE_INVOCATION_COMMAND}")
endif()
else()
message(WARNING "Ccache was requested, but no program was not found")
Expand Down
11 changes: 11 additions & 0 deletions doc/source/development/building_from_source.rst
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,17 @@ All cached entries can be viewed using ``cmake -LAH`` from a build directory.
`CMAKE_SKIP_INSTALL_RPATH <https://cmake.org/cmake/help/latest/variable/CMAKE_SKIP_INSTALL_RPATH.html>`__
variable is not set.

.. option:: USE_CCACHE=ON

Whether cached build using `ccache <https://ccache.dev/>`__ should be enabled.
This defaults to ON when :program:`ccache` is found.

.. option:: USE_PRECOMPILED_HEADER=OFF

Whether builds with precompiled headers should be enabled. This may speed
up the build process. This is still a bit experimental, so it is disabled by
default. It also cannot be enabled when using the Visual Studio C++ compiler.

Resource files embedding
++++++++++++++++++++++++

Expand Down
1 change: 1 addition & 0 deletions frmts/dds/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
add_gdal_driver(TARGET gdal_DDS
SOURCES ddsdataset.cpp
CORE_SOURCES ddsdrivercore.cpp
SKIP_GDAL_PRIV_HEADER # because of issue with _REENTRANT
PLUGIN_CAPABLE
NO_SHARED_SYMBOL_WITH_CORE)

Expand Down
1 change: 1 addition & 0 deletions frmts/pdf/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ add_gdal_driver(
pdfcreatefromcomposition.cpp
CORE_SOURCES pdfdrivercore.cpp
STRONG_CXX_WFLAGS
SKIP_GDAL_PRIV_HEADER
PLUGIN_CAPABLE
NO_SHARED_SYMBOL_WITH_CORE)

Expand Down
31 changes: 19 additions & 12 deletions gcore/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ add_library(
gdaldrivermanager.cpp
gdaldataset.cpp
gdalrasterband.cpp
gdal_misc.cpp
gdalrasterblock.cpp
gdalcolortable.cpp
gdalmajorobject.cpp
Expand Down Expand Up @@ -58,15 +57,19 @@ add_library(
gdal_thread_pool.cpp
nasakeywordhandler.cpp)

get_property(IS_UNITY_BUILD TARGET gcore PROPERTY UNITY_BUILD)
if(IS_UNITY_BUILD)
set_property(
SOURCE gdal_misc.cpp
APPEND
PROPERTY COMPILE_DEFINITIONS CMAKE_UNITY_BUILD)
endif()
add_library(gcore_gdal_misc OBJECT gdal_misc.cpp)
gdal_standard_includes(gcore_gdal_misc)
add_dependencies(gcore_gdal_misc generate_gdal_version_h)
set_property(TARGET gcore_gdal_misc PROPERTY POSITION_INDEPENDENT_CODE ${GDAL_OBJECT_LIBRARIES_POSITION_INDEPENDENT_CODE})
target_sources(${GDAL_LIB_TARGET_NAME} PRIVATE $<TARGET_OBJECTS:gcore_gdal_misc>)
target_link_libraries(gcore_gdal_misc PRIVATE PROJ::proj)
target_link_libraries(gcore PRIVATE PROJ::proj)

gdal_standard_includes(gcore)
target_compile_definitions(gcore PUBLIC $<$<CONFIG:DEBUG>:GDAL_DEBUG>)
if (USE_PRECOMPILED_HEADERS)
target_precompile_headers(gcore REUSE_FROM gdal_priv_header)
endif()
add_dependencies(gcore generate_gdal_version_h)
target_compile_options(gcore PRIVATE ${GDAL_CXX_WARNING_FLAGS} ${WFLAG_OLD_STYLE_CAST} ${WFLAG_EFFCXX})
target_include_directories(
Expand Down Expand Up @@ -109,8 +112,12 @@ if (GDAL_ENABLE_ARM_NEON_OPTIMIZATIONS)
target_compile_definitions(gcore PRIVATE -DHAVE_SSSE3_AT_COMPILE_TIME -DUSE_NEON_OPTIMIZATIONS)
target_sources(gcore PRIVATE rasterio_ssse3.cpp)
elseif (HAVE_SSSE3_AT_COMPILE_TIME)
target_compile_definitions(gcore PRIVATE -DHAVE_SSSE3_AT_COMPILE_TIME)
target_sources(gcore PRIVATE rasterio_ssse3.cpp)
add_library(gcore_rasterio_ssse3 OBJECT rasterio_ssse3.cpp)
add_dependencies(gcore_rasterio_ssse3 generate_gdal_version_h)
target_compile_definitions(gcore_rasterio_ssse3 PRIVATE -DHAVE_SSSE3_AT_COMPILE_TIME)
gdal_standard_includes(gcore_rasterio_ssse3)
set_property(TARGET gcore_rasterio_ssse3 PROPERTY POSITION_INDEPENDENT_CODE ${GDAL_OBJECT_LIBRARIES_POSITION_INDEPENDENT_CODE})
target_sources(${GDAL_LIB_TARGET_NAME} PRIVATE $<TARGET_OBJECTS:gcore_rasterio_ssse3>)
set_property(
SOURCE rasterio_ssse3.cpp
APPEND
Expand All @@ -122,11 +129,13 @@ if (EMBED_RESOURCE_FILES)
gdal_standard_includes(gcore_resources)
set_property(TARGET gcore_resources PROPERTY POSITION_INDEPENDENT_CODE ${GDAL_OBJECT_LIBRARIES_POSITION_INDEPENDENT_CODE})
target_compile_definitions(gcore PRIVATE EMBED_RESOURCE_FILES)
target_compile_definitions(gcore_gdal_misc PRIVATE EMBED_RESOURCE_FILES)
set_target_properties(gcore_resources PROPERTIES C_STANDARD 23)
target_sources(${GDAL_LIB_TARGET_NAME} PRIVATE $<TARGET_OBJECTS:gcore_resources>)
endif()
if (USE_ONLY_EMBEDDED_RESOURCE_FILES)
target_compile_definitions(gcore PRIVATE USE_ONLY_EMBEDDED_RESOURCE_FILES)
target_compile_definitions(gcore_gdal_misc PRIVATE USE_ONLY_EMBEDDED_RESOURCE_FILES)
endif()

target_sources(${GDAL_LIB_TARGET_NAME} PRIVATE $<TARGET_OBJECTS:gcore>)
Expand Down Expand Up @@ -184,8 +193,6 @@ if (GDAL_USE_CURL)
gdal_target_link_libraries(gcore PRIVATE CURL::libcurl)
endif ()

gdal_target_link_libraries(gcore PRIVATE PROJ::proj)

# Windows(Mingw/MSVC) link libraries
if (CMAKE_SYSTEM_NAME MATCHES "Windows")
# psapi needed for gdalpython.cpp (EnumProcessModules)
Expand Down
17 changes: 17 additions & 0 deletions gdal.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,23 @@ if(OGR_ENABLE_DRIVER_TAB AND
option(OGR_ENABLE_DRIVER_TAB_PLUGIN "Set ON to build OGR MapInfo TAB and MIF/MID driver as plugin" ON)
endif()

# Precompiled header
if (USE_PRECOMPILED_HEADERS)
include(GdalStandardIncludes)
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/gcore/empty_c.c" "")
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/gcore/empty.cpp" "")
add_library(gdal_priv_header OBJECT "${CMAKE_CURRENT_BINARY_DIR}/gcore/empty_c.c" "${CMAKE_CURRENT_BINARY_DIR}/gcore/empty.cpp")
gdal_standard_includes(gdal_priv_header)
add_dependencies(gdal_priv_header generate_gdal_version_h)
target_compile_options(gdal_priv_header PRIVATE $<$<COMPILE_LANGUAGE:CXX>:${GDAL_CXX_WARNING_FLAGS} ${WFLAG_OLD_STYLE_CAST} ${WFLAG_EFFCXX}> $<$<COMPILE_LANGUAGE:C>:${GDAL_C_WARNING_FLAGS}>)
target_compile_definitions(gdal_priv_header PUBLIC $<$<CONFIG:DEBUG>:GDAL_DEBUG>)
set_property(TARGET gdal_priv_header PROPERTY POSITION_INDEPENDENT_CODE ${GDAL_OBJECT_LIBRARIES_POSITION_INDEPENDENT_CODE})
target_precompile_headers(gdal_priv_header PUBLIC
$<$<COMPILE_LANGUAGE:CXX>:${CMAKE_CURRENT_SOURCE_DIR}/gcore/gdal_priv.h>
$<$<COMPILE_LANGUAGE:C>:${CMAKE_CURRENT_SOURCE_DIR}/port/cpl_port.h>
)
endif()

# Core components
add_subdirectory(alg)
add_subdirectory(ogr)
Expand Down
5 changes: 5 additions & 0 deletions ogr/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ target_include_directories(ogr PRIVATE $<TARGET_PROPERTY:ogr_MEM,SOURCE_DIR>)
set_property(TARGET ogr PROPERTY POSITION_INDEPENDENT_CODE ${GDAL_OBJECT_LIBRARIES_POSITION_INDEPENDENT_CODE})
target_sources(${GDAL_LIB_TARGET_NAME} PRIVATE $<TARGET_OBJECTS:ogr>)

target_compile_definitions(ogr PUBLIC $<$<CONFIG:DEBUG>:GDAL_DEBUG>)
if (USE_PRECOMPILED_HEADERS)
target_precompile_headers(ogr REUSE_FROM gdal_priv_header)
endif()

if (GDAL_USE_ZLIB_INTERNAL)
gdal_add_vendored_lib(ogr libz)
endif ()
Expand Down
1 change: 1 addition & 0 deletions ogr/ogrsf_frmts/dwg/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ add_gdal_driver(TARGET ogr_DWG_DGNV8
ogrdgnv8drivercore.cpp
ogrdwgdrivercore.cpp
DRIVER_NAME_OPTION DWG
SKIP_GDAL_PRIV_HEADER # because of issue with _REENTRANT
PLUGIN_CAPABLE
NO_SHARED_SYMBOL_WITH_CORE)

Expand Down
2 changes: 1 addition & 1 deletion ogr/ogrsf_frmts/mitab/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ add_gdal_driver(
mitab_geometry.cpp
mitab_tabseamless.cpp)
gdal_standard_includes(ogr_TAB)
target_compile_definitions(ogr_TAB PRIVATE -DOGR -DMITAB_USE_OFTDATETIME)
target_compile_definitions(ogr_TAB PRIVATE -DMITAB_USE_OFTDATETIME)
1 change: 1 addition & 0 deletions ogr/ogrsf_frmts/mongodbv3/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
add_gdal_driver(TARGET ogr_MongoDBv3
SOURCES ogrmongodbv3driver.cpp
CORE_SOURCES ogrmongodbv3drivercore.cpp
SKIP_GDAL_PRIV_HEADER # because of below -fno-operator-names
NO_CXX_WFLAGS PLUGIN_CAPABLE
NO_SHARED_SYMBOL_WITH_CORE)

Expand Down
Loading

0 comments on commit 9b04b5a

Please sign in to comment.