2010-06-25 11:42:21 +00:00
|
|
|
# - Try to find precompiled headers support for GCC 3.4 and 4.x (and MSVC)
|
2010-06-25 06:33:15 +00:00
|
|
|
# Once done this will define:
|
|
|
|
#
|
|
|
|
# Variable:
|
|
|
|
# PCHSupport_FOUND
|
|
|
|
#
|
2010-06-27 10:19:53 +00:00
|
|
|
# ADD_PRECOMPILED_HEADER _targetName _inputh _inputcpp
|
|
|
|
# ADD_PRECOMPILED_HEADER_TO_TARGET _targetName _input _pch_output_to_use
|
|
|
|
# ADD_NATIVE_PRECOMPILED_HEADER _targetName _inputh _inputcpp
|
2010-06-25 06:33:15 +00:00
|
|
|
|
2012-03-09 08:31:13 +00:00
|
|
|
IF(MSVC)
|
2012-12-08 10:34:39 +00:00
|
|
|
SET(PCHSupport_FOUND TRUE)
|
2015-10-06 18:30:43 +00:00
|
|
|
ELSE()
|
2012-12-08 10:34:39 +00:00
|
|
|
IF(CMAKE_COMPILER_IS_GNUCXX)
|
|
|
|
EXEC_PROGRAM(${CMAKE_CXX_COMPILER}
|
|
|
|
ARGS ${CMAKE_CXX_COMPILER_ARG1} -dumpversion
|
|
|
|
OUTPUT_VARIABLE gcc_compiler_version)
|
|
|
|
|
2015-10-25 14:11:27 +00:00
|
|
|
IF(gcc_compiler_version VERSION_LESS "4.2")
|
2012-12-08 10:34:39 +00:00
|
|
|
SET(PCHSupport_FOUND FALSE)
|
2015-10-25 14:11:27 +00:00
|
|
|
ELSE()
|
2012-12-08 10:34:39 +00:00
|
|
|
SET(PCHSupport_FOUND TRUE)
|
2015-10-06 18:30:43 +00:00
|
|
|
ENDIF()
|
|
|
|
ELSE()
|
2012-12-08 10:34:39 +00:00
|
|
|
# TODO: make tests for other compilers than GCC
|
|
|
|
SET(PCHSupport_FOUND TRUE)
|
2015-10-06 18:30:43 +00:00
|
|
|
ENDIF()
|
|
|
|
ENDIF()
|
2010-06-25 06:33:15 +00:00
|
|
|
|
2012-12-08 10:34:39 +00:00
|
|
|
# Set PCH_FLAGS for common flags, PCH_ARCH_XXX_FLAGS for specific archs flags and PCH_ARCHS for archs
|
|
|
|
MACRO(PCH_SET_COMPILE_FLAGS _target)
|
|
|
|
SET(PCH_FLAGS)
|
2013-08-05 08:32:17 +00:00
|
|
|
SET(PCH_ARCHS)
|
|
|
|
|
2013-07-24 21:57:52 +00:00
|
|
|
SET(_FLAGS)
|
2012-12-08 10:34:39 +00:00
|
|
|
LIST(APPEND _FLAGS ${CMAKE_CXX_FLAGS})
|
|
|
|
|
|
|
|
STRING(TOUPPER "${CMAKE_BUILD_TYPE}" _UPPER_BUILD)
|
|
|
|
LIST(APPEND _FLAGS " ${CMAKE_CXX_FLAGS_${_UPPER_BUILD}}")
|
|
|
|
|
2013-09-06 06:43:44 +00:00
|
|
|
GET_TARGET_PROPERTY(_targetType ${_target} TYPE)
|
2013-08-05 08:32:17 +00:00
|
|
|
|
2015-12-25 17:00:37 +00:00
|
|
|
SET(_USE_PIC OFF)
|
2015-12-15 12:41:07 +00:00
|
|
|
|
2015-10-06 18:31:41 +00:00
|
|
|
IF(${_targetType} STREQUAL "SHARED_LIBRARY" OR ${_targetType} STREQUAL "MODULE_LIBRARY")
|
2013-09-06 06:43:44 +00:00
|
|
|
LIST(APPEND _FLAGS " ${CMAKE_SHARED_LIBRARY_CXX_FLAGS}")
|
2015-10-06 18:30:43 +00:00
|
|
|
ELSE()
|
2013-08-05 08:32:17 +00:00
|
|
|
GET_TARGET_PROPERTY(_pic ${_target} POSITION_INDEPENDENT_CODE)
|
|
|
|
IF(_pic)
|
2015-12-25 17:00:37 +00:00
|
|
|
SET(_USE_PIC ON)
|
2015-10-06 18:30:43 +00:00
|
|
|
ENDIF()
|
|
|
|
ENDIF()
|
2012-12-08 10:34:39 +00:00
|
|
|
|
|
|
|
GET_DIRECTORY_PROPERTY(DIRINC INCLUDE_DIRECTORIES)
|
|
|
|
FOREACH(item ${DIRINC})
|
2013-08-05 08:32:17 +00:00
|
|
|
LIST(APPEND _FLAGS " -I\"${item}\"")
|
2015-10-06 18:30:43 +00:00
|
|
|
ENDFOREACH()
|
2012-12-08 10:34:39 +00:00
|
|
|
|
|
|
|
# Required for CMake 2.6
|
|
|
|
SET(GLOBAL_DEFINITIONS)
|
|
|
|
GET_DIRECTORY_PROPERTY(DEFINITIONS COMPILE_DEFINITIONS)
|
2013-08-05 08:32:17 +00:00
|
|
|
IF(DEFINITIONS)
|
|
|
|
FOREACH(item ${DEFINITIONS})
|
|
|
|
LIST(APPEND GLOBAL_DEFINITIONS " -D${item}")
|
2015-10-06 18:30:43 +00:00
|
|
|
ENDFOREACH()
|
|
|
|
ENDIF()
|
2012-12-08 10:34:39 +00:00
|
|
|
|
|
|
|
GET_DIRECTORY_PROPERTY(DEFINITIONS COMPILE_DEFINITIONS_${_UPPER_BUILD})
|
2013-08-05 08:32:17 +00:00
|
|
|
IF(DEFINITIONS)
|
|
|
|
FOREACH(item ${DEFINITIONS})
|
|
|
|
LIST(APPEND GLOBAL_DEFINITIONS " -D${item}")
|
2015-10-06 18:30:43 +00:00
|
|
|
ENDFOREACH()
|
|
|
|
ENDIF()
|
2012-12-08 10:34:39 +00:00
|
|
|
|
2015-12-15 12:41:07 +00:00
|
|
|
GET_DIRECTORY_PROPERTY(DEFINITIONS DIRECTORY ${CMAKE_SOURCE_DIR} COMPILE_DEFINITIONS)
|
|
|
|
IF(DEFINITIONS)
|
|
|
|
FOREACH(item ${DEFINITIONS})
|
|
|
|
LIST(APPEND GLOBAL_DEFINITIONS " -D${item}")
|
|
|
|
ENDFOREACH()
|
|
|
|
ENDIF()
|
|
|
|
|
|
|
|
GET_DIRECTORY_PROPERTY(DEFINITIONS DIRECTORY ${CMAKE_SOURCE_DIR} COMPILE_DEFINITIONS_${_UPPER_BUILD})
|
|
|
|
IF(DEFINITIONS)
|
|
|
|
FOREACH(item ${DEFINITIONS})
|
|
|
|
LIST(APPEND GLOBAL_DEFINITIONS " -D${item}")
|
|
|
|
ENDFOREACH()
|
|
|
|
ENDIF()
|
|
|
|
|
2012-12-08 10:34:39 +00:00
|
|
|
GET_TARGET_PROPERTY(oldProps ${_target} COMPILE_FLAGS)
|
|
|
|
IF(oldProps)
|
|
|
|
LIST(APPEND _FLAGS " ${oldProps}")
|
2015-10-06 18:30:43 +00:00
|
|
|
ENDIF()
|
2012-12-08 10:34:39 +00:00
|
|
|
|
|
|
|
GET_TARGET_PROPERTY(oldPropsBuild ${_target} COMPILE_FLAGS_${_UPPER_BUILD})
|
|
|
|
IF(oldPropsBuild)
|
|
|
|
LIST(APPEND _FLAGS " ${oldPropsBuild}")
|
2015-10-06 18:30:43 +00:00
|
|
|
ENDIF()
|
2012-12-08 10:34:39 +00:00
|
|
|
|
2013-08-05 08:32:17 +00:00
|
|
|
GET_TARGET_PROPERTY(DIRINC ${_target} INCLUDE_DIRECTORIES)
|
|
|
|
IF(DIRINC)
|
|
|
|
FOREACH(item ${DIRINC})
|
|
|
|
LIST(APPEND _FLAGS " -I\"${item}\"")
|
2015-10-06 18:30:43 +00:00
|
|
|
ENDFOREACH()
|
|
|
|
ENDIF()
|
2013-08-05 08:32:17 +00:00
|
|
|
|
|
|
|
GET_TARGET_PROPERTY(DEFINITIONS ${_target} COMPILE_DEFINITIONS)
|
|
|
|
IF(DEFINITIONS)
|
|
|
|
FOREACH(item ${DEFINITIONS})
|
|
|
|
LIST(APPEND GLOBAL_DEFINITIONS " -D${item}")
|
2015-10-06 18:30:43 +00:00
|
|
|
ENDFOREACH()
|
|
|
|
ENDIF()
|
2013-08-05 08:32:17 +00:00
|
|
|
|
|
|
|
GET_TARGET_PROPERTY(DEFINITIONS ${_target} COMPILE_DEFINITIONS_${_UPPER_BUILD})
|
|
|
|
IF(DEFINITIONS)
|
|
|
|
FOREACH(item ${DEFINITIONS})
|
|
|
|
LIST(APPEND GLOBAL_DEFINITIONS " -D${item}")
|
2015-10-06 18:30:43 +00:00
|
|
|
ENDFOREACH()
|
|
|
|
ENDIF()
|
2013-08-05 08:32:17 +00:00
|
|
|
|
2015-12-15 12:41:07 +00:00
|
|
|
GET_TARGET_PROPERTY(_LIBS ${_target} INTERFACE_LINK_LIBRARIES)
|
|
|
|
IF(_LIBS)
|
|
|
|
FOREACH(_LIB ${_LIBS})
|
|
|
|
IF(TARGET "${_LIB}")
|
|
|
|
# use same include directories
|
|
|
|
GET_TARGET_PROPERTY(_DIRS ${_LIB} INTERFACE_INCLUDE_DIRECTORIES)
|
|
|
|
|
|
|
|
IF(_DIRS)
|
|
|
|
FOREACH(item ${_DIRS})
|
|
|
|
LIST(APPEND GLOBAL_DEFINITIONS " -I\"${item}\"")
|
|
|
|
ENDFOREACH()
|
|
|
|
ENDIF()
|
|
|
|
|
|
|
|
# use same compile definitions
|
|
|
|
GET_TARGET_PROPERTY(_DEFINITIONS ${_LIB} INTERFACE_COMPILE_DEFINITIONS)
|
|
|
|
|
|
|
|
IF(_DEFINITIONS)
|
|
|
|
FOREACH(item ${_DEFINITIONS})
|
|
|
|
# don't use dynamic expressions
|
|
|
|
IF(NOT item MATCHES "\\$<")
|
|
|
|
LIST(APPEND GLOBAL_DEFINITIONS " -D${item}")
|
|
|
|
ENDIF()
|
|
|
|
ENDFOREACH()
|
|
|
|
ENDIF()
|
|
|
|
ENDIF()
|
|
|
|
ENDFOREACH()
|
|
|
|
ENDIF()
|
|
|
|
|
2015-12-25 14:31:34 +00:00
|
|
|
# Special Qt 5 cases
|
|
|
|
IF(GLOBAL_DEFINITIONS MATCHES "QT_CORE_LIB")
|
|
|
|
# Hack to define missing QT_NO_DEBUG with Qt 5.2
|
|
|
|
IF(_UPPER_BUILD STREQUAL "RELEASE")
|
|
|
|
LIST(APPEND GLOBAL_DEFINITIONS " -DQT_NO_DEBUG")
|
|
|
|
ENDIF()
|
2015-12-15 12:41:07 +00:00
|
|
|
|
2015-12-25 17:00:37 +00:00
|
|
|
# Qt5_POSITION_INDEPENDENT_CODE should be true if Qt was compiled with PIC
|
2015-12-25 14:31:34 +00:00
|
|
|
IF(Qt5_POSITION_INDEPENDENT_CODE)
|
2015-12-25 17:00:37 +00:00
|
|
|
SET(_USE_PIC ON)
|
2015-12-25 14:31:34 +00:00
|
|
|
ENDIF()
|
2015-12-15 12:41:07 +00:00
|
|
|
|
2015-12-25 17:00:37 +00:00
|
|
|
IF(_USE_PIC)
|
2015-12-25 14:31:34 +00:00
|
|
|
LIST(APPEND _FLAGS " ${CMAKE_CXX_COMPILE_OPTIONS_PIC}")
|
|
|
|
ENDIF()
|
2015-12-15 12:41:07 +00:00
|
|
|
ENDIF()
|
|
|
|
|
2012-12-08 10:34:39 +00:00
|
|
|
LIST(APPEND _FLAGS " ${GLOBAL_DEFINITIONS}")
|
2015-12-07 12:08:27 +00:00
|
|
|
|
2015-10-06 18:31:41 +00:00
|
|
|
IF(CMAKE_VERSION VERSION_LESS "3.3.0")
|
|
|
|
GET_DIRECTORY_PROPERTY(_directory_flags DEFINITIONS)
|
|
|
|
GET_DIRECTORY_PROPERTY(_directory_definitions DIRECTORY ${CMAKE_SOURCE_DIR} DEFINITIONS)
|
|
|
|
LIST(APPEND _FLAGS " ${_directory_flags}")
|
|
|
|
LIST(APPEND _FLAGS " ${_directory_definitions}")
|
|
|
|
ENDIF()
|
2012-12-08 10:34:39 +00:00
|
|
|
|
|
|
|
# Format definitions
|
2013-07-24 20:53:33 +00:00
|
|
|
IF(MSVC)
|
|
|
|
# Fix path with space
|
|
|
|
SEPARATE_ARGUMENTS(_FLAGS UNIX_COMMAND "${_FLAGS}")
|
2015-10-06 18:30:43 +00:00
|
|
|
ELSE()
|
2013-07-24 20:53:33 +00:00
|
|
|
STRING(REGEX REPLACE " +" " " _FLAGS ${_FLAGS})
|
|
|
|
SEPARATE_ARGUMENTS(_FLAGS)
|
2015-10-06 18:30:43 +00:00
|
|
|
ENDIF()
|
2013-07-24 20:53:33 +00:00
|
|
|
|
2012-12-08 10:34:39 +00:00
|
|
|
IF(CLANG)
|
|
|
|
# Determining all architectures and get common flags
|
|
|
|
SET(_ARCH_NEXT)
|
|
|
|
SET(_XARCH_NEXT)
|
|
|
|
FOREACH(item ${_FLAGS})
|
|
|
|
IF(_ARCH_NEXT)
|
|
|
|
LIST(FIND PCH_ARCHS ${item} ITEM_FOUND)
|
|
|
|
IF(ITEM_FOUND EQUAL -1)
|
|
|
|
LIST(APPEND PCH_ARCHS ${item})
|
|
|
|
STRING(TOUPPER "${item}" _UPPER_ARCH)
|
|
|
|
SET(PCH_ARCH_${_UPPER_ARCH}_FLAGS "-arch" ${item})
|
2015-10-06 18:30:43 +00:00
|
|
|
ENDIF()
|
2012-12-08 10:34:39 +00:00
|
|
|
SET(_ARCH_NEXT OFF)
|
|
|
|
ELSEIF(_XARCH_NEXT)
|
|
|
|
SET(_XARCH_NEXT OFF)
|
2015-10-06 18:30:43 +00:00
|
|
|
ELSE()
|
2012-12-08 10:34:39 +00:00
|
|
|
IF(item MATCHES "^-arch")
|
|
|
|
SET(_ARCH_NEXT ON)
|
|
|
|
ELSEIF(item MATCHES "^-Xarch_")
|
|
|
|
STRING(REGEX REPLACE "-Xarch_([a-z0-9_]+)" "\\1" item ${item})
|
|
|
|
LIST(FIND PCH_ARCHS ${item} ITEM_FOUND)
|
|
|
|
IF(ITEM_FOUND EQUAL -1)
|
|
|
|
LIST(APPEND PCH_ARCHS ${item})
|
|
|
|
STRING(TOUPPER "${item}" _UPPER_ARCH)
|
|
|
|
SET(PCH_ARCH_${_UPPER_ARCH}_FLAGS "-arch" ${item})
|
2015-10-06 18:30:43 +00:00
|
|
|
ENDIF()
|
2012-12-08 10:34:39 +00:00
|
|
|
SET(_XARCH_NEXT ON)
|
2015-10-06 18:30:43 +00:00
|
|
|
ELSE()
|
2012-12-08 10:34:39 +00:00
|
|
|
LIST(APPEND PCH_FLAGS ${item})
|
2015-10-06 18:30:43 +00:00
|
|
|
ENDIF()
|
|
|
|
ENDIF()
|
|
|
|
ENDFOREACH()
|
2012-12-08 10:34:39 +00:00
|
|
|
|
|
|
|
# Get architcture specific flags
|
|
|
|
SET(_XARCH_NEXT)
|
|
|
|
FOREACH(item ${_FLAGS})
|
|
|
|
IF(_XARCH_NEXT)
|
|
|
|
STRING(TOUPPER "${_XARCH_NEXT}" _UPPER_XARCH)
|
|
|
|
LIST(APPEND PCH_ARCH_${_UPPER_XARCH}_FLAGS ${item})
|
|
|
|
SET(_XARCH_NEXT OFF)
|
2015-10-06 18:30:43 +00:00
|
|
|
ELSE()
|
2012-12-08 10:34:39 +00:00
|
|
|
IF(item MATCHES "^-Xarch_")
|
|
|
|
STRING(SUBSTRING "${item}" 7 -1 _XARCH_NEXT)
|
2015-10-06 18:30:43 +00:00
|
|
|
ENDIF()
|
|
|
|
ENDIF()
|
|
|
|
ENDFOREACH()
|
2012-12-08 10:34:39 +00:00
|
|
|
|
|
|
|
# Remove duplicated architectures
|
|
|
|
IF(_ARCHS AND PCH_ARCHS)
|
|
|
|
LIST(REMOVE_DUPLICATES PCH_ARCHS)
|
2015-10-06 18:30:43 +00:00
|
|
|
ENDIF()
|
|
|
|
ELSE()
|
2012-12-08 10:34:39 +00:00
|
|
|
SET(PCH_FLAGS ${_FLAGS})
|
2015-10-06 18:30:43 +00:00
|
|
|
ENDIF()
|
2012-12-08 10:34:39 +00:00
|
|
|
|
|
|
|
IF(PCH_FLAGS)
|
|
|
|
LIST(REMOVE_DUPLICATES PCH_FLAGS)
|
2015-10-06 18:30:43 +00:00
|
|
|
ENDIF()
|
|
|
|
ENDMACRO()
|
2012-12-08 10:34:39 +00:00
|
|
|
|
|
|
|
MACRO(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})
|
|
|
|
ELSEIF(${_targetType} STREQUAL STATIC_LIBRARY)
|
|
|
|
SET(_targetOutput ${CMAKE_ARCHIVE_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(GET_PDB_FILENAME)
|
|
|
|
|
|
|
|
MACRO(PCH_SET_COMPILE_COMMAND _inputcpp _compile_FLAGS)
|
|
|
|
IF(CMAKE_CXX_COMPILER_ARG1)
|
|
|
|
# remove leading space in compiler argument
|
|
|
|
STRING(REGEX REPLACE "^ +" "" pchsupport_compiler_cxx_arg1 ${CMAKE_CXX_COMPILER_ARG1})
|
2015-10-06 18:30:43 +00:00
|
|
|
ELSE()
|
2012-12-08 10:34:39 +00:00
|
|
|
SET(pchsupport_compiler_cxx_arg1 "")
|
2015-10-06 18:30:43 +00:00
|
|
|
ENDIF()
|
2012-12-08 10:34:39 +00:00
|
|
|
|
|
|
|
IF(MSVC)
|
|
|
|
GET_PDB_FILENAME(PDB_FILE ${_PCH_current_target})
|
|
|
|
SET(PCH_COMMAND ${CMAKE_CXX_COMPILER} ${pchsupport_compiler_cxx_arg1} ${_compile_FLAGS} /Yc /Fp"${PCH_OUTPUT}" ${_inputcpp} /Fd"${PDB_FILE}" /c /Fo"${PCH_OUTPUT}.obj")
|
2013-09-05 15:18:01 +00:00
|
|
|
# Ninja PCH Support
|
|
|
|
# http://public.kitware.com/pipermail/cmake-developers/2012-March/003653.html
|
|
|
|
SET_SOURCE_FILES_PROPERTIES(${_inputcpp} PROPERTIES OBJECT_OUTPUTS "${PCH_OUTPUT}.obj")
|
2015-10-06 18:30:43 +00:00
|
|
|
ELSE()
|
2012-12-08 10:34:39 +00:00
|
|
|
SET(HEADER_FORMAT "c++-header")
|
|
|
|
SET(_FLAGS "")
|
|
|
|
IF(APPLE)
|
|
|
|
SET(HEADER_FORMAT "objective-${HEADER_FORMAT}")
|
|
|
|
SET(_FLAGS -fobjc-abi-version=2 -fobjc-legacy-dispatch)
|
2015-10-06 18:30:43 +00:00
|
|
|
ENDIF()
|
2012-12-08 10:34:39 +00:00
|
|
|
SET(PCH_COMMAND ${CMAKE_CXX_COMPILER} ${pchsupport_compiler_cxx_arg1} ${_compile_FLAGS} ${_FLAGS} -x ${HEADER_FORMAT} -o ${PCH_OUTPUT} -c ${PCH_INPUT})
|
2015-10-06 18:30:43 +00:00
|
|
|
ENDIF()
|
|
|
|
ENDMACRO()
|
2012-12-08 10:34:39 +00:00
|
|
|
|
|
|
|
MACRO(PCH_SET_PRECOMPILED_HEADER_OUTPUT _targetName _input _arch _language)
|
|
|
|
SET(_OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/${_targetName}_pch")
|
|
|
|
|
|
|
|
IF(MSVC)
|
|
|
|
FILE(MAKE_DIRECTORY ${_OUTPUT_DIR})
|
|
|
|
GET_FILENAME_COMPONENT(_name ${_input} NAME_WE)
|
|
|
|
SET(PCH_INPUT ${_input})
|
|
|
|
SET(PCH_OUTPUT "${_OUTPUT_DIR}/${_name}.pch")
|
2015-10-06 18:30:43 +00:00
|
|
|
ELSE()
|
2012-12-08 10:34:39 +00:00
|
|
|
IF(NOT "${_arch}" STREQUAL "")
|
|
|
|
SET(_OUTPUT_DIR "${_OUTPUT_DIR}_${_arch}")
|
2015-10-06 18:30:43 +00:00
|
|
|
ENDIF()
|
2012-12-08 10:34:39 +00:00
|
|
|
|
|
|
|
IF(NOT "${_language}" STREQUAL "")
|
|
|
|
SET(_OUTPUT_DIR "${_OUTPUT_DIR}_${_language}")
|
2015-10-06 18:30:43 +00:00
|
|
|
ENDIF()
|
2012-12-08 10:34:39 +00:00
|
|
|
|
|
|
|
GET_FILENAME_COMPONENT(_name ${_input} NAME)
|
|
|
|
|
|
|
|
# Copy .h to output dir
|
|
|
|
SET(PCH_INPUT "${_OUTPUT_DIR}/${_name}")
|
|
|
|
ADD_CUSTOM_COMMAND(OUTPUT ${PCH_INPUT}
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${_input} ${PCH_INPUT}
|
|
|
|
DEPENDS ${_input}
|
|
|
|
COMMENT "[${_targetName}] Update precompiled header - done"
|
|
|
|
)
|
|
|
|
|
|
|
|
IF(CLANG)
|
|
|
|
SET(PCH_EXT "pth")
|
2015-10-06 18:30:43 +00:00
|
|
|
ELSE()
|
2012-12-08 10:34:39 +00:00
|
|
|
SET(PCH_EXT "gch")
|
2015-10-06 18:30:43 +00:00
|
|
|
ENDIF()
|
2012-12-08 10:34:39 +00:00
|
|
|
|
|
|
|
# For GCC and Clang, PCH needs to be in the same directory as .h
|
|
|
|
SET(PCH_OUTPUT "${_OUTPUT_DIR}/${_name}.${PCH_EXT}")
|
2015-10-06 18:30:43 +00:00
|
|
|
ENDIF()
|
|
|
|
ENDMACRO()
|
2012-12-08 10:34:39 +00:00
|
|
|
|
|
|
|
# Add common flags
|
|
|
|
MACRO(ADD_PRECOMPILED_HEADER_TO_TARGET _targetName)
|
|
|
|
GET_TARGET_PROPERTY(oldProps ${_targetName} COMPILE_FLAGS)
|
|
|
|
|
|
|
|
IF(${oldProps} MATCHES NOTFOUND)
|
|
|
|
SET(oldProps "")
|
2015-10-06 18:30:43 +00:00
|
|
|
ENDIF()
|
2012-12-08 10:34:39 +00:00
|
|
|
|
|
|
|
IF(MSVC)
|
|
|
|
SET(_target_cflags "${oldProps} /Yu\"${PCH_INPUT}\" /FI\"${PCH_INPUT}\" /Fp\"${PCH_OUTPUT}\"")
|
2013-09-05 15:18:01 +00:00
|
|
|
# Ninja PCH Support
|
|
|
|
# http://public.kitware.com/pipermail/cmake-developers/2012-March/003653.html
|
|
|
|
SET_TARGET_PROPERTIES(${_targetName} PROPERTIES OBJECT_DEPENDS "${PCH_OUTPUT}")
|
2013-09-26 20:50:13 +00:00
|
|
|
|
2013-09-05 15:18:01 +00:00
|
|
|
# NMAKE-VS2012 Error LNK2011 (NMAKE-VS2010 do not complain)
|
|
|
|
# we need to link the pch.obj file, see http://msdn.microsoft.com/en-us/library/3ay26wa2(v=vs.110).aspx
|
2013-09-26 20:50:13 +00:00
|
|
|
GET_TARGET_PROPERTY(_STATIC_LIBRARY_FLAGS ${_targetName} STATIC_LIBRARY_FLAGS)
|
|
|
|
IF(NOT _STATIC_LIBRARY_FLAGS)
|
|
|
|
SET(_STATIC_LIBRARY_FLAGS)
|
2015-10-06 18:30:43 +00:00
|
|
|
ENDIF()
|
2013-09-26 20:50:13 +00:00
|
|
|
SET(_STATIC_LIBRARY_FLAGS "${PCH_OUTPUT}.obj ${_STATIC_LIBRARY_FLAGS}")
|
|
|
|
|
|
|
|
GET_TARGET_PROPERTY(_LINK_FLAGS ${_targetName} LINK_FLAGS)
|
|
|
|
IF(NOT _LINK_FLAGS)
|
|
|
|
SET(_LINK_FLAGS)
|
2015-10-06 18:30:43 +00:00
|
|
|
ENDIF()
|
2013-09-26 20:50:13 +00:00
|
|
|
SET(_LINK_FLAGS "${PCH_OUTPUT}.obj ${_LINK_FLAGS}")
|
|
|
|
|
|
|
|
SET_TARGET_PROPERTIES(${_targetName} PROPERTIES STATIC_LIBRARY_FLAGS ${_STATIC_LIBRARY_FLAGS} LINK_FLAGS ${_LINK_FLAGS})
|
2015-10-06 18:30:43 +00:00
|
|
|
ELSE()
|
2012-12-08 10:34:39 +00:00
|
|
|
# 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(PCH_ADDITIONAL_COMPILER_FLAGS)
|
|
|
|
LIST(LENGTH PCH_ARCHS PCH_ARCHS_COUNT)
|
|
|
|
|
|
|
|
# If no arch is specified, create common flags
|
|
|
|
IF(PCH_ARCHS_COUNT LESS 2)
|
|
|
|
SET(PCH_ADDITIONAL_COMPILER_FLAGS "-include ${PCH_INPUT} ${PCH_ADDITIONAL_COMPILER_FLAGS}")
|
2015-10-06 18:30:43 +00:00
|
|
|
ENDIF()
|
2012-12-08 10:34:39 +00:00
|
|
|
|
|
|
|
IF(APPLE)
|
|
|
|
SET(PCH_ADDITIONAL_COMPILER_FLAGS "-fobjc-abi-version=2 -fobjc-legacy-dispatch -x objective-c++ ${PCH_ADDITIONAL_COMPILER_FLAGS}")
|
2015-10-06 18:30:43 +00:00
|
|
|
ENDIF()
|
2015-12-07 12:08:27 +00:00
|
|
|
|
2012-12-08 10:34:39 +00:00
|
|
|
IF(WITH_PCH_DEBUG)
|
|
|
|
SET(PCH_ADDITIONAL_COMPILER_FLAGS "-H ${PCH_ADDITIONAL_COMPILER_FLAGS}")
|
2015-10-06 18:30:43 +00:00
|
|
|
ENDIF()
|
2012-12-08 10:34:39 +00:00
|
|
|
|
|
|
|
SET(_target_cflags "${oldProps} ${PCH_ADDITIONAL_COMPILER_FLAGS} -Winvalid-pch")
|
2015-10-06 18:30:43 +00:00
|
|
|
ENDIF()
|
2012-12-08 10:34:39 +00:00
|
|
|
|
|
|
|
SET_TARGET_PROPERTIES(${_targetName} PROPERTIES COMPILE_FLAGS ${_target_cflags})
|
2015-10-06 18:30:43 +00:00
|
|
|
ENDMACRO()
|
2010-06-25 06:33:15 +00:00
|
|
|
|
2012-12-08 10:34:39 +00:00
|
|
|
# Add specific flags for an arch
|
|
|
|
MACRO(ADD_PRECOMPILED_HEADER_TO_TARGET_ARCH _targetName _arch)
|
|
|
|
LIST(LENGTH PCH_ARCHS PCH_ARCHS_COUNT)
|
|
|
|
|
|
|
|
IF(PCH_ARCHS_COUNT GREATER 1)
|
|
|
|
GET_TARGET_PROPERTY(_FLAGS ${_targetName} COMPILE_FLAGS)
|
|
|
|
|
|
|
|
IF(${_FLAGS} MATCHES NOTFOUND)
|
|
|
|
SET(_FLAGS "")
|
2015-10-06 18:30:43 +00:00
|
|
|
ENDIF()
|
2012-12-08 10:34:39 +00:00
|
|
|
|
|
|
|
SET(_FLAGS "${_FLAGS} -Xarch_${_arch} -include${PCH_INPUT}")
|
2010-06-25 06:33:15 +00:00
|
|
|
|
2012-12-08 10:34:39 +00:00
|
|
|
SET_TARGET_PROPERTIES(${_targetName} PROPERTIES COMPILE_FLAGS ${_FLAGS})
|
2015-10-06 18:30:43 +00:00
|
|
|
ENDIF()
|
|
|
|
ENDMACRO()
|
2010-06-25 11:42:21 +00:00
|
|
|
|
2012-12-08 10:34:39 +00:00
|
|
|
MACRO(PCH_CREATE_TARGET _targetName _targetNamePCH)
|
|
|
|
ADD_CUSTOM_COMMAND(OUTPUT ${PCH_OUTPUT} COMMAND ${PCH_COMMAND} COMMENT "Generating ${_targetNamePCH}" DEPENDS ${PCH_INPUT})
|
|
|
|
ADD_CUSTOM_TARGET(${_targetNamePCH} DEPENDS ${PCH_INPUT} ${PCH_OUTPUT})
|
|
|
|
ADD_DEPENDENCIES(${_targetName} ${_targetNamePCH})
|
2015-10-06 18:30:43 +00:00
|
|
|
ENDMACRO()
|
2010-06-25 06:33:15 +00:00
|
|
|
|
2012-12-08 10:34:39 +00:00
|
|
|
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!"
|
|
|
|
)
|
2015-10-06 18:30:43 +00:00
|
|
|
ENDIF()
|
2010-06-25 06:33:15 +00:00
|
|
|
|
2012-12-08 10:34:39 +00:00
|
|
|
PCH_SET_COMPILE_FLAGS(${_targetName})
|
2010-06-25 06:33:15 +00:00
|
|
|
|
2012-12-08 10:34:39 +00:00
|
|
|
IF(PCH_ARCHS)
|
|
|
|
SET(PCH_OUTPUTS)
|
|
|
|
FOREACH(_ARCH ${PCH_ARCHS})
|
|
|
|
STRING(TOUPPER "${_ARCH}" _UPPER_ARCH)
|
2010-06-25 06:33:15 +00:00
|
|
|
|
2012-12-08 10:34:39 +00:00
|
|
|
PCH_SET_PRECOMPILED_HEADER_OUTPUT(${_targetName} ${_inputh} ${_ARCH} "")
|
|
|
|
LIST(APPEND PCH_OUTPUTS ${PCH_OUTPUT})
|
2010-06-25 11:42:21 +00:00
|
|
|
|
2012-12-08 10:34:39 +00:00
|
|
|
PCH_SET_COMPILE_COMMAND(${_inputcpp} "${PCH_ARCH_${_UPPER_ARCH}_FLAGS};${PCH_FLAGS}")
|
|
|
|
PCH_CREATE_TARGET(${_targetName} ${_targetName}_pch_${_ARCH})
|
2010-06-25 11:42:21 +00:00
|
|
|
|
2012-12-08 10:34:39 +00:00
|
|
|
ADD_PRECOMPILED_HEADER_TO_TARGET_ARCH(${_targetName} ${_ARCH})
|
2015-10-06 18:30:43 +00:00
|
|
|
ENDFOREACH()
|
|
|
|
ELSE()
|
2012-12-08 10:34:39 +00:00
|
|
|
PCH_SET_PRECOMPILED_HEADER_OUTPUT(${_targetName} ${_inputh} "" "")
|
|
|
|
LIST(APPEND PCH_OUTPUTS ${PCH_OUTPUT})
|
2010-06-25 11:42:21 +00:00
|
|
|
|
2012-12-08 10:34:39 +00:00
|
|
|
PCH_SET_COMPILE_COMMAND(${_inputcpp} "${PCH_FLAGS}")
|
|
|
|
PCH_CREATE_TARGET(${_targetName} ${_targetName}_pch)
|
2015-10-06 18:30:43 +00:00
|
|
|
ENDIF()
|
2010-06-25 06:33:15 +00:00
|
|
|
|
2012-12-08 10:34:39 +00:00
|
|
|
ADD_PRECOMPILED_HEADER_TO_TARGET(${_targetName})
|
|
|
|
|
|
|
|
SET_DIRECTORY_PROPERTIES(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES "${PCH_OUTPUTS}")
|
2015-10-06 18:30:43 +00:00
|
|
|
ENDMACRO()
|
2010-06-25 06:33:15 +00:00
|
|
|
|
2010-06-26 14:47:36 +00:00
|
|
|
MACRO(ADD_NATIVE_PRECOMPILED_HEADER _targetName _inputh _inputcpp)
|
2015-12-07 12:08:27 +00:00
|
|
|
IF(PCHSupport_FOUND)
|
|
|
|
# 0 => creating a new target for PCH, works for all makefiles
|
|
|
|
# 1 => setting PCH for VC++ project, works for VC++ projects
|
|
|
|
# 2 => setting PCH for XCode project, works for XCode projects
|
|
|
|
IF(CMAKE_GENERATOR MATCHES "Visual Studio")
|
|
|
|
SET(PCH_METHOD 1)
|
|
|
|
ELSEIF(CMAKE_GENERATOR MATCHES "Xcode")
|
|
|
|
SET(PCH_METHOD 2)
|
|
|
|
ELSE()
|
|
|
|
SET(PCH_METHOD 0)
|
|
|
|
ENDIF()
|
2012-12-08 10:34:39 +00:00
|
|
|
|
2015-12-07 12:08:27 +00:00
|
|
|
IF(PCH_METHOD EQUAL 1)
|
|
|
|
# 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)
|
2012-12-08 10:34:39 +00:00
|
|
|
|
2015-12-07 12:08:27 +00:00
|
|
|
GET_TARGET_PROPERTY(oldProps ${_targetName} COMPILE_FLAGS)
|
|
|
|
IF(${oldProps} MATCHES NOTFOUND)
|
|
|
|
SET(oldProps "")
|
|
|
|
ENDIF()
|
2012-12-08 10:34:39 +00:00
|
|
|
|
2015-12-07 12:08:27 +00:00
|
|
|
SET(newProperties "${oldProps} /Yu\"${_inputh}\" /FI\"${_inputh}\"")
|
|
|
|
SET_TARGET_PROPERTIES(${_targetName} PROPERTIES COMPILE_FLAGS "${newProperties}")
|
2012-12-08 10:34:39 +00:00
|
|
|
|
2015-12-07 12:08:27 +00:00
|
|
|
#also inlude ${oldProps} to have the same compile options
|
|
|
|
SET_SOURCE_FILES_PROPERTIES(${_inputcpp} PROPERTIES COMPILE_FLAGS "${oldProps} /Yc\"${_inputh}\"")
|
|
|
|
ELSEIF(PCH_METHOD EQUAL 2)
|
|
|
|
# For Xcode, cmake needs my patch to process
|
|
|
|
# GCC_PREFIX_HEADER and GCC_PRECOMPILE_PREFIX_HEADER as target properties
|
2012-12-08 10:34:39 +00:00
|
|
|
|
2015-12-07 12:08:27 +00:00
|
|
|
# When buiding out of the tree, precompiled may not be located
|
|
|
|
# Use full path instead.
|
|
|
|
GET_FILENAME_COMPONENT(fullPath ${_inputh} ABSOLUTE)
|
2012-12-08 10:34:39 +00:00
|
|
|
|
2015-12-07 12:08:27 +00:00
|
|
|
SET_TARGET_PROPERTIES(${_targetName} PROPERTIES XCODE_ATTRIBUTE_GCC_PREFIX_HEADER "${fullPath}")
|
|
|
|
SET_TARGET_PROPERTIES(${_targetName} PROPERTIES XCODE_ATTRIBUTE_GCC_PRECOMPILE_PREFIX_HEADER "YES")
|
|
|
|
ELSE()
|
|
|
|
#Fallback to the "old" precompiled suppport
|
|
|
|
ADD_PRECOMPILED_HEADER(${_targetName} ${_inputh} ${_inputcpp})
|
|
|
|
ENDIF()
|
2012-12-08 10:34:39 +00:00
|
|
|
|
2015-12-07 12:08:27 +00:00
|
|
|
IF(TARGET ${_targetName}_static)
|
|
|
|
ADD_NATIVE_PRECOMPILED_HEADER(${_targetName}_static ${_inputh} ${_inputcpp})
|
|
|
|
ENDIF()
|
2015-10-06 18:30:43 +00:00
|
|
|
ELSE()
|
2015-12-07 12:08:27 +00:00
|
|
|
MESSAGE(STATUS "PCH disabled because compiler doesn't support them")
|
2015-10-06 18:30:43 +00:00
|
|
|
ENDIF()
|
|
|
|
ENDMACRO()
|