diff --git a/code/nel/CMakeLists.txt b/code/nel/CMakeLists.txt index 3af0eb2f7..801466119 100644 --- a/code/nel/CMakeLists.txt +++ b/code/nel/CMakeLists.txt @@ -167,9 +167,7 @@ ENDIF(UNIX) IF(WIN32) INCLUDE(${CMAKE_ROOT}/Modules/Platform/Windows-cl.cmake) - SET(WINSOCK2_LIB ws2_32.lib) - ENDIF(WIN32) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include ${CMAKE_CURRENT_SOURCE_DIR}/src) diff --git a/code/nel/CMakeModules/PCHSupport.cmake b/code/nel/CMakeModules/PCHSupport.cmake index 7e77829ac..dcfcc753a 100644 --- a/code/nel/CMakeModules/PCHSupport.cmake +++ b/code/nel/CMakeModules/PCHSupport.cmake @@ -134,84 +134,79 @@ ENDMACRO(ADD_PRECOMPILED_HEADER_TO_TARGET) MACRO(ADD_PRECOMPILED_HEADER _targetName _inputh _inputcpp) - IF(WITH_PCH) - SET(_PCH_current_target ${_targetName}) + 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) - - GET_PRECOMPILED_HEADER_OUTPUT( ${_targetName} ${_inputh} _output) - - 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}) - - _PCH_GET_COMPILE_FLAGS(_compile_FLAGS) - - SET_SOURCE_FILES_PROPERTIES(${_inputh} PROPERTIES GENERATED 1) - - _PCH_GET_COMPILE_COMMAND(_command ${_inputh} ${_output}) - - ADD_CUSTOM_COMMAND( - OUTPUT ${_output} - COMMAND ${_command} - DEPENDS ${_inputh} ${_targetName}_pch_dephelp + 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) - ADD_PRECOMPILED_HEADER_TO_TARGET(${_targetName} ${_inputh} ${_output}) - ENDIF(WITH_PCH) + GET_PRECOMPILED_HEADER_OUTPUT( ${_targetName} ${_inputh} _output) + + 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}) + + _PCH_GET_COMPILE_FLAGS(_compile_FLAGS) + + SET_SOURCE_FILES_PROPERTIES(${_inputh} PROPERTIES GENERATED 1) + + _PCH_GET_COMPILE_COMMAND(_command ${_inputh} ${_output}) + + ADD_CUSTOM_COMMAND( + OUTPUT ${_output} + COMMAND ${_command} + DEPENDS ${_inputh} ${_targetName}_pch_dephelp + ) + + ADD_PRECOMPILED_HEADER_TO_TARGET(${_targetName} ${_inputh} ${_output}) ENDMACRO(ADD_PRECOMPILED_HEADER) MACRO(ADD_NATIVE_PRECOMPILED_HEADER _targetName _inputh _inputcpp) - IF(WITH_PCH) + 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) - 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 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}") + # When buiding out of the tree, precompiled may not be located + # Use full path instead. + GET_FILENAME_COMPONENT(fullPath ${_inputh} ABSOLUTE) - #also inlude ${oldProps} to have the same compile options - SET_SOURCE_FILES_PROPERTIES(${_inputcpp} PROPERTIES COMPILE_FLAGS "${oldProps} /Yc\"${_inputh}\"") + 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 Visual*) + else (CMAKE_GENERATOR MATCHES Xcode) - 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}) - endif(CMAKE_GENERATOR MATCHES Xcode) - endif(CMAKE_GENERATOR MATCHES Visual*) - ENDIF(WITH_PCH) + #Fallback to the "old" precompiled suppport + ADD_PRECOMPILED_HEADER(${_targetName} ${_inputh} ${_inputcpp}) + endif(CMAKE_GENERATOR MATCHES Xcode) + endif(CMAKE_GENERATOR MATCHES Visual*) ENDMACRO(ADD_NATIVE_PRECOMPILED_HEADER) diff --git a/code/nel/src/3d/CMakeLists.txt b/code/nel/src/3d/CMakeLists.txt index 9037738fe..d32a1a6a5 100644 --- a/code/nel/src/3d/CMakeLists.txt +++ b/code/nel/src/3d/CMakeLists.txt @@ -693,7 +693,9 @@ ENDIF(WIN32) ADD_DEFINITIONS(${LIBXML2_DEFINITIONS}) -ADD_NATIVE_PRECOMPILED_HEADER(nel3d ${CMAKE_CURRENT_SOURCE_DIR}/std3d.h ${CMAKE_CURRENT_SOURCE_DIR}/std3d.cpp) +IF(WITH_PCH) + ADD_NATIVE_PRECOMPILED_HEADER(nel3d ${CMAKE_CURRENT_SOURCE_DIR}/std3d.h ${CMAKE_CURRENT_SOURCE_DIR}/std3d.cpp) +ENDIF(WITH_PCH) INSTALL(TARGETS nel3d LIBRARY DESTINATION lib ARCHIVE DESTINATION lib COMPONENT libraries) diff --git a/code/nel/src/3d/driver/direct3d/CMakeLists.txt b/code/nel/src/3d/driver/direct3d/CMakeLists.txt index 464a81ee6..f007893db 100644 --- a/code/nel/src/3d/driver/direct3d/CMakeLists.txt +++ b/code/nel/src/3d/driver/direct3d/CMakeLists.txt @@ -22,7 +22,9 @@ ADD_DEFINITIONS(/Ddriver_direct3d_EXPORTS) ADD_DEFINITIONS(${LIBXML2_DEFINITIONS}) -ADD_NATIVE_PRECOMPILED_HEADER(nel_drv_direct3d_win ${CMAKE_CURRENT_SOURCE_DIR}/stddirect3d.h ${CMAKE_CURRENT_SOURCE_DIR}/stddirect3d.cpp) +IF(WITH_PCH) + ADD_NATIVE_PRECOMPILED_HEADER(nel_drv_direct3d_win ${CMAKE_CURRENT_SOURCE_DIR}/stddirect3d.h ${CMAKE_CURRENT_SOURCE_DIR}/stddirect3d.cpp) +ENDIF(WITH_PCH) INSTALL(TARGETS nel_drv_direct3d_win LIBRARY DESTINATION lib RUNTIME DESTINATION bin COMPONENT drivers3d) IF(WITH_MAXPLUGIN) diff --git a/code/nel/src/3d/driver/opengl/CMakeLists.txt b/code/nel/src/3d/driver/opengl/CMakeLists.txt index 533c7b77e..c7827d820 100644 --- a/code/nel/src/3d/driver/opengl/CMakeLists.txt +++ b/code/nel/src/3d/driver/opengl/CMakeLists.txt @@ -52,9 +52,9 @@ ENDIF(WIN32) ADD_DEFINITIONS(${LIBXML2_DEFINITIONS}) -IF(NOT WITH_COCOA) +IF(NOT WITH_COCOA AND WITH_PCH) ADD_NATIVE_PRECOMPILED_HEADER(${NLDRV_OGL_LIB} ${CMAKE_CURRENT_SOURCE_DIR}/stdopengl.h ${CMAKE_CURRENT_SOURCE_DIR}/stdopengl.cpp) -ENDIF(NOT WITH_COCOA) +ENDIF(NOT WITH_COCOA AND WITH_PCH) INSTALL(TARGETS ${NLDRV_OGL_LIB} LIBRARY DESTINATION lib RUNTIME DESTINATION bin COMPONENT drivers3d) IF(WITH_MAXPLUGIN) diff --git a/code/nel/src/georges/CMakeLists.txt b/code/nel/src/georges/CMakeLists.txt index 223fee488..7b46520eb 100644 --- a/code/nel/src/georges/CMakeLists.txt +++ b/code/nel/src/georges/CMakeLists.txt @@ -27,6 +27,8 @@ ENDIF(WIN32) ADD_DEFINITIONS(${LIBXML2_DEFINITIONS}) -ADD_NATIVE_PRECOMPILED_HEADER(nelgeorges ${CMAKE_CURRENT_SOURCE_DIR}/stdgeorges.h ${CMAKE_CURRENT_SOURCE_DIR}/stdgeorges.cpp) +IF(WITH_PCH) + ADD_NATIVE_PRECOMPILED_HEADER(nelgeorges ${CMAKE_CURRENT_SOURCE_DIR}/stdgeorges.h ${CMAKE_CURRENT_SOURCE_DIR}/stdgeorges.cpp) +ENDIF(WITH_PCH) INSTALL(TARGETS nelgeorges LIBRARY DESTINATION lib ARCHIVE DESTINATION lib COMPONENT libraries) diff --git a/code/nel/src/misc/CMakeLists.txt b/code/nel/src/misc/CMakeLists.txt index 6b09cc1f3..ab523536c 100644 --- a/code/nel/src/misc/CMakeLists.txt +++ b/code/nel/src/misc/CMakeLists.txt @@ -29,8 +29,6 @@ SET_TARGET_PROPERTIES(nelmisc PROPERTIES SOVERSION ${NL_VERSION_MAJOR} PROJECT_LABEL "Library: NeL Misc") -ADD_DEFINITIONS(${LIBXML2_DEFINITIONS}) - IF(WIN32) SET_TARGET_PROPERTIES(nelmisc PROPERTIES DEBUG_POSTFIX "_d" @@ -38,6 +36,10 @@ IF(WIN32) INCLUDE_DIRECTORIES(${DXSDK_INCLUDE_DIR}) ENDIF(WIN32) -ADD_NATIVE_PRECOMPILED_HEADER(nelmisc ${CMAKE_CURRENT_SOURCE_DIR}/stdmisc.h ${CMAKE_CURRENT_SOURCE_DIR}/stdmisc.cpp) +ADD_DEFINITIONS(${LIBXML2_DEFINITIONS}) + +IF(WITH_PCH) + ADD_NATIVE_PRECOMPILED_HEADER(nelmisc ${CMAKE_CURRENT_SOURCE_DIR}/stdmisc.h ${CMAKE_CURRENT_SOURCE_DIR}/stdmisc.cpp) +ENDIF(WITH_PCH) INSTALL(TARGETS nelmisc LIBRARY DESTINATION lib ARCHIVE DESTINATION lib COMPONENT libraries) diff --git a/code/nel/src/net/CMakeLists.txt b/code/nel/src/net/CMakeLists.txt index bfa6da5d4..712ce0e5a 100644 --- a/code/nel/src/net/CMakeLists.txt +++ b/code/nel/src/net/CMakeLists.txt @@ -38,6 +38,8 @@ ENDIF(WIN32) ADD_DEFINITIONS(${LIBXML2_DEFINITIONS}) -ADD_NATIVE_PRECOMPILED_HEADER(${NLNET_LIB} ${CMAKE_CURRENT_SOURCE_DIR}/stdnet.h ${CMAKE_CURRENT_SOURCE_DIR}/stdnet.cpp) +IF(WITH_PCH) + ADD_NATIVE_PRECOMPILED_HEADER(${NLNET_LIB} ${CMAKE_CURRENT_SOURCE_DIR}/stdnet.h ${CMAKE_CURRENT_SOURCE_DIR}/stdnet.cpp) +ENDIF(WITH_PCH) INSTALL(TARGETS ${NLNET_LIB} LIBRARY DESTINATION lib ARCHIVE DESTINATION lib COMPONENT libraries) diff --git a/code/nel/src/pacs/CMakeLists.txt b/code/nel/src/pacs/CMakeLists.txt index 4072a90a7..722f151d9 100644 --- a/code/nel/src/pacs/CMakeLists.txt +++ b/code/nel/src/pacs/CMakeLists.txt @@ -20,6 +20,8 @@ IF(WIN32) SET_TARGET_PROPERTIES(nelpacs PROPERTIES DEBUG_POSTFIX "_d" RELEASE_POSTFIX "_r") ENDIF(WIN32) -ADD_NATIVE_PRECOMPILED_HEADER(nelpacs ${CMAKE_CURRENT_SOURCE_DIR}/stdpacs.h ${CMAKE_CURRENT_SOURCE_DIR}/stdpacs.cpp) +IF(WITH_PCH) + ADD_NATIVE_PRECOMPILED_HEADER(nelpacs ${CMAKE_CURRENT_SOURCE_DIR}/stdpacs.h ${CMAKE_CURRENT_SOURCE_DIR}/stdpacs.cpp) +ENDIF(WITH_PCH) INSTALL(TARGETS nelpacs LIBRARY DESTINATION lib ARCHIVE DESTINATION lib COMPONENT libraries) diff --git a/code/nel/src/sound/CMakeLists.txt b/code/nel/src/sound/CMakeLists.txt index 103c9606b..36d43c182 100644 --- a/code/nel/src/sound/CMakeLists.txt +++ b/code/nel/src/sound/CMakeLists.txt @@ -28,7 +28,9 @@ IF(WIN32) RELEASE_POSTFIX "_r") ENDIF(WIN32) -ADD_NATIVE_PRECOMPILED_HEADER(nelsound ${CMAKE_CURRENT_SOURCE_DIR}/stdsound.h ${CMAKE_CURRENT_SOURCE_DIR}/stdsound.cpp) +IF(WITH_PCH) + ADD_NATIVE_PRECOMPILED_HEADER(nelsound ${CMAKE_CURRENT_SOURCE_DIR}/stdsound.h ${CMAKE_CURRENT_SOURCE_DIR}/stdsound.cpp) +ENDIF(WITH_PCH) INSTALL(TARGETS nelsound LIBRARY DESTINATION lib ARCHIVE DESTINATION lib COMPONENT libraries) diff --git a/code/nel/src/sound/driver/dsound/CMakeLists.txt b/code/nel/src/sound/driver/dsound/CMakeLists.txt index 48c0506d6..fa5166d5a 100644 --- a/code/nel/src/sound/driver/dsound/CMakeLists.txt +++ b/code/nel/src/sound/driver/dsound/CMakeLists.txt @@ -14,7 +14,9 @@ SET_TARGET_PROPERTIES(nel_drv_dsound PROPERTIES PROJECT_LABEL "Driver, Sound: DirectSound") ADD_DEFINITIONS(${LIBXML2_DEFINITIONS}) -ADD_NATIVE_PRECOMPILED_HEADER(nel_drv_dsound ${CMAKE_CURRENT_SOURCE_DIR}/stddsound.h ${CMAKE_CURRENT_SOURCE_DIR}/stddsound.cpp) +IF(WITH_PCH) + ADD_NATIVE_PRECOMPILED_HEADER(nel_drv_dsound ${CMAKE_CURRENT_SOURCE_DIR}/stddsound.h ${CMAKE_CURRENT_SOURCE_DIR}/stddsound.cpp) +ENDIF(WITH_PCH) INSTALL(TARGETS nel_drv_dsound RUNTIME DESTINATION bin LIBRARY DESTINATION lib ARCHIVE DESTINATION lib COMPONENT driverssound) IF(WITH_MAXPLUGIN) diff --git a/code/nel/src/sound/driver/fmod/CMakeLists.txt b/code/nel/src/sound/driver/fmod/CMakeLists.txt index 3682a3fd6..976b727cf 100644 --- a/code/nel/src/sound/driver/fmod/CMakeLists.txt +++ b/code/nel/src/sound/driver/fmod/CMakeLists.txt @@ -18,7 +18,9 @@ IF(WIN32) RELEASE_POSTFIX "_r") ENDIF(WIN32) -ADD_NATIVE_PRECOMPILED_HEADER(nel_drv_fmod ${CMAKE_CURRENT_SOURCE_DIR}/stdfmod.h ${CMAKE_CURRENT_SOURCE_DIR}/stdfmod.cpp) +IF(WITH_PCH) + ADD_NATIVE_PRECOMPILED_HEADER(nel_drv_fmod ${CMAKE_CURRENT_SOURCE_DIR}/stdfmod.h ${CMAKE_CURRENT_SOURCE_DIR}/stdfmod.cpp) +ENDIF(WITH_PCH) INSTALL(TARGETS nel_drv_fmod RUNTIME DESTINATION bin LIBRARY DESTINATION lib ARCHIVE DESTINATION lib COMPONENT driverssound) IF(WITH_MAXPLUGIN) diff --git a/code/nel/src/sound/driver/openal/CMakeLists.txt b/code/nel/src/sound/driver/openal/CMakeLists.txt index 9b1a26967..cb180898c 100644 --- a/code/nel/src/sound/driver/openal/CMakeLists.txt +++ b/code/nel/src/sound/driver/openal/CMakeLists.txt @@ -23,7 +23,9 @@ IF(WIN32) PROJECT_LABEL "Driver, Sound: OpenAL") ENDIF(WIN32) -ADD_NATIVE_PRECOMPILED_HEADER(nel_drv_openal ${CMAKE_CURRENT_SOURCE_DIR}/stdopenal.h ${CMAKE_CURRENT_SOURCE_DIR}/stdopenal.cpp) +IF(WITH_PCH) + ADD_NATIVE_PRECOMPILED_HEADER(nel_drv_openal ${CMAKE_CURRENT_SOURCE_DIR}/stdopenal.h ${CMAKE_CURRENT_SOURCE_DIR}/stdopenal.cpp) +ENDIF(WITH_PCH) INSTALL(TARGETS nel_drv_openal RUNTIME DESTINATION bin LIBRARY DESTINATION lib ARCHIVE DESTINATION lib COMPONENT driverssound) IF(WITH_MAXPLUGIN) diff --git a/code/nel/src/sound/driver/xaudio2/CMakeLists.txt b/code/nel/src/sound/driver/xaudio2/CMakeLists.txt index 6363e9457..57a2ebe68 100644 --- a/code/nel/src/sound/driver/xaudio2/CMakeLists.txt +++ b/code/nel/src/sound/driver/xaudio2/CMakeLists.txt @@ -18,7 +18,9 @@ IF(WIN32) PROJECT_LABEL "Driver, Sound: XAudio2") ENDIF(WIN32) -ADD_NATIVE_PRECOMPILED_HEADER(nel_drv_xaudio2 ${CMAKE_CURRENT_SOURCE_DIR}/stdxaudio2.h ${CMAKE_CURRENT_SOURCE_DIR}/stdxaudio2.cpp) +IF(WITH_PCH) + ADD_NATIVE_PRECOMPILED_HEADER(nel_drv_xaudio2 ${CMAKE_CURRENT_SOURCE_DIR}/stdxaudio2.h ${CMAKE_CURRENT_SOURCE_DIR}/stdxaudio2.cpp) +ENDIF(WITH_PCH) INSTALL(TARGETS nel_drv_xaudio2 RUNTIME DESTINATION bin LIBRARY DESTINATION lib ARCHIVE DESTINATION lib COMPONENT driverssound) IF(WITH_MAXPLUGIN) diff --git a/code/nel/tools/3d/object_viewer_exe/CMakeLists.txt b/code/nel/tools/3d/object_viewer_exe/CMakeLists.txt index eec97c4c9..4f9c946f1 100644 --- a/code/nel/tools/3d/object_viewer_exe/CMakeLists.txt +++ b/code/nel/tools/3d/object_viewer_exe/CMakeLists.txt @@ -21,7 +21,9 @@ SET_TARGET_PROPERTIES(object_viewer PROPERTIES 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) +IF(WITH_PCH) + ADD_NATIVE_PRECOMPILED_HEADER(object_viewer ${CMAKE_CURRENT_SOURCE_DIR}/std_afx.h ${CMAKE_CURRENT_SOURCE_DIR}/std_afx.cpp) +ENDIF(WITH_PCH) INSTALL(TARGETS object_viewer RUNTIME DESTINATION bin COMPONENT tools3d) IF(WITH_MAXPLUGIN) diff --git a/code/ryzom/CMakeLists.txt b/code/ryzom/CMakeLists.txt index 09c4210ce..c6fc9e6e1 100644 --- a/code/ryzom/CMakeLists.txt +++ b/code/ryzom/CMakeLists.txt @@ -1,6 +1,6 @@ #----------------------------------------------------------------------------- # -# Ryzom +# Ryzom # Author: Spiderweb # # Notes: @@ -56,7 +56,7 @@ IF(COMMAND cmake_policy) # have absolute paths (e.g. -lpthreads) cmake_policy(SET CMP0003 NEW) - # Works around warnings about escaped quotes in ADD_DEFINITIONS + # Works around warnings about escaped quotes in ADD_DEFINITIONS # statements cmake_policy(SET CMP0005 OLD) ENDIF(COMMAND cmake_policy) @@ -108,6 +108,8 @@ INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/common ) NL_SETUP_BUILD_FLAGS() +INCLUDE(${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules/PCHSupport.cmake) + IF(FINAL_VERSION) ADD_DEFINITIONS(-DFINAL_VERSION=1) ENDIF(FINAL_VERSION) diff --git a/code/ryzom/CMakeModules/PCHSupport.cmake b/code/ryzom/CMakeModules/PCHSupport.cmake new file mode 100644 index 000000000..dcfcc753a --- /dev/null +++ b/code/ryzom/CMakeModules/PCHSupport.cmake @@ -0,0 +1,212 @@ +# - Try to find precompiled headers support for GCC 3.4 and 4.x (and MSVC) +# Once done this will define: +# +# Variable: +# PCHSupport_FOUND +# +# ADD_PRECOMPILED_HEADER _targetName _inputh _inputcpp +# ADD_PRECOMPILED_HEADER_TO_TARGET _targetName _input _pch_output_to_use +# ADD_NATIVE_PRECOMPILED_HEADER _targetName _inputh _inputcpp + +IF(CMAKE_COMPILER_IS_GNUCXX) + + EXEC_PROGRAM( + ${CMAKE_CXX_COMPILER} + ARGS ${CMAKE_CXX_COMPILER_ARG1} -dumpversion + OUTPUT_VARIABLE gcc_compiler_version) + + IF(gcc_compiler_version MATCHES "4\\.[0-9]\\.[0-9]") + SET(PCHSupport_FOUND TRUE) + ELSE(gcc_compiler_version MATCHES "4\\.[0-9]\\.[0-9]") + IF(gcc_compiler_version MATCHES "3\\.4\\.[0-9]") + SET(PCHSupport_FOUND TRUE) + ENDIF(gcc_compiler_version MATCHES "3\\.4\\.[0-9]") + ENDIF(gcc_compiler_version MATCHES "4\\.[0-9]\\.[0-9]") + + SET(_PCH_include_prefix "-I") + +ELSE(CMAKE_COMPILER_IS_GNUCXX) + + IF(WIN32) + SET(PCHSupport_FOUND TRUE) # for experimental msvc support + SET(_PCH_include_prefix "/I") + ELSE(WIN32) + SET(PCHSupport_FOUND FALSE) + ENDIF(WIN32) + +ENDIF(CMAKE_COMPILER_IS_GNUCXX) + +MACRO(_PCH_GET_COMPILE_FLAGS _out_compile_flags) + + STRING(TOUPPER "CMAKE_CXX_FLAGS_${CMAKE_BUILD_TYPE}" _flags_var_name) + SET(${_out_compile_flags} ${${_flags_var_name}} ) + + IF(CMAKE_COMPILER_IS_GNUCXX) + + GET_TARGET_PROPERTY(_targetType ${_PCH_current_target} TYPE) + IF(${_targetType} STREQUAL SHARED_LIBRARY AND NOT WIN32) + LIST(APPEND ${_out_compile_flags} "-fPIC") + ENDIF(${_targetType} STREQUAL SHARED_LIBRARY AND NOT WIN32) + + ELSE(CMAKE_COMPILER_IS_GNUCXX) + ## TODO ... ? or does it work out of the box + ENDIF(CMAKE_COMPILER_IS_GNUCXX) + + GET_DIRECTORY_PROPERTY(DIRINC INCLUDE_DIRECTORIES ) + FOREACH(item ${DIRINC}) + LIST(APPEND ${_out_compile_flags} "${_PCH_include_prefix}${item}") + ENDFOREACH(item) + + GET_DIRECTORY_PROPERTY(_directory_flags DEFINITIONS) + GET_DIRECTORY_PROPERTY(_global_definitions DIRECTORY ${CMAKE_SOURCE_DIR} DEFINITIONS) + LIST(APPEND ${_out_compile_flags} ${_directory_flags}) + LIST(APPEND ${_out_compile_flags} ${_global_definitions}) + LIST(APPEND ${_out_compile_flags} ${CMAKE_CXX_FLAGS}) + + SEPARATE_ARGUMENTS(${_out_compile_flags}) + +ENDMACRO(_PCH_GET_COMPILE_FLAGS) + +MACRO(_PCH_GET_COMPILE_COMMAND out_command _input _output) + + IF(CMAKE_COMPILER_IS_GNUCXX) + IF(CMAKE_CXX_COMPILER_ARG1) + # remove leading space in compiler argument + STRING(REGEX REPLACE "^ +" "" pchsupport_compiler_cxx_arg1 ${CMAKE_CXX_COMPILER_ARG1}) + + SET(${out_command} + ${CMAKE_CXX_COMPILER} ${pchsupport_compiler_cxx_arg1} ${_compile_FLAGS} -x c++-header -o ${_output} -c ${_input} + ) + ELSE(CMAKE_CXX_COMPILER_ARG1) + SET(${out_command} + ${CMAKE_CXX_COMPILER} ${_compile_FLAGS} -x c++-header -o ${_output} -c ${_input} + ) + ENDIF(CMAKE_CXX_COMPILER_ARG1) + ELSE(CMAKE_COMPILER_IS_GNUCXX) + + # nothing to do because std*.cpp are already added to target + + ENDIF(CMAKE_COMPILER_IS_GNUCXX) + +ENDMACRO(_PCH_GET_COMPILE_COMMAND ) + + + +MACRO(_PCH_GET_TARGET_COMPILE_FLAGS _cflags _header_name _pch_path) + + FILE(TO_NATIVE_PATH ${_pch_path} _native_pch_path) + + IF(CMAKE_COMPILER_IS_GNUCXX) + # for use with distcc and gcc >4.0.1 if preprocessed files are accessible + # on all remote machines set + # PCH_ADDITIONAL_COMPILER_FLAGS to -fpch-preprocess + SET(${_cflags} "${PCH_ADDITIONAL_COMPILER_FLAGS}-include ${CMAKE_CURRENT_BINARY_DIR}/${_header_name} -Winvalid-pch") + ENDIF(CMAKE_COMPILER_IS_GNUCXX) + +ENDMACRO(_PCH_GET_TARGET_COMPILE_FLAGS ) + +MACRO(GET_PRECOMPILED_HEADER_OUTPUT _targetName _input _output) + GET_FILENAME_COMPONENT(_name ${_input} NAME) + SET(_output "${CMAKE_CURRENT_BINARY_DIR}/${_name}.gch") +ENDMACRO(GET_PRECOMPILED_HEADER_OUTPUT _targetName _input) + + +MACRO(ADD_PRECOMPILED_HEADER_TO_TARGET _targetName _input _pch_output_to_use ) + + # to do: test whether compiler flags match between target _targetName + # and _pch_output_to_use + GET_FILENAME_COMPONENT(_name ${_input} NAME) + + _PCH_GET_TARGET_COMPILE_FLAGS(_target_cflags ${_name} ${_pch_output_to_use}) + + SET_TARGET_PROPERTIES(${_targetName} + PROPERTIES + COMPILE_FLAGS ${_target_cflags} + ) + + ADD_CUSTOM_TARGET(pch_Generate_${_targetName} + DEPENDS ${_pch_output_to_use} + ) + + ADD_DEPENDENCIES(${_targetName} pch_Generate_${_targetName} ) + +ENDMACRO(ADD_PRECOMPILED_HEADER_TO_TARGET) + +MACRO(ADD_PRECOMPILED_HEADER _targetName _inputh _inputcpp) + + 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) + + GET_PRECOMPILED_HEADER_OUTPUT( ${_targetName} ${_inputh} _output) + + 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}) + + _PCH_GET_COMPILE_FLAGS(_compile_FLAGS) + + SET_SOURCE_FILES_PROPERTIES(${_inputh} PROPERTIES GENERATED 1) + + _PCH_GET_COMPILE_COMMAND(_command ${_inputh} ${_output}) + + ADD_CUSTOM_COMMAND( + OUTPUT ${_output} + COMMAND ${_command} + DEPENDS ${_inputh} ${_targetName}_pch_dephelp + ) + + ADD_PRECOMPILED_HEADER_TO_TARGET(${_targetName} ${_inputh} ${_output}) + +ENDMACRO(ADD_PRECOMPILED_HEADER) + +MACRO(ADD_NATIVE_PRECOMPILED_HEADER _targetName _inputh _inputcpp) + + 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 + + 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}) + endif(CMAKE_GENERATOR MATCHES Xcode) + endif(CMAKE_GENERATOR MATCHES Visual*) + +ENDMACRO(ADD_NATIVE_PRECOMPILED_HEADER) diff --git a/code/ryzom/CMakeModules/nel.cmake b/code/ryzom/CMakeModules/nel.cmake index 85335132a..25ecef21e 100644 --- a/code/ryzom/CMakeModules/nel.cmake +++ b/code/ryzom/CMakeModules/nel.cmake @@ -33,6 +33,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 ) ### # Optional support @@ -48,12 +49,6 @@ MACRO(NL_SETUP_BUILD) #----------------------------------------------------------------------------- # Setup the buildmode variables. # - # None = NL_RELEASE_DEBUG - # Debug = NL_DEBUG - # Release = NL_RELEASE - # RelWithDebInfo = NL_RELEASE_DEBUG - # MinSizeRel = NL_RELEASE_DEBUG - # None = NL_RELEASE # Debug = NL_DEBUG # Release = NL_RELEASE, NL_NO_DEBUG diff --git a/code/ryzom/client/src/CMakeLists.txt b/code/ryzom/client/src/CMakeLists.txt index 0f0df597f..273b09022 100644 --- a/code/ryzom/client/src/CMakeLists.txt +++ b/code/ryzom/client/src/CMakeLists.txt @@ -95,4 +95,8 @@ ENDIF(NOT WITH_COCOA) ADD_DEFINITIONS(${LIBXML2_DEFINITIONS}) +IF(WITH_PCH) + ADD_NATIVE_PRECOMPILED_HEADER(ryzom_client ${CMAKE_CURRENT_SOURCE_DIR}/stdpch.h ${CMAKE_CURRENT_SOURCE_DIR}/stdpch.cpp) +ENDIF(WITH_PCH) + INSTALL(TARGETS ryzom_client RUNTIME DESTINATION bin COMPONENT client BUNDLE DESTINATION /Applications) diff --git a/code/ryzom/client/src/client_sheets/CMakeLists.txt b/code/ryzom/client/src/client_sheets/CMakeLists.txt index 4aa5fbc95..52648361b 100644 --- a/code/ryzom/client/src/client_sheets/CMakeLists.txt +++ b/code/ryzom/client/src/client_sheets/CMakeLists.txt @@ -17,8 +17,6 @@ SET_TARGET_PROPERTIES(ryzom_clientsheets PROPERTIES SOVERSION ${NL_VERSION_MAJOR}) IF(WIN32) - SET_TARGET_PROPERTIES(ryzom_clientsheets PROPERTIES COMPILE_FLAGS "/Yustdpch.h") - SET_SOURCE_FILES_PROPERTIES(stdpch.cpp PROPERTIES COMPILE_FLAGS "/Ycstdpch.h") SET_TARGET_PROPERTIES(ryzom_clientsheets PROJECT_LABEL "Library: Client Sheets" DEBUG_POSTFIX "_d" @@ -26,4 +24,8 @@ IF(WIN32) LINK_FLAGS_DEBUG "/NODEFAULTLIB:msvcrt") ENDIF(WIN32) +IF(WITH_PCH) + ADD_NATIVE_PRECOMPILED_HEADER(ryzom_clientsheets ${CMAKE_CURRENT_SOURCE_DIR}/stdpch.h ${CMAKE_CURRENT_SOURCE_DIR}/stdpch.cpp) +ENDIF(WITH_PCH) + INSTALL(TARGETS ryzom_clientsheets LIBRARY DESTINATION lib ARCHIVE DESTINATION lib COMPONENT libraries) diff --git a/code/ryzom/common/src/game_share/CMakeLists.txt b/code/ryzom/common/src/game_share/CMakeLists.txt index 816f00ab5..7c0f768ca 100644 --- a/code/ryzom/common/src/game_share/CMakeLists.txt +++ b/code/ryzom/common/src/game_share/CMakeLists.txt @@ -22,8 +22,6 @@ SET_TARGET_PROPERTIES(ryzom_gameshare PROPERTIES SOVERSION ${NL_VERSION_MAJOR}) IF(WIN32) -# SET_TARGET_PROPERTIES(${GAME_SHARE_LIB} PROPERTIES COMPILE_FLAGS "/Yustdgeorges.h") -# SET_SOURCE_FILES_PROPERTIES(stdgeorges.cpp PROPERTIES COMPILE_FLAGS "/Ycstdgeorges.h") SET_TARGET_PROPERTIES(ryzom_gameshare PROJECT_LABEL "Library: Game Share" DEBUG_POSTFIX "_d" @@ -33,5 +31,9 @@ ENDIF(WIN32) ADD_DEFINITIONS(${LIBXML2_DEFINITIONS}) +IF(WITH_PCH) + ADD_NATIVE_PRECOMPILED_HEADER(ryzom_gameshare ${CMAKE_CURRENT_SOURCE_DIR}/stdpch.h ${CMAKE_CURRENT_SOURCE_DIR}/stdpch.cpp) +ENDIF(WITH_PCH) + INSTALL(TARGETS ryzom_gameshare LIBRARY DESTINATION lib ARCHIVE DESTINATION lib COMPONENT libraries)