Changed: #880 Added WITH_PCH to activate Precompiled Header (default is ON)

This commit is contained in:
kervala 2010-06-26 17:14:08 +02:00
parent 0238458539
commit f33365ea10
5 changed files with 89 additions and 84 deletions

View file

@ -159,107 +159,112 @@ ENDMACRO(ADD_PRECOMPILED_HEADER_TO_TARGET)
MACRO(ADD_PRECOMPILED_HEADER _targetName _inputh _inputcpp) MACRO(ADD_PRECOMPILED_HEADER _targetName _inputh _inputcpp)
SET(_PCH_current_target ${_targetName}) IF(WITH_PCH)
SET(_PCH_current_target ${_targetName})
IF(NOT CMAKE_BUILD_TYPE) IF(NOT CMAKE_BUILD_TYPE)
MESSAGE(FATAL_ERROR MESSAGE(FATAL_ERROR
"This is the ADD_PRECOMPILED_HEADER macro. " "This is the ADD_PRECOMPILED_HEADER macro. "
"You must set CMAKE_BUILD_TYPE!" "You must set CMAKE_BUILD_TYPE!"
) )
ENDIF(NOT CMAKE_BUILD_TYPE) ENDIF(NOT CMAKE_BUILD_TYPE)
IF( "${ARGN}" STREQUAL "0") IF( "${ARGN}" STREQUAL "0")
SET(_dowarn 0) SET(_dowarn 0)
ELSE( "${ARGN}" STREQUAL "0") ELSE( "${ARGN}" STREQUAL "0")
SET(_dowarn 1) SET(_dowarn 1)
ENDIF("${ARGN}" STREQUAL "0") ENDIF("${ARGN}" STREQUAL "0")
GET_FILENAME_COMPONENT(_name ${_inputh} NAME) GET_FILENAME_COMPONENT(_name ${_inputh} NAME)
GET_FILENAME_COMPONENT(_path ${_inputh} PATH) GET_FILENAME_COMPONENT(_path ${_inputh} PATH)
GET_PRECOMPILED_HEADER_OUTPUT( ${_targetName} ${_inputh} _output) GET_PRECOMPILED_HEADER_OUTPUT( ${_targetName} ${_inputh} _output)
GET_FILENAME_COMPONENT(_outdir ${_output} PATH ) GET_FILENAME_COMPONENT(_outdir ${_output} PATH )
GET_TARGET_PROPERTY(_targetType ${_PCH_current_target} TYPE) GET_TARGET_PROPERTY(_targetType ${_PCH_current_target} TYPE)
# always build static library because it doesn't need linking # always build static library because it doesn't need linking
ADD_LIBRARY(${_targetName}_pch_dephelp STATIC ${_inputcpp}) ADD_LIBRARY(${_targetName}_pch_dephelp STATIC ${_inputcpp})
FILE(MAKE_DIRECTORY ${_outdir}) FILE(MAKE_DIRECTORY ${_outdir})
_PCH_GET_COMPILE_FLAGS(_compile_FLAGS) _PCH_GET_COMPILE_FLAGS(_compile_FLAGS)
#MESSAGE("_compile_FLAGS: ${_compile_FLAGS}") #MESSAGE("_compile_FLAGS: ${_compile_FLAGS}")
#message("COMMAND ${CMAKE_CXX_COMPILER} ${_compile_FLAGS} -x c++-header -o ${_output} ${_input}") #message("COMMAND ${CMAKE_CXX_COMPILER} ${_compile_FLAGS} -x c++-header -o ${_output} ${_input}")
SET_SOURCE_FILES_PROPERTIES(${CMAKE_CURRENT_BINARY_DIR}/${_name} PROPERTIES GENERATED 1) SET_SOURCE_FILES_PROPERTIES(${CMAKE_CURRENT_BINARY_DIR}/${_name} PROPERTIES GENERATED 1)
ADD_CUSTOM_COMMAND( ADD_CUSTOM_COMMAND(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${_name} OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${_name}
COMMAND ${CMAKE_COMMAND} -E copy ${_inputh} ${CMAKE_CURRENT_BINARY_DIR}/${_name} # ensure same directory! Required by gcc COMMAND ${CMAKE_COMMAND} -E copy ${_inputh} ${CMAKE_CURRENT_BINARY_DIR}/${_name} # ensure same directory! Required by gcc
DEPENDS ${_inputh} DEPENDS ${_inputh}
)
#message("_command ${_input} ${_output}")
_PCH_GET_COMPILE_COMMAND(_command ${CMAKE_CURRENT_BINARY_DIR}/${_name} ${_output})
#message(${_input} )
#message("_output ${_output}")
ADD_CUSTOM_COMMAND(
OUTPUT ${_output}
COMMAND ${_command}
DEPENDS ${_inputh} ${CMAKE_CURRENT_BINARY_DIR}/${_name} ${_targetName}_pch_dephelp
) )
#message("_command ${_input} ${_output}") ADD_PRECOMPILED_HEADER_TO_TARGET(${_targetName} ${_inputh} ${_output} ${_dowarn})
_PCH_GET_COMPILE_COMMAND(_command ${CMAKE_CURRENT_BINARY_DIR}/${_name} ${_output}) ENDIF(WITH_PCH)
#message(${_input} )
#message("_output ${_output}")
ADD_CUSTOM_COMMAND(
OUTPUT ${_output}
COMMAND ${_command}
DEPENDS ${_inputh} ${CMAKE_CURRENT_BINARY_DIR}/${_name} ${_targetName}_pch_dephelp
)
ADD_PRECOMPILED_HEADER_TO_TARGET(${_targetName} ${_inputh} ${_output} ${_dowarn})
ENDMACRO(ADD_PRECOMPILED_HEADER) ENDMACRO(ADD_PRECOMPILED_HEADER)
MACRO(ADD_NATIVE_PRECOMPILED_HEADER _targetName _inputh _inputcpp) MACRO(ADD_NATIVE_PRECOMPILED_HEADER _targetName _inputh _inputcpp)
IF( "${ARGN}" STREQUAL "0") IF(WITH_PCH)
SET(_dowarn 0) IF( "${ARGN}" STREQUAL "0")
ELSE( "${ARGN}" STREQUAL "0") SET(_dowarn 0)
SET(_dowarn 1) ELSE( "${ARGN}" STREQUAL "0")
ENDIF("${ARGN}" STREQUAL "0") SET(_dowarn 1)
ENDIF("${ARGN}" STREQUAL "0")
if(CMAKE_GENERATOR MATCHES Visual*) if(CMAKE_GENERATOR MATCHES Visual*)
# Auto include the precompile (useful for moc processing, since the use of # Auto include the precompile (useful for moc processing, since the use of
# precompiled is specified at the target level # precompiled is specified at the target level
# and I don't want to specifiy /F- for each moc/res/ui generated files (using Qt) # and I don't want to specifiy /F- for each moc/res/ui generated files (using Qt)
GET_TARGET_PROPERTY(oldProps ${_targetName} COMPILE_FLAGS)
if (${oldProps} MATCHES NOTFOUND)
SET(oldProps "")
endif(${oldProps} MATCHES NOTFOUND)
SET(newProperties "${oldProps} /Yu\"${_inputh}\" /FI\"${_inputh}\"")
SET_TARGET_PROPERTIES(${_targetName} PROPERTIES COMPILE_FLAGS "${newProperties}")
#also inlude ${oldProps} to have the same compile options
SET_SOURCE_FILES_PROPERTIES(${_inputcpp} PROPERTIES COMPILE_FLAGS "${oldProps} /Yc\"${_inputh}\"")
else(CMAKE_GENERATOR MATCHES Visual*)
if (CMAKE_GENERATOR MATCHES Xcode)
# For Xcode, cmake needs my patch to process
# GCC_PREFIX_HEADER and GCC_PRECOMPILE_PREFIX_HEADER as target properties
GET_TARGET_PROPERTY(oldProps ${_targetName} COMPILE_FLAGS) GET_TARGET_PROPERTY(oldProps ${_targetName} COMPILE_FLAGS)
if (${oldProps} MATCHES NOTFOUND) if (${oldProps} MATCHES NOTFOUND)
SET(oldProps "") SET(oldProps "")
endif(${oldProps} MATCHES NOTFOUND) endif(${oldProps} MATCHES NOTFOUND)
# When buiding out of the tree, precompiled may not be located SET(newProperties "${oldProps} /Yu\"${_inputh}\" /FI\"${_inputh}\"")
# Use full path instead. SET_TARGET_PROPERTIES(${_targetName} PROPERTIES COMPILE_FLAGS "${newProperties}")
GET_FILENAME_COMPONENT(fullPath ${_inputh} ABSOLUTE)
SET_TARGET_PROPERTIES(${_targetName} PROPERTIES XCODE_ATTRIBUTE_GCC_PREFIX_HEADER "${fullPath}") #also inlude ${oldProps} to have the same compile options
SET_TARGET_PROPERTIES(${_targetName} PROPERTIES XCODE_ATTRIBUTE_GCC_PRECOMPILE_PREFIX_HEADER "YES") SET_SOURCE_FILES_PROPERTIES(${_inputcpp} PROPERTIES COMPILE_FLAGS "${oldProps} /Yc\"${_inputh}\"")
else (CMAKE_GENERATOR MATCHES Xcode) else(CMAKE_GENERATOR MATCHES Visual*)
#Fallback to the "old" precompiled suppport if (CMAKE_GENERATOR MATCHES Xcode)
ADD_PRECOMPILED_HEADER(${_targetName} ${_inputh} ${_inputcpp} ${_dowarn}) # For Xcode, cmake needs my patch to process
endif(CMAKE_GENERATOR MATCHES Xcode) # GCC_PREFIX_HEADER and GCC_PRECOMPILE_PREFIX_HEADER as target properties
endif(CMAKE_GENERATOR MATCHES Visual*)
GET_TARGET_PROPERTY(oldProps ${_targetName} COMPILE_FLAGS)
if (${oldProps} MATCHES NOTFOUND)
SET(oldProps "")
endif(${oldProps} MATCHES NOTFOUND)
# When buiding out of the tree, precompiled may not be located
# Use full path instead.
GET_FILENAME_COMPONENT(fullPath ${_inputh} ABSOLUTE)
SET_TARGET_PROPERTIES(${_targetName} PROPERTIES XCODE_ATTRIBUTE_GCC_PREFIX_HEADER "${fullPath}")
SET_TARGET_PROPERTIES(${_targetName} PROPERTIES XCODE_ATTRIBUTE_GCC_PRECOMPILE_PREFIX_HEADER "YES")
else (CMAKE_GENERATOR MATCHES Xcode)
#Fallback to the "old" precompiled suppport
ADD_PRECOMPILED_HEADER(${_targetName} ${_inputh} ${_inputcpp} ${_dowarn})
endif(CMAKE_GENERATOR MATCHES Xcode)
endif(CMAKE_GENERATOR MATCHES Visual*)
ENDIF(WITH_PCH)
ENDMACRO(ADD_NATIVE_PRECOMPILED_HEADER) ENDMACRO(ADD_NATIVE_PRECOMPILED_HEADER)

