From 63c82ed8c60e0bd3694c48df2fdba4e2b3ef711e Mon Sep 17 00:00:00 2001 From: tamasmeszaros Date: Thu, 14 May 2020 10:10:47 +0200 Subject: [PATCH] Modify PCH script to use builtin cmake function if possible. --- cmake/modules/PrecompiledHeader.cmake | 15 +++++++++++++++ src/libslic3r/CMakeLists.txt | 3 +-- src/slic3r/CMakeLists.txt | 3 +-- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/cmake/modules/PrecompiledHeader.cmake b/cmake/modules/PrecompiledHeader.cmake index 2f62a7dbe..e5f01af21 100644 --- a/cmake/modules/PrecompiledHeader.cmake +++ b/cmake/modules/PrecompiledHeader.cmake @@ -101,7 +101,14 @@ function(export_all_flags _filename) file(GENERATE OUTPUT "${_filename}" CONTENT "${_compile_definitions}${_include_directories}${_compile_flags}${_compile_options}${_cxx_flags}\n") endfunction() +# Use the new builtin CMake function if possible or fall back to the old one. +if (CMAKE_VERSION VERSION_LESS 3.16) + function(add_precompiled_header _target _input) + + message(STATUS "Adding precompiled header ${_input} to target ${_target} with legacy method. " + "Update your cmake instance to use the native PCH functions.") + cmake_parse_arguments(_PCH "FORCEINCLUDE" "SOURCE_CXX;SOURCE_C" "" ${ARGN}) get_filename_component(_input_we ${_input} NAME_WE) @@ -241,3 +248,11 @@ function(add_precompiled_header _target _input) endforeach() endif(CMAKE_COMPILER_IS_GNUCXX) endfunction() + +else () + +function(add_precompiled_header _target _input) + target_precompile_headers(${_target} PRIVATE ${_input}) +endfunction() + +endif (CMAKE_VERSION VERSION_LESS 3.16) diff --git a/src/libslic3r/CMakeLists.txt b/src/libslic3r/CMakeLists.txt index ae9087ed4..12e61d7f3 100644 --- a/src/libslic3r/CMakeLists.txt +++ b/src/libslic3r/CMakeLists.txt @@ -308,6 +308,5 @@ if(SLIC3R_PROFILE) endif() if (SLIC3R_PCH AND NOT SLIC3R_SYNTAXONLY) - #add_precompiled_header(libslic3r pchheader.hpp FORCEINCLUDE) - target_precompile_headers(libslic3r PRIVATE pchheader.hpp) + add_precompiled_header(libslic3r pchheader.hpp FORCEINCLUDE) endif () diff --git a/src/slic3r/CMakeLists.txt b/src/slic3r/CMakeLists.txt index a110a82ed..ac6961990 100644 --- a/src/slic3r/CMakeLists.txt +++ b/src/slic3r/CMakeLists.txt @@ -231,6 +231,5 @@ if (SLIC3R_STATIC AND UNIX AND NOT APPLE) endif () if (SLIC3R_PCH AND NOT SLIC3R_SYNTAXONLY) - #add_precompiled_header(libslic3r_gui pchheader.hpp FORCEINCLUDE) - target_precompile_headers(libslic3r_gui PRIVATE pchheader.hpp) + add_precompiled_header(libslic3r_gui pchheader.hpp FORCEINCLUDE) endif ()