<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
</head>
<body bgcolor="#FFFFFF" text="#000000">
I've spent all day trying to get a single precompiled header to work
on a series of targets within a rather complex project. I'll profess
to a fair amount of stabbing in the dark.<br>
<br>
I came up with the following, but it doesn't bother building the PCH
until the *end* of the first target. And then it fails because it
doesn't have the compiler definitions needed.<br>
<br>
So, how do I get my ADD_PCH(targetname) macro to prioritize the PCH
file, without making it always build the pch?<br>
<br>
Note: All of the candidate targets use the project include files,
compiler flags and definitions.<i></i><br>
<br>
8x --- snip --- x8<br>
<blockquote>
<pre><font face="Consolas">SET(_PCH_SRC "${Project_SOURCE_DIR}/cfg/syscfg.h")
SET(_PCH_HDR ${_PCH_SRC})        # Viable as a dependency name.
IF ( _USE_PCH )
IF (WINDOWS)
SET(_PCH_HDR "${_PCH_SRC}.pch")
ELSE ()
SET(_PCH_HDR "${_PCH_SRC}.gch")
ENDIF()
SET(_pchFlags "${CMAKE_CXX_FLAGS}")
GET_DIRECTORY_PROPERTY(_pcfIncludePaths INCLUDE_DIRECTORIES)
FOREACH (_inc ${_pcfIncludePaths})
LIST(APPEND _pchFlags "-I" ${_inc})
ENDFOREACH()
GET_DIRECTORY_PROPERTY(_pcfIncludePaths COMPILE_DEFINITIONS)
FOREACH (_inc ${_pcfIncludePaths})
LIST(APPEND _pchFlags "-D" ${_inc})
ENDFOREACH()
SEPARATE_ARGUMENTS(_pchFlags)
ADD_CUSTOM_COMMAND(
PRE_BUILD
OUTPUT ${_PCH_HDR}
COMMAND ${CMAKE_CXX_COMPILER} ${CMAKE_CXX_COMPILER_ARG1} ${_pchFlags} -o ${_PCH_HDR} ${_PCH_SRC}
MAIN_DEPENDENCY ${_PCH_SRC}
IMPLICIT_DEPENDS CXX ${_PCH_SRC}
DEPENDS ${_PCH_SRC}
)
ENDIF ( _USE_PCH )
MACRO(ADD_PCH _TARGET)
IF ( WW2_USE_PCH )
MESSAGE(STATUS "Adding pch to ${_TARGET}")
add_dependencies(${_TARGET} ${_PCH_HDR})
ENDIF ( )
ENDMACRO()
</font></pre>
</blockquote>
8x --- snip --- x8<br>
<br>
For bonus points: The business of having to copy the include paths
and compiler definitions seems really clumsy, it's horribly platform
dependent. Surely there's a better way say "build it the same way
you'd build anything else in this directory"????<br>
<br>
- Oliver<br>
<br>
</body>
</html>