View file

@ -47,6 +47,7 @@ MACRO(NL_SETUP_DEFAULT_OPTIONS)
### ###
OPTION(WITH_LOGGING "With Logging" ON ) OPTION(WITH_LOGGING "With Logging" ON )
OPTION(WITH_COVERAGE "With Code Coverage Support" OFF) OPTION(WITH_COVERAGE "With Code Coverage Support" OFF)
OPTION(WITH_PCH "With Precompiled Headers" ON )
### ###
# Core libraries # Core libraries

View file

@ -16,13 +16,13 @@ TARGET_LINK_LIBRARIES( object_viewer
object_viewer_dll) object_viewer_dll)
ADD_DEFINITIONS(${LIBXML2_DEFINITIONS}) ADD_DEFINITIONS(${LIBXML2_DEFINITIONS})
SET_TARGET_PROPERTIES(object_viewer PROPERTIES COMPILE_FLAGS "/Yustd_afx.h")
SET_SOURCE_FILES_PROPERTIES(std_afx.cpp PROPERTIES COMPILE_FLAGS "/Ycstd_afx.h")
SET_TARGET_PROPERTIES(object_viewer PROPERTIES SET_TARGET_PROPERTIES(object_viewer PROPERTIES
LINK_FLAGS_DEBUG "${CMAKE_LINK_FLAGS_DEBUG}" LINK_FLAGS_DEBUG "${CMAKE_LINK_FLAGS_DEBUG}"
LINK_FLAGS_RELEASE "${CMAKE_LINK_FLAGS_RELEASE}" LINK_FLAGS_RELEASE "${CMAKE_LINK_FLAGS_RELEASE}"
PROJECT_LABEL "Tools, 3D: Object Viewer") PROJECT_LABEL "Tools, 3D: Object Viewer")
ADD_NATIVE_PRECOMPILED_HEADER(object_viewer ${CMAKE_CURRENT_SOURCE_DIR}/std_afx.h ${CMAKE_CURRENT_SOURCE_DIR}/std_afx.cpp)
INSTALL(TARGETS object_viewer RUNTIME DESTINATION bin COMPONENT tools3d) INSTALL(TARGETS object_viewer RUNTIME DESTINATION bin COMPONENT tools3d)
IF(WITH_MAXPLUGIN) IF(WITH_MAXPLUGIN)
INSTALL(TARGETS object_viewer RUNTIME DESTINATION maxplugin COMPONENT tools3d) INSTALL(TARGETS object_viewer RUNTIME DESTINATION maxplugin COMPONENT tools3d)

