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
heavy-resources
Julius Michaelis 2012-03-30 19:47:21 +02:00
parent f5504f7497
commit 15696e75ae
2 changed files with 8 additions and 14 deletions

View File

@ -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()
############################################################################

View File

@ -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)