From 15696e75aee8656f2e2e369f8988f073f98e931f Mon Sep 17 00:00:00 2001 From: Julius Michaelis Date: Fri, 30 Mar 2012 19:47:21 +0200 Subject: [PATCH] Fix the GCC precompiled headers It's still hacky as hell, but changing CMAKE_BUILD_TYPE or only rebuilding c4script without c4group_pch shouldn't break anymore --- CMakeLists.txt | 1 + cmake/GccPchSupport.cmake | 21 +++++++-------------- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index cbfa88fe7..28cc58e20 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1101,6 +1101,7 @@ endif() if(USE_GCC_PCH) add_precompiled_header(clonk src/C4Include.h) add_precompiled_header(c4group src/C4Include.h) + add_precompiled_header(c4script src/C4Include.h) endif() ############################################################################ diff --git a/cmake/GccPchSupport.cmake b/cmake/GccPchSupport.cmake index 47a6f2dfe..aa1f5c351 100644 --- a/cmake/GccPchSupport.cmake +++ b/cmake/GccPchSupport.cmake @@ -1,22 +1,15 @@ #Copied from http://www.mail-archive.com/cmake@cmake.org/msg04394.html which copied it from the rosengarden project #see also: http://gcc.gnu.org/onlinedocs/gcc-4.0.4/gcc/Precompiled-Headers.html -MACRO(ADD_PRECOMPILED_HEADER _targetName _input ) +MACRO(ADD_PRECOMPILED_HEADER _targetName _input) # Prepare environment - if(CMAKE_BUILD_TYPE) - SET(_proper_build_type ${CMAKE_BUILD_TYPE}) - else() - SET(_proper_build_type Standard) - endif() GET_FILENAME_COMPONENT(_name ${_input} NAME) - SET(_pchdir "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/pch.custom.dir") + SET(_pchdir "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${_targetName}_pch") + MAKE_DIRECTORY(${_pchdir}) SET(_source "${CMAKE_CURRENT_SOURCE_DIR}/${_input}") - SET(_outdir "${_pchdir}/${_name}.gch") - MAKE_DIRECTORY(${_outdir}) - string(REPLACE "/" "_" _inputescaped ${_input}) - SET(_output "${_outdir}/${_inputescaped}_${_targetName}_${_proper_build_type}.o") - #FILE(WRITE "${_pchdir}/${_name}" "\#error Precompiled header not used") + SET(_includeput "${_pchdir}/${_name}") + SET(_output "${_includeput}.gch") # Assemble the compiler command with which future stuff will be built STRING(TOUPPER "CMAKE_CXX_FLAGS_${CMAKE_BUILD_TYPE}" _flags_var_name) # Don't worry: CMake won't use any of the R/D/RWDI/MSR vars if the build type is not defined @@ -75,9 +68,9 @@ MACRO(ADD_PRECOMPILED_HEADER _targetName _input ) ${_compiler_FLAGS} -x c++-header -o ${_output} ${_source} IMPLICIT_DEPENDS CXX ${_source} ) + FILE(WRITE "${_pchdir}/${_name}" "") # This file is added so the cc-units don't stumble over not being able to include the file ADD_CUSTOM_TARGET(${_targetName}_pch DEPENDS ${_output}) ADD_DEPENDENCIES(${_targetName} ${_targetName}_pch) - INCLUDE_DIRECTORIES(BEFORE ${_pchdir}) - #SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Winvalid-pch" CACHE STRING "C++ compiler flags" FORCE) + SET_TARGET_PROPERTIES(${_targetName} PROPERTIES COMPILE_FLAGS "-include ${_includeput}") ENDMACRO(ADD_PRECOMPILED_HEADER)