View file

@ -16,15 +16,14 @@ SET_TARGET_PROPERTIES(logic_editor_dll PROPERTIES
PROJECT_LABEL "Tools, Logic: Logic Editor DLL") PROJECT_LABEL "Tools, Logic: Logic Editor DLL")
IF(WIN32) IF(WIN32)
SET_TARGET_PROPERTIES(logic_editor_dll PROPERTIES COMPILE_FLAGS "/YuStdAfx.h")
SET_SOURCE_FILES_PROPERTIES(StdAfx.cpp PROPERTIES COMPILE_FLAGS "/YcStdAfx.h")
SET_TARGET_PROPERTIES(logic_editor_dll PROPERTIES SET_TARGET_PROPERTIES(logic_editor_dll PROPERTIES
LINK_FLAGS_DEBUG "${CMAKE_LINK_FLAGS_DEBUG}" LINK_FLAGS_DEBUG "${CMAKE_LINK_FLAGS_DEBUG}"
LINK_FLAGS_RELEASE "${CMAKE_LINK_FLAGS_RELEASE}" LINK_FLAGS_RELEASE "${CMAKE_LINK_FLAGS_RELEASE}"
) )
ENDIF(WIN32) ENDIF(WIN32)
ADD_DEFINITIONS(${LIBXML2_DEFINITIONS}) ADD_DEFINITIONS(${LIBXML2_DEFINITIONS})
ADD_NATIVE_PRECOMPILED_HEADER(logic_editor_dll ${CMAKE_CURRENT_SOURCE_DIR}/StdAfx.h ${CMAKE_CURRENT_SOURCE_DIR}/StdAfx.cpp)
INSTALL(TARGETS logic_editor_dll LIBRARY DESTINATION lib RUNTIME DESTINATION bin ARCHIVE DESTINATION lib COMPONENT toolsmisc) INSTALL(TARGETS logic_editor_dll LIBRARY DESTINATION lib RUNTIME DESTINATION bin ARCHIVE DESTINATION lib COMPONENT toolsmisc)

