From 05b81e9f30a5da72508dc5824985fcfa7874514d Mon Sep 17 00:00:00 2001 From: kervala Date: Sat, 26 Jun 2010 17:14:08 +0200 Subject: [PATCH] Changed: #880 Added WITH_PCH to activate Precompiled Header (default is ON) --- code/nel/CMakeModules/PCHSupport.cmake | 157 +++++++++--------- code/nel/CMakeModules/nel.cmake | 1 + .../tools/3d/object_viewer_exe/CMakeLists.txt | 6 +- .../logic/logic_editor_dll/CMakeLists.txt | 5 +- .../logic/logic_editor_exe/CMakeLists.txt | 4 +- 5 files changed, 89 insertions(+), 84 deletions(-) diff --git a/code/nel/CMakeModules/PCHSupport.cmake b/code/nel/CMakeModules/PCHSupport.cmake index 58fe92223..efdf19894 100644 --- a/code/nel/CMakeModules/PCHSupport.cmake +++ b/code/nel/CMakeModules/PCHSupport.cmake @@ -159,107 +159,112 @@ ENDMACRO(ADD_PRECOMPILED_HEADER_TO_TARGET) 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) - MESSAGE(FATAL_ERROR - "This is the ADD_PRECOMPILED_HEADER macro. " - "You must set CMAKE_BUILD_TYPE!" - ) - ENDIF(NOT CMAKE_BUILD_TYPE) + IF(NOT CMAKE_BUILD_TYPE) + MESSAGE(FATAL_ERROR + "This is the ADD_PRECOMPILED_HEADER macro. " + "You must set CMAKE_BUILD_TYPE!" + ) + ENDIF(NOT CMAKE_BUILD_TYPE) - IF( "${ARGN}" STREQUAL "0") - SET(_dowarn 0) - ELSE( "${ARGN}" STREQUAL "0") - SET(_dowarn 1) - ENDIF("${ARGN}" STREQUAL "0") + IF( "${ARGN}" STREQUAL "0") + SET(_dowarn 0) + ELSE( "${ARGN}" STREQUAL "0") + SET(_dowarn 1) + ENDIF("${ARGN}" STREQUAL "0") - GET_FILENAME_COMPONENT(_name ${_inputh} NAME) - GET_FILENAME_COMPONENT(_path ${_inputh} PATH) - GET_PRECOMPILED_HEADER_OUTPUT( ${_targetName} ${_inputh} _output) + GET_FILENAME_COMPONENT(_name ${_inputh} NAME) + GET_FILENAME_COMPONENT(_path ${_inputh} PATH) + 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 - ADD_LIBRARY(${_targetName}_pch_dephelp STATIC ${_inputcpp}) + # always build static library because it doesn't need linking + 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("COMMAND ${CMAKE_CXX_COMPILER} ${_compile_FLAGS} -x c++-header -o ${_output} ${_input}") - SET_SOURCE_FILES_PROPERTIES(${CMAKE_CURRENT_BINARY_DIR}/${_name} PROPERTIES GENERATED 1) - ADD_CUSTOM_COMMAND( - OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${_name} - COMMAND ${CMAKE_COMMAND} -E copy ${_inputh} ${CMAKE_CURRENT_BINARY_DIR}/${_name} # ensure same directory! Required by gcc - DEPENDS ${_inputh} + #MESSAGE("_compile_FLAGS: ${_compile_FLAGS}") + #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) + ADD_CUSTOM_COMMAND( + OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${_name} + COMMAND ${CMAKE_COMMAND} -E copy ${_inputh} ${CMAKE_CURRENT_BINARY_DIR}/${_name} # ensure same directory! Required by gcc + 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}") - _PCH_GET_COMPILE_COMMAND(_command ${CMAKE_CURRENT_BINARY_DIR}/${_name} ${_output}) + ADD_PRECOMPILED_HEADER_TO_TARGET(${_targetName} ${_inputh} ${_output} ${_dowarn}) + 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) MACRO(ADD_NATIVE_PRECOMPILED_HEADER _targetName _inputh _inputcpp) - IF( "${ARGN}" STREQUAL "0") - SET(_dowarn 0) - ELSE( "${ARGN}" STREQUAL "0") - SET(_dowarn 1) - ENDIF("${ARGN}" STREQUAL "0") + IF(WITH_PCH) + IF( "${ARGN}" STREQUAL "0") + SET(_dowarn 0) + ELSE( "${ARGN}" STREQUAL "0") + SET(_dowarn 1) + ENDIF("${ARGN}" STREQUAL "0") - if(CMAKE_GENERATOR MATCHES Visual*) - # Auto include the precompile (useful for moc processing, since the use of - # precompiled is specified at the target level - # 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 + if(CMAKE_GENERATOR MATCHES Visual*) + # Auto include the precompile (useful for moc processing, since the use of + # precompiled is specified at the target level + # 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) - # When buiding out of the tree, precompiled may not be located - # Use full path instead. - GET_FILENAME_COMPONENT(fullPath ${_inputh} ABSOLUTE) + SET(newProperties "${oldProps} /Yu\"${_inputh}\" /FI\"${_inputh}\"") + SET_TARGET_PROPERTIES(${_targetName} PROPERTIES COMPILE_FLAGS "${newProperties}") - SET_TARGET_PROPERTIES(${_targetName} PROPERTIES XCODE_ATTRIBUTE_GCC_PREFIX_HEADER "${fullPath}") - SET_TARGET_PROPERTIES(${_targetName} PROPERTIES XCODE_ATTRIBUTE_GCC_PRECOMPILE_PREFIX_HEADER "YES") + #also inlude ${oldProps} to have the same compile options + 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 - ADD_PRECOMPILED_HEADER(${_targetName} ${_inputh} ${_inputcpp} ${_dowarn}) - endif(CMAKE_GENERATOR MATCHES Xcode) - endif(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) + 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) diff --git a/code/nel/CMakeModules/nel.cmake b/code/nel/CMakeModules/nel.cmake index 6931cecca..0a76037cf 100644 --- a/code/nel/CMakeModules/nel.cmake +++ b/code/nel/CMakeModules/nel.cmake @@ -47,6 +47,7 @@ MACRO(NL_SETUP_DEFAULT_OPTIONS) ### OPTION(WITH_LOGGING "With Logging" ON ) OPTION(WITH_COVERAGE "With Code Coverage Support" OFF) + OPTION(WITH_PCH "With Precompiled Headers" ON ) ### # Core libraries diff --git a/code/nel/tools/3d/object_viewer_exe/CMakeLists.txt b/code/nel/tools/3d/object_viewer_exe/CMakeLists.txt index 2fc4b8fe3..eec97c4c9 100644 --- a/code/nel/tools/3d/object_viewer_exe/CMakeLists.txt +++ b/code/nel/tools/3d/object_viewer_exe/CMakeLists.txt @@ -16,14 +16,14 @@ TARGET_LINK_LIBRARIES( object_viewer object_viewer_dll) 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 LINK_FLAGS_DEBUG "${CMAKE_LINK_FLAGS_DEBUG}" LINK_FLAGS_RELEASE "${CMAKE_LINK_FLAGS_RELEASE}" 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) IF(WITH_MAXPLUGIN) INSTALL(TARGETS object_viewer RUNTIME DESTINATION maxplugin COMPONENT tools3d) -ENDIF(WITH_MAXPLUGIN) \ No newline at end of file +ENDIF(WITH_MAXPLUGIN) diff --git a/code/nel/tools/logic/logic_editor_dll/CMakeLists.txt b/code/nel/tools/logic/logic_editor_dll/CMakeLists.txt index 384428235..30fb836ac 100644 --- a/code/nel/tools/logic/logic_editor_dll/CMakeLists.txt +++ b/code/nel/tools/logic/logic_editor_dll/CMakeLists.txt @@ -16,15 +16,14 @@ SET_TARGET_PROPERTIES(logic_editor_dll PROPERTIES PROJECT_LABEL "Tools, Logic: Logic Editor DLL") 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 LINK_FLAGS_DEBUG "${CMAKE_LINK_FLAGS_DEBUG}" LINK_FLAGS_RELEASE "${CMAKE_LINK_FLAGS_RELEASE}" ) ENDIF(WIN32) - 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) diff --git a/code/nel/tools/logic/logic_editor_exe/CMakeLists.txt b/code/nel/tools/logic/logic_editor_exe/CMakeLists.txt index aaaa1a75f..dd4b4c8c6 100644 --- a/code/nel/tools/logic/logic_editor_exe/CMakeLists.txt +++ b/code/nel/tools/logic/logic_editor_exe/CMakeLists.txt @@ -7,12 +7,12 @@ TARGET_LINK_LIBRARIES(logic_editor ${LIBXML2_LIBRARIES} ${PLATFORM_LINKFLAGS} ne ADD_DEFINITIONS(${LIBXML2_DEFINITIONS}) 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 LINK_FLAGS_DEBUG "${CMAKE_LINK_FLAGS_DEBUG}" LINK_FLAGS_RELEASE "${CMAKE_LINK_FLAGS_RELEASE}" PROJECT_LABEL "Tools, Logic: Logic Editor") 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)