From 7ce279972e808988cc86ee4ed149ad6165bae3de Mon Sep 17 00:00:00 2001 From: kervala Date: Mon, 27 Sep 2010 23:25:40 +0200 Subject: [PATCH 1/5] Fixed: Use of CMAKE_CXX_COMPILER instead of CMAKE_MAKE_PROGRAM because Jom is not installed in VC++ directory --- code/CMakeLists.txt | 2 +- code/CMakeModules/FindCustomMFC.cmake | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/code/CMakeLists.txt b/code/CMakeLists.txt index c391946d7..4d8efb413 100644 --- a/code/CMakeLists.txt +++ b/code/CMakeLists.txt @@ -109,7 +109,7 @@ IF(WITH_STLPORT) IF(WIN32) FIND_PACKAGE(WindowsSDK REQUIRED) # convert IDE fullpath to include path - STRING(REGEX REPLACE "Common7/IDE/.+" "VC/include" VC_INCLUDE_DIR ${CMAKE_MAKE_PROGRAM}) + STRING(REGEX REPLACE "VC/bin/.+" "VC/include" VC_INCLUDE_DIR ${CMAKE_CXX_COMPILER}) # use VC++ and Windows SDK include paths INCLUDE_DIRECTORIES(${VC_INCLUDE_DIR} ${WINSDK_INCLUDE_DIR}) ENDIF(WIN32) diff --git a/code/CMakeModules/FindCustomMFC.cmake b/code/CMakeModules/FindCustomMFC.cmake index a8ae3e443..553f69b7c 100644 --- a/code/CMakeModules/FindCustomMFC.cmake +++ b/code/CMakeModules/FindCustomMFC.cmake @@ -11,7 +11,7 @@ SET(CUSTOM_MFC_DIR FALSE) # If using STLport and MFC have been found, remember its directory IF(WITH_STLPORT AND MFC_FOUND) - STRING(REGEX REPLACE "Common7/IDE/.+" "VC/atlmfc" MFC_STANDARD_DIR ${CMAKE_MAKE_PROGRAM}) + STRING(REGEX REPLACE "VC/bin/.+" "VC/atlmfc" VC_INCLUDE_DIR ${CMAKE_CXX_COMPILER}) ENDIF(WITH_STLPORT AND MFC_FOUND) # If using STLport or MFC haven't been found, search for afxwin.h From 326b7d79f3264a9846147076dc094878d77b86a3 Mon Sep 17 00:00:00 2001 From: kervala Date: Mon, 27 Sep 2010 23:33:26 +0200 Subject: [PATCH 2/5] Changed: Updated variables EXECUTABLE_OUTPUT_PATH and LIBRARY_OUTPUT_PATH (they are depreciated in CMake 2.6+) --- code/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/code/CMakeLists.txt b/code/CMakeLists.txt index 4d8efb413..ec8c53be8 100644 --- a/code/CMakeLists.txt +++ b/code/CMakeLists.txt @@ -53,8 +53,8 @@ SET(NL_VERSION "${NL_VERSION_MAJOR}.${NL_VERSION_MINOR}.${NL_VERSION_PATCH}") #----------------------------------------------------------------------------- # Redirect output files -SET(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin) -SET(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib) +SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) +SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) IF(WIN32) FIND_PACKAGE(External REQUIRED) From 73e5befa12e202d48d45767cedd13db663c773fc Mon Sep 17 00:00:00 2001 From: kervala Date: Mon, 27 Sep 2010 23:34:35 +0200 Subject: [PATCH 3/5] Fixed: PCHSupport.cmake to support Jom and Nmake --- code/CMakeModules/PCHSupport.cmake | 148 +++++++++++++++-------------- 1 file changed, 75 insertions(+), 73 deletions(-) diff --git a/code/CMakeModules/PCHSupport.cmake b/code/CMakeModules/PCHSupport.cmake index 351b3c4f4..5cebe1005 100644 --- a/code/CMakeModules/PCHSupport.cmake +++ b/code/CMakeModules/PCHSupport.cmake @@ -37,24 +37,21 @@ ELSE(CMAKE_COMPILER_IS_GNUCXX) 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) OR (${_targetType} STREQUAL MODULE_LIBRARY)) LIST(APPEND ${_out_compile_flags} "-fPIC") ENDIF((${_targetType} STREQUAL SHARED_LIBRARY) OR (${_targetType} STREQUAL MODULE_LIBRARY)) - 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}") + LIST(APPEND ${_out_compile_flags} " ${_PCH_include_prefix}\"${item}\"") ENDFOREACH(item) GET_DIRECTORY_PROPERTY(_directory_flags DEFINITIONS) @@ -64,72 +61,83 @@ MACRO(_PCH_GET_COMPILE_FLAGS _out_compile_flags) 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) +MACRO(_PCH_GET_PDB_FILENAME out_filename _target) + # determine output directory based on target type + GET_TARGET_PROPERTY(_targetType ${_target} TYPE) + IF(${_targetType} STREQUAL EXECUTABLE) + SET(_targetOutput ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}) + ELSE(${_targetType} STREQUAL EXECUTABLE) + SET(_targetOutput ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}) + ENDIF(${_targetType} STREQUAL EXECUTABLE) + + # determine target postfix + STRING(TOUPPER "${CMAKE_BUILD_TYPE}_POSTFIX" _postfix_var_name) + GET_TARGET_PROPERTY(_targetPostfix ${_target} ${_postfix_var_name}) + IF(${_targetPostfix} MATCHES NOTFOUND) + SET(_targetPostfix "") + ENDIF(${_targetPostfix} MATCHES NOTFOUND) + + SET(${out_filename} "${_targetOutput}/${_target}${_targetPostfix}.pdb") +ENDMACRO(_PCH_GET_PDB_FILENAME) + +MACRO(_PCH_GET_COMPILE_COMMAND out_command _input _inputcpp _output) + IF(CMAKE_CXX_COMPILER_ARG1) + # remove leading space in compiler argument + STRING(REGEX REPLACE "^ +" "" pchsupport_compiler_cxx_arg1 ${CMAKE_CXX_COMPILER_ARG1}) + ELSE(CMAKE_CXX_COMPILER_ARG1) + SET(pchsupport_compiler_cxx_arg1 "") + ENDIF(CMAKE_CXX_COMPILER_ARG1) 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) + SET(${out_command} + ${CMAKE_CXX_COMPILER} ${pchsupport_compiler_cxx_arg1} ${_compile_FLAGS} -x c++-header -o ${_output} -c ${_input} + ) ELSE(CMAKE_COMPILER_IS_GNUCXX) - - # nothing to do because std*.cpp are already added to target - + _PCH_GET_PDB_FILENAME(PDB_FILE ${_PCH_current_target}) + SET(${out_command} + ${CMAKE_CXX_COMPILER} ${pchsupport_compiler_cxx_arg1} ${_compile_FLAGS} /Yc /Fp\"${_output}\" ${_inputcpp} /c /Fd\"${PDB_FILE}\" + ) ENDIF(CMAKE_COMPILER_IS_GNUCXX) - ENDMACRO(_PCH_GET_COMPILE_COMMAND ) +MACRO(GET_PRECOMPILED_HEADER_OUTPUT _targetName _input _output) + IF(MSVC) + GET_FILENAME_COMPONENT(_name ${_input} NAME_WE) + SET(_output "${CMAKE_CURRENT_BINARY_DIR}/${_name}.pch") + ELSE(MSVC) + GET_FILENAME_COMPONENT(_name ${_input} NAME) + SET(_output "${CMAKE_CURRENT_BINARY_DIR}/${_name}.gch") + ENDIF(MSVC) +ENDMACRO(GET_PRECOMPILED_HEADER_OUTPUT _targetName _input) - -MACRO(_PCH_GET_TARGET_COMPILE_FLAGS _cflags _header_name _pch_path) - - FILE(TO_NATIVE_PATH ${_pch_path} _native_pch_path) - +MACRO(ADD_PRECOMPILED_HEADER_TO_TARGET _targetName _input _pch_output_to_use ) IF(CMAKE_COMPILER_IS_GNUCXX) + # to do: test whether compiler flags match between target _targetName + # and _pch_output_to_use + GET_FILENAME_COMPONENT(_name ${_input} NAME) + + FILE(TO_NATIVE_PATH ${_pch_output_to_use} _native_pch_path) + # 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") + SET(_target_cflags "${PCH_ADDITIONAL_COMPILER_FLAGS} -include ${CMAKE_CURRENT_BINARY_DIR}/${_input} -Winvalid-pch") + ELSE(MSVCCMAKE_COMPILER_IS_GNUCXX) + IF(MSVC) + GET_TARGET_PROPERTY(oldProps ${_targetName} COMPILE_FLAGS) + IF(${oldProps} MATCHES NOTFOUND) + SET(oldProps "") + ENDIF(${oldProps} MATCHES NOTFOUND) + + SET(_target_cflags "${oldProps} /Yu\"${_input}\" /FI\"${_input}\" /Fp\"${_pch_output_to_use}\"") + ENDIF(MSVC) 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} ) - + 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) @@ -154,7 +162,7 @@ MACRO(ADD_PRECOMPILED_HEADER _targetName _inputh _inputcpp) SET_SOURCE_FILES_PROPERTIES(${_inputh} PROPERTIES GENERATED 1) - _PCH_GET_COMPILE_COMMAND(_command ${_inputh} ${_output}) + _PCH_GET_COMPILE_COMMAND(_command ${_inputh} ${_inputcpp} ${_output}) ADD_CUSTOM_COMMAND( OUTPUT ${_output} @@ -162,38 +170,34 @@ MACRO(ADD_PRECOMPILED_HEADER _targetName _inputh _inputcpp) DEPENDS ${_inputh} ${_targetName}_pch_dephelp ) - ADD_PRECOMPILED_HEADER_TO_TARGET(${_targetName} ${_inputh} ${_output}) - + 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*) + 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) + IF(${oldProps} MATCHES NOTFOUND) SET(oldProps "") - endif(${oldProps} MATCHES NOTFOUND) + 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) + 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) + IF(${oldProps} MATCHES NOTFOUND) SET(oldProps "") - endif(${oldProps} MATCHES NOTFOUND) + ENDIF(${oldProps} MATCHES NOTFOUND) # When buiding out of the tree, precompiled may not be located # Use full path instead. @@ -201,12 +205,10 @@ MACRO(ADD_NATIVE_PRECOMPILED_HEADER _targetName _inputh _inputcpp) 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) - + 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(CMAKE_GENERATOR MATCHES Xcode) + ENDIF(CMAKE_GENERATOR MATCHES Visual*) ENDMACRO(ADD_NATIVE_PRECOMPILED_HEADER) From f88ded7ee0dec27c7fe5bec88622f5a631984277 Mon Sep 17 00:00:00 2001 From: kervala Date: Tue, 28 Sep 2010 00:03:11 +0200 Subject: [PATCH 4/5] Fixed: CMAKE_MAKE_PROGRAM or CMAKE_CXX_COMPILER can have relative path --- code/CMakeLists.txt | 11 +++++++++-- code/CMakeModules/FindCustomMFC.cmake | 6 +++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/code/CMakeLists.txt b/code/CMakeLists.txt index ec8c53be8..ac6a57a04 100644 --- a/code/CMakeLists.txt +++ b/code/CMakeLists.txt @@ -92,6 +92,15 @@ IF(WIN32) INCLUDE(${CMAKE_ROOT}/Modules/Platform/Windows-cl.cmake) SET(WINSOCK2_LIB ws2_32.lib) + IF(${CMAKE_MAKE_PROGRAM} MATCHES "Common7") + # convert IDE fullpath to VC++ path + STRING(REGEX REPLACE "Common7/IDE/.+" "VC" VC_DIR ${CMAKE_MAKE_PROGRAM}) + ELSE(${CMAKE_MAKE_PROGRAM} MATCHES "Common7") + # convert compiler fullpath to VC++ path + STRING(REGEX REPLACE "VC/bin/.+" "VC" VC_DIR ${CMAKE_CXX_COMPILER}) + ENDIF(${CMAKE_MAKE_PROGRAM} MATCHES "Common7") + SET(VC_INCLUDE_DIR "${VC_DIR}/include") + IF(WITH_MFC) FIND_PACKAGE(CustomMFC REQUIRED) ENDIF(WITH_MFC) @@ -108,8 +117,6 @@ IF(WITH_STLPORT) INCLUDE_DIRECTORIES(${STLPORT_INCLUDE_DIR}) IF(WIN32) FIND_PACKAGE(WindowsSDK REQUIRED) - # convert IDE fullpath to include path - STRING(REGEX REPLACE "VC/bin/.+" "VC/include" VC_INCLUDE_DIR ${CMAKE_CXX_COMPILER}) # use VC++ and Windows SDK include paths INCLUDE_DIRECTORIES(${VC_INCLUDE_DIR} ${WINSDK_INCLUDE_DIR}) ENDIF(WIN32) diff --git a/code/CMakeModules/FindCustomMFC.cmake b/code/CMakeModules/FindCustomMFC.cmake index 553f69b7c..b1b43864f 100644 --- a/code/CMakeModules/FindCustomMFC.cmake +++ b/code/CMakeModules/FindCustomMFC.cmake @@ -10,9 +10,9 @@ FIND_PACKAGE(MFC) SET(CUSTOM_MFC_DIR FALSE) # If using STLport and MFC have been found, remember its directory -IF(WITH_STLPORT AND MFC_FOUND) - STRING(REGEX REPLACE "VC/bin/.+" "VC/atlmfc" VC_INCLUDE_DIR ${CMAKE_CXX_COMPILER}) -ENDIF(WITH_STLPORT AND MFC_FOUND) +IF(WITH_STLPORT AND MFC_FOUND AND VC_DIR) + SET(MFC_STANDARD_DIR "${VC_DIR}/atlmfc") +ENDIF(WITH_STLPORT AND MFC_FOUND AND VC_DIR) # If using STLport or MFC haven't been found, search for afxwin.h IF(WITH_STLPORT OR NOT MFC_FOUND) From d15c631914b603be7d23cc9fcd7a53fdeaf05ff0 Mon Sep 17 00:00:00 2001 From: kervala Date: Tue, 28 Sep 2010 00:16:12 +0200 Subject: [PATCH 5/5] Fixed: Compilation with nmake and jom --- code/CMakeLists.txt | 2 ++ code/CMakeModules/FindExternal.cmake | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/code/CMakeLists.txt b/code/CMakeLists.txt index ac6a57a04..6fddf6951 100644 --- a/code/CMakeLists.txt +++ b/code/CMakeLists.txt @@ -55,6 +55,8 @@ SET(NL_VERSION "${NL_VERSION_MAJOR}.${NL_VERSION_MINOR}.${NL_VERSION_PATCH}") # Redirect output files SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) +SET(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin) +SET(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib) IF(WIN32) FIND_PACKAGE(External REQUIRED) diff --git a/code/CMakeModules/FindExternal.cmake b/code/CMakeModules/FindExternal.cmake index 506f69697..7e87fd98d 100644 --- a/code/CMakeModules/FindExternal.cmake +++ b/code/CMakeModules/FindExternal.cmake @@ -25,7 +25,8 @@ IF(EXTERNAL_PATH) SET(EXTERNAL_INCLUDE_PATH "${EXTERNAL_PATH}/include") IF(NOT CMAKE_SIZEOF_VOID_P) - MESSAGE(FATAL_ERROR "Size of void* is not set, you should call PROJECT(...) before") + INCLUDE (CheckTypeSize) + CHECK_TYPE_SIZE("void*" CMAKE_SIZEOF_VOID_P) ENDIF(NOT CMAKE_SIZEOF_VOID_P) # Using 32 or 64 bits libraries