View file

@ -7,12 +7,12 @@ TARGET_LINK_LIBRARIES(logic_editor ${LIBXML2_LIBRARIES} ${PLATFORM_LINKFLAGS} ne
ADD_DEFINITIONS(${LIBXML2_DEFINITIONS}) ADD_DEFINITIONS(${LIBXML2_DEFINITIONS})
IF(WIN32) IF(WIN32)
SET_TARGET_PROPERTIES(logic_editor PROPERTIES COMPILE_FLAGS "/YuStdAfx.h")
SET_SOURCE_FILES_PROPERTIES(StdAfx.cpp PROPERTIES COMPILE_FLAGS "/YcStdAfx.h")
SET_TARGET_PROPERTIES(logic_editor PROPERTIES SET_TARGET_PROPERTIES(logic_editor PROPERTIES
LINK_FLAGS_DEBUG "${CMAKE_LINK_FLAGS_DEBUG}" LINK_FLAGS_DEBUG "${CMAKE_LINK_FLAGS_DEBUG}"
LINK_FLAGS_RELEASE "${CMAKE_LINK_FLAGS_RELEASE}" LINK_FLAGS_RELEASE "${CMAKE_LINK_FLAGS_RELEASE}"
PROJECT_LABEL "Tools, Logic: Logic Editor") PROJECT_LABEL "Tools, Logic: Logic Editor")
ENDIF(WIN32) ENDIF(WIN32)
ADD_NATIVE_PRECOMPILED_HEADER(logic_editor ${CMAKE_CURRENT_SOURCE_DIR}/StdAfx.h ${CMAKE_CURRENT_SOURCE_DIR}/StdAfx.cpp)
INSTALL(TARGETS logic_editor RUNTIME DESTINATION bin COMPONENT toolsmisc) INSTALL(TARGETS logic_editor RUNTIME DESTINATION bin COMPONENT toolsmisc)