2012-06-18 08:53:13 +02:00
|
|
|
# taken from http://public.kitware.com/Bug/view.php?id=1260 and slightly adjusted
|
2010-05-11 19:44:00 +02:00
|
|
|
|
|
|
|
# - Try to find precompiled headers support for GCC 3.4 and 4.x
|
|
|
|
# Once done this will define:
|
|
|
|
#
|
|
|
|
# Variable:
|
|
|
|
# PCHSupport_FOUND
|
|
|
|
#
|
|
|
|
# Macro:
|
|
|
|
# ADD_PRECOMPILED_HEADER _targetName _input _dowarn
|
|
|
|
# ADD_PRECOMPILED_HEADER_TO_TARGET _targetName _input _pch_output_to_use _dowarn
|
|
|
|
# ADD_NATIVE_PRECOMPILED_HEADER _targetName _input _dowarn
|
|
|
|
# GET_NATIVE_PRECOMPILED_HEADER _targetName _input
|
|
|
|
|
|
|
|
IF(CMAKE_COMPILER_IS_GNUCXX)
|
|
|
|
|
|
|
|
EXEC_PROGRAM(
|
2011-07-24 21:22:58 +02:00
|
|
|
${CMAKE_CXX_COMPILER}
|
|
|
|
ARGS ${CMAKE_CXX_COMPILER_ARG1} -dumpversion
|
2010-05-11 19:44:00 +02:00
|
|
|
OUTPUT_VARIABLE gcc_compiler_version)
|
|
|
|
#MESSAGE("GCC Version: ${gcc_compiler_version}")
|
2012-09-04 14:50:55 +02:00
|
|
|
IF(gcc_compiler_version MATCHES "4\\.[0,2-9]\\.[0-9x]")
|
2010-05-11 19:44:00 +02:00
|
|
|
SET(PCHSupport_FOUND TRUE)
|
2010-07-05 22:50:29 +02:00
|
|
|
ENDIF()
|
2010-05-11 19:44:00 +02:00
|
|
|
|
2011-07-24 21:22:58 +02:00
|
|
|
SET(_PCH_include_prefix "-I")
|
2012-06-08 18:04:14 +02:00
|
|
|
SET(_PCH_isystem_prefix "-isystem")
|
2010-05-11 19:44:00 +02:00
|
|
|
|
2012-06-18 08:53:13 +02:00
|
|
|
ELSEIF(CMAKE_GENERATOR MATCHES "^Visual.*$")
|
|
|
|
SET(PCHSupport_FOUND TRUE)
|
2011-07-24 21:22:58 +02:00
|
|
|
SET(_PCH_include_prefix "/I")
|
2012-06-08 18:04:14 +02:00
|
|
|
SET(_PCH_isystem_prefix "/I")
|
2010-07-05 22:50:29 +02:00
|
|
|
ELSE()
|
2011-07-24 21:22:58 +02:00
|
|
|
SET(PCHSupport_FOUND FALSE)
|
|
|
|
ENDIF()
|
2010-05-11 19:44:00 +02:00
|
|
|
|
|
|
|
MACRO(_PCH_GET_COMPILE_FLAGS _out_compile_flags)
|
|
|
|
|
2011-07-24 21:22:58 +02:00
|
|
|
STRING(TOUPPER "CMAKE_CXX_FLAGS_${CMAKE_BUILD_TYPE}" _flags_var_name)
|
|
|
|
SET(${_out_compile_flags} ${${_flags_var_name}} )
|
2010-05-11 19:44:00 +02:00
|
|
|
|
2011-07-24 21:22:58 +02:00
|
|
|
IF(CMAKE_COMPILER_IS_GNUCXX)
|
2010-05-11 19:44:00 +02:00
|
|
|
|
2011-07-24 21:22:58 +02:00
|
|
|
GET_TARGET_PROPERTY(_targetType ${_PCH_current_target} TYPE)
|
|
|
|
IF(${_targetType} STREQUAL SHARED_LIBRARY AND NOT WIN32)
|
|
|
|
LIST(APPEND ${_out_compile_flags} "-fPIC")
|
|
|
|
ENDIF()
|
2010-05-11 19:44:00 +02:00
|
|
|
|
2011-07-24 21:22:58 +02:00
|
|
|
ELSE()
|
|
|
|
## TODO ... ? or does it work out of the box
|
2010-05-11 19:44:00 +02:00
|
|
|
ENDIF()
|
|
|
|
|
2011-07-24 21:22:58 +02:00
|
|
|
GET_DIRECTORY_PROPERTY(DIRINC INCLUDE_DIRECTORIES )
|
|
|
|
FOREACH(item ${DIRINC})
|
2012-06-08 18:04:14 +02:00
|
|
|
if(item MATCHES "^${OpenCV_SOURCE_DIR}/modules/")
|
|
|
|
LIST(APPEND ${_out_compile_flags} "${_PCH_include_prefix}\"${item}\"")
|
|
|
|
else()
|
|
|
|
LIST(APPEND ${_out_compile_flags} "${_PCH_isystem_prefix}\"${item}\"")
|
|
|
|
endif()
|
2011-07-24 21:22:58 +02:00
|
|
|
ENDFOREACH(item)
|
2010-05-11 19:44:00 +02:00
|
|
|
|
2011-07-24 21:22:58 +02:00
|
|
|
GET_DIRECTORY_PROPERTY(_directory_flags DEFINITIONS)
|
|
|
|
GET_DIRECTORY_PROPERTY(_global_definitions DIRECTORY ${OpenCV_SOURCE_DIR} DEFINITIONS)
|
|
|
|
#MESSAGE("_directory_flags ${_directory_flags} ${_global_definitions}" )
|
|
|
|
LIST(APPEND ${_out_compile_flags} ${_directory_flags})
|
|
|
|
LIST(APPEND ${_out_compile_flags} ${_global_definitions})
|
|
|
|
LIST(APPEND ${_out_compile_flags} ${CMAKE_CXX_FLAGS})
|
2010-05-11 19:44:00 +02:00
|
|
|
|
2011-07-24 21:22:58 +02:00
|
|
|
SEPARATE_ARGUMENTS(${_out_compile_flags})
|
2010-05-11 19:44:00 +02:00
|
|
|
|
|
|
|
ENDMACRO(_PCH_GET_COMPILE_FLAGS)
|
|
|
|
|
|
|
|
|
|
|
|
MACRO(_PCH_WRITE_PCHDEP_CXX _targetName _include_file _dephelp)
|
|
|
|
|
2011-07-24 21:22:58 +02:00
|
|
|
SET(${_dephelp} ${CMAKE_CURRENT_BINARY_DIR}/${_targetName}_pch_dephelp.cxx)
|
2011-07-24 23:08:36 +02:00
|
|
|
IF(CMAKE_HOST_WIN32)
|
|
|
|
ADD_CUSTOM_COMMAND(
|
|
|
|
OUTPUT "${${_dephelp}}"
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E echo "#include \\\"${_include_file}\\\"" > "${${_dephelp}}"
|
2012-06-07 19:21:29 +02:00
|
|
|
COMMAND ${CMAKE_COMMAND} -E echo "int testfunction();" >> "${${_dephelp}}"
|
2011-07-26 09:07:38 +02:00
|
|
|
COMMAND ${CMAKE_COMMAND} -E echo "int testfunction()" >> "${${_dephelp}}"
|
2011-07-24 23:08:36 +02:00
|
|
|
COMMAND ${CMAKE_COMMAND} -E echo "{" >> "${${_dephelp}}"
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E echo " return 0;" >> "${${_dephelp}}"
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E echo "}" >> "${${_dephelp}}"
|
|
|
|
DEPENDS "${_include_file}"
|
|
|
|
)
|
|
|
|
else()
|
|
|
|
ADD_CUSTOM_COMMAND(
|
|
|
|
OUTPUT "${${_dephelp}}"
|
2011-07-26 09:07:38 +02:00
|
|
|
COMMAND ${CMAKE_COMMAND} -E echo "\\#include \\\"${_include_file}\\\"" > "${${_dephelp}}"
|
2012-06-07 19:21:29 +02:00
|
|
|
COMMAND ${CMAKE_COMMAND} -E echo "int testfunction\\(\\)\\;" >> "${${_dephelp}}"
|
2011-07-24 23:08:36 +02:00
|
|
|
COMMAND ${CMAKE_COMMAND} -E echo "int testfunction\\(\\)" >> "${${_dephelp}}"
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E echo "{" >> "${${_dephelp}}"
|
2011-07-26 09:07:38 +02:00
|
|
|
COMMAND ${CMAKE_COMMAND} -E echo " \\return 0\\;" >> "${${_dephelp}}"
|
2011-07-24 23:08:36 +02:00
|
|
|
COMMAND ${CMAKE_COMMAND} -E echo "}" >> "${${_dephelp}}"
|
|
|
|
DEPENDS "${_include_file}"
|
|
|
|
)
|
|
|
|
endif()
|
2010-05-11 19:44:00 +02:00
|
|
|
|
|
|
|
ENDMACRO(_PCH_WRITE_PCHDEP_CXX )
|
|
|
|
|
|
|
|
MACRO(_PCH_GET_COMPILE_COMMAND out_command _input _output)
|
|
|
|
|
2011-07-24 21:22:58 +02:00
|
|
|
FILE(TO_NATIVE_PATH ${_input} _native_input)
|
|
|
|
FILE(TO_NATIVE_PATH ${_output} _native_output)
|
2010-05-11 19:44:00 +02:00
|
|
|
|
2011-07-24 21:22:58 +02:00
|
|
|
IF(CMAKE_COMPILER_IS_GNUCXX)
|
|
|
|
IF(CMAKE_CXX_COMPILER_ARG1)
|
|
|
|
# remove leading space in compiler argument
|
2010-05-11 19:44:00 +02:00
|
|
|
STRING(REGEX REPLACE "^ +" "" pchsupport_compiler_cxx_arg1 ${CMAKE_CXX_COMPILER_ARG1})
|
|
|
|
|
2011-07-24 21:22:58 +02:00
|
|
|
SET(${out_command}
|
|
|
|
${CMAKE_CXX_COMPILER} ${pchsupport_compiler_cxx_arg1} ${_compile_FLAGS} -x c++-header -o ${_output} ${_input}
|
|
|
|
)
|
|
|
|
ELSE(CMAKE_CXX_COMPILER_ARG1)
|
|
|
|
SET(${out_command}
|
|
|
|
${CMAKE_CXX_COMPILER} ${_compile_FLAGS} -x c++-header -o ${_output} ${_input}
|
|
|
|
)
|
|
|
|
ENDIF(CMAKE_CXX_COMPILER_ARG1)
|
|
|
|
ELSE(CMAKE_COMPILER_IS_GNUCXX)
|
2010-05-11 19:44:00 +02:00
|
|
|
|
2011-07-24 21:22:58 +02:00
|
|
|
SET(_dummy_str "#include <${_input}>")
|
|
|
|
FILE(WRITE ${CMAKE_CURRENT_BINARY_DIR}/pch_dummy.cpp ${_dummy_str})
|
2010-05-11 19:44:00 +02:00
|
|
|
|
2011-07-24 21:22:58 +02:00
|
|
|
SET(${out_command}
|
|
|
|
${CMAKE_CXX_COMPILER} ${_compile_FLAGS} /c /Fp${_native_output} /Yc${_native_input} pch_dummy.cpp
|
|
|
|
)
|
|
|
|
#/out:${_output}
|
2010-05-11 19:44:00 +02:00
|
|
|
|
2011-07-24 21:22:58 +02:00
|
|
|
ENDIF(CMAKE_COMPILER_IS_GNUCXX)
|
2010-05-11 19:44:00 +02:00
|
|
|
|
|
|
|
ENDMACRO(_PCH_GET_COMPILE_COMMAND )
|
|
|
|
|
|
|
|
|
|
|
|
MACRO(_PCH_GET_TARGET_COMPILE_FLAGS _cflags _header_name _pch_path _dowarn )
|
|
|
|
|
2011-07-24 21:22:58 +02:00
|
|
|
FILE(TO_NATIVE_PATH ${_pch_path} _native_pch_path)
|
2010-05-11 19:44:00 +02:00
|
|
|
|
2011-07-24 21:22:58 +02:00
|
|
|
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
|
|
|
|
# if you want warnings for invalid header files (which is very inconvenient
|
|
|
|
# if you have different versions of the headers for different build types
|
|
|
|
# you may set _pch_dowarn
|
|
|
|
IF (_dowarn)
|
|
|
|
SET(${_cflags} "${PCH_ADDITIONAL_COMPILER_FLAGS} -include \"${CMAKE_CURRENT_BINARY_DIR}/${_header_name}\" -Winvalid-pch " )
|
|
|
|
ELSE (_dowarn)
|
|
|
|
SET(${_cflags} "${PCH_ADDITIONAL_COMPILER_FLAGS} -include \"${CMAKE_CURRENT_BINARY_DIR}/${_header_name}\" " )
|
|
|
|
ENDIF (_dowarn)
|
2010-05-11 19:44:00 +02:00
|
|
|
|
2011-07-24 21:22:58 +02:00
|
|
|
ELSE(CMAKE_COMPILER_IS_GNUCXX)
|
2010-05-11 19:44:00 +02:00
|
|
|
|
2011-07-24 21:22:58 +02:00
|
|
|
set(${_cflags} "/Fp${_native_pch_path} /Yu${_header_name}" )
|
|
|
|
|
|
|
|
ENDIF(CMAKE_COMPILER_IS_GNUCXX)
|
2010-05-11 19:44:00 +02:00
|
|
|
|
|
|
|
ENDMACRO(_PCH_GET_TARGET_COMPILE_FLAGS )
|
|
|
|
|
2011-07-24 21:22:58 +02:00
|
|
|
|
2010-05-11 19:44:00 +02:00
|
|
|
MACRO(GET_PRECOMPILED_HEADER_OUTPUT _targetName _input _output)
|
2011-07-24 21:22:58 +02:00
|
|
|
|
|
|
|
GET_FILENAME_COMPONENT(_name ${_input} NAME)
|
|
|
|
GET_FILENAME_COMPONENT(_path ${_input} PATH)
|
|
|
|
SET(${_output} "${CMAKE_CURRENT_BINARY_DIR}/${_name}.gch/${_targetName}_${CMAKE_BUILD_TYPE}.gch")
|
|
|
|
|
2010-05-11 19:44:00 +02:00
|
|
|
ENDMACRO(GET_PRECOMPILED_HEADER_OUTPUT _targetName _input)
|
|
|
|
|
|
|
|
|
|
|
|
MACRO(ADD_PRECOMPILED_HEADER_TO_TARGET _targetName _input _pch_output_to_use )
|
|
|
|
|
2011-07-24 21:22:58 +02:00
|
|
|
# to do: test whether compiler flags match between target _targetName
|
|
|
|
# and _pch_output_to_use
|
|
|
|
GET_FILENAME_COMPONENT(_name ${_input} NAME)
|
2010-05-11 19:44:00 +02:00
|
|
|
|
2011-07-24 21:22:58 +02:00
|
|
|
IF(ARGN STREQUAL "0")
|
|
|
|
SET(_dowarn 0)
|
|
|
|
ELSE()
|
|
|
|
SET(_dowarn 1)
|
|
|
|
ENDIF()
|
2010-05-11 19:44:00 +02:00
|
|
|
|
2011-07-24 21:22:58 +02:00
|
|
|
_PCH_GET_TARGET_COMPILE_FLAGS(_target_cflags ${_name} ${_pch_output_to_use} ${_dowarn})
|
|
|
|
#MESSAGE("Add flags ${_target_cflags} to ${_targetName} " )
|
2012-10-22 17:13:29 +02:00
|
|
|
|
|
|
|
GET_TARGET_PROPERTY(_sources ${_targetName} SOURCES)
|
|
|
|
FOREACH(src ${_sources})
|
|
|
|
if(NOT "${src}" MATCHES "\\.mm$")
|
|
|
|
get_source_file_property(_flags "${src}" COMPILE_FLAGS)
|
|
|
|
if(_flags)
|
|
|
|
set(_flags "${_flags} ${_target_cflags}")
|
|
|
|
else()
|
|
|
|
set(_flags "${_target_cflags}")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
set_source_files_properties("${src}" PROPERTIES COMPILE_FLAGS "${_flags}")
|
|
|
|
endif()
|
|
|
|
ENDFOREACH()
|
2010-05-11 19:44:00 +02:00
|
|
|
|
2011-07-24 21:22:58 +02:00
|
|
|
ADD_CUSTOM_TARGET(pch_Generate_${_targetName}
|
|
|
|
DEPENDS ${_pch_output_to_use}
|
|
|
|
)
|
2010-05-11 19:44:00 +02:00
|
|
|
|
2011-07-24 21:22:58 +02:00
|
|
|
ADD_DEPENDENCIES(${_targetName} pch_Generate_${_targetName} )
|
2010-05-11 19:44:00 +02:00
|
|
|
|
|
|
|
ENDMACRO(ADD_PRECOMPILED_HEADER_TO_TARGET)
|
|
|
|
|
|
|
|
MACRO(ADD_PRECOMPILED_HEADER _targetName _input)
|
|
|
|
|
2011-07-24 21:22:58 +02:00
|
|
|
SET(_PCH_current_target ${_targetName})
|
2010-05-11 19:44:00 +02:00
|
|
|
|
2011-07-24 21:22:58 +02:00
|
|
|
IF(NOT CMAKE_BUILD_TYPE)
|
|
|
|
MESSAGE(FATAL_ERROR
|
|
|
|
"This is the ADD_PRECOMPILED_HEADER macro. "
|
|
|
|
"You must set CMAKE_BUILD_TYPE!"
|
|
|
|
)
|
|
|
|
ENDIF()
|
2010-05-11 19:44:00 +02:00
|
|
|
|
2011-07-24 21:22:58 +02:00
|
|
|
IF(ARGN STREQUAL "0")
|
|
|
|
SET(_dowarn 0)
|
|
|
|
ELSE()
|
|
|
|
SET(_dowarn 1)
|
|
|
|
ENDIF()
|
2010-05-11 19:44:00 +02:00
|
|
|
|
2011-07-24 21:22:58 +02:00
|
|
|
GET_FILENAME_COMPONENT(_name ${_input} NAME)
|
|
|
|
GET_FILENAME_COMPONENT(_path ${_input} PATH)
|
|
|
|
GET_PRECOMPILED_HEADER_OUTPUT( ${_targetName} ${_input} _output)
|
2010-05-11 19:44:00 +02:00
|
|
|
|
2011-07-24 21:22:58 +02:00
|
|
|
_PCH_WRITE_PCHDEP_CXX(${_targetName} "${_input}" _pch_dephelp_cxx)
|
2010-05-11 19:44:00 +02:00
|
|
|
|
2011-07-24 21:22:58 +02:00
|
|
|
ADD_LIBRARY(${_targetName}_pch_dephelp STATIC "${_pch_dephelp_cxx}" "${_input}" )
|
2012-01-03 14:48:12 +01:00
|
|
|
|
2011-07-24 21:22:58 +02:00
|
|
|
set_target_properties(${_targetName}_pch_dephelp PROPERTIES
|
|
|
|
DEBUG_POSTFIX "${OPENCV_DEBUG_POSTFIX}"
|
|
|
|
ARCHIVE_OUTPUT_DIRECTORY "${LIBRARY_OUTPUT_PATH}"
|
|
|
|
)
|
2010-05-11 19:44:00 +02:00
|
|
|
|
2011-07-24 21:22:58 +02:00
|
|
|
_PCH_GET_COMPILE_FLAGS(_compile_FLAGS)
|
2010-05-11 19:44:00 +02:00
|
|
|
|
2011-07-24 21:22:58 +02:00
|
|
|
#MESSAGE("_compile_FLAGS: ${_compile_FLAGS}")
|
|
|
|
#message("COMMAND ${CMAKE_CXX_COMPILER} ${_compile_FLAGS} -x c++-header -o ${_output} ${_input}")
|
2012-01-03 14:48:12 +01:00
|
|
|
|
2011-07-24 21:22:58 +02:00
|
|
|
ADD_CUSTOM_COMMAND(
|
|
|
|
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${_name}"
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E copy "${_input}" "${CMAKE_CURRENT_BINARY_DIR}/${_name}" # ensure same directory! Required by gcc
|
|
|
|
DEPENDS "${_input}"
|
|
|
|
)
|
2010-05-11 19:44:00 +02:00
|
|
|
|
2011-07-24 21:22:58 +02:00
|
|
|
#message("_command ${_input} ${_output}")
|
|
|
|
_PCH_GET_COMPILE_COMMAND(_command ${CMAKE_CURRENT_BINARY_DIR}/${_name} ${_output} )
|
|
|
|
|
|
|
|
GET_FILENAME_COMPONENT(_outdir ${_output} PATH)
|
|
|
|
ADD_CUSTOM_COMMAND(
|
|
|
|
OUTPUT "${_output}"
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E make_directory "${_outdir}"
|
|
|
|
COMMAND ${_command}
|
|
|
|
DEPENDS "${_input}"
|
|
|
|
DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/${_name}"
|
|
|
|
DEPENDS ${_targetName}_pch_dephelp
|
|
|
|
)
|
2010-05-11 19:44:00 +02:00
|
|
|
|
2011-07-24 21:22:58 +02:00
|
|
|
ADD_PRECOMPILED_HEADER_TO_TARGET(${_targetName} ${_input} ${_output} ${_dowarn})
|
2012-01-03 14:48:12 +01:00
|
|
|
|
2010-05-11 19:44:00 +02:00
|
|
|
ENDMACRO(ADD_PRECOMPILED_HEADER)
|
|
|
|
|
|
|
|
|
|
|
|
# Generates the use of precompiled in a target,
|
|
|
|
# without using depency targets (2 extra for each target)
|
|
|
|
# Using Visual, must also add ${_targetName}_pch to sources
|
|
|
|
# Not needed by Xcode
|
|
|
|
|
|
|
|
MACRO(GET_NATIVE_PRECOMPILED_HEADER _targetName _input)
|
|
|
|
|
2011-07-24 21:22:58 +02:00
|
|
|
if(CMAKE_GENERATOR MATCHES "^Visual.*$")
|
|
|
|
SET(_dummy_str "#include \"${_input}\"\n"
|
|
|
|
"// This is required to suppress LNK4221. Very annoying.\n"
|
|
|
|
"void *g_${_targetName}Dummy = 0\;\n")
|
|
|
|
|
|
|
|
# Use of cxx extension for generated files (as Qt does)
|
|
|
|
SET(${_targetName}_pch ${CMAKE_CURRENT_BINARY_DIR}/${_targetName}_pch.cxx)
|
|
|
|
if(EXISTS ${${_targetName}_pch})
|
|
|
|
# Check if contents is the same, if not rewrite
|
|
|
|
# todo
|
|
|
|
else()
|
|
|
|
FILE(WRITE ${${_targetName}_pch} ${_dummy_str})
|
|
|
|
endif()
|
|
|
|
endif()
|
2010-05-11 19:44:00 +02:00
|
|
|
|
|
|
|
ENDMACRO(GET_NATIVE_PRECOMPILED_HEADER)
|
|
|
|
|
|
|
|
|
|
|
|
MACRO(ADD_NATIVE_PRECOMPILED_HEADER _targetName _input)
|
|
|
|
|
2011-07-24 21:22:58 +02:00
|
|
|
IF(ARGN STREQUAL "0")
|
|
|
|
SET(_dowarn 0)
|
|
|
|
ELSE()
|
|
|
|
SET(_dowarn 1)
|
|
|
|
ENDIF()
|
2010-05-11 19:44:00 +02:00
|
|
|
|
2011-07-24 21:22:58 +02:00
|
|
|
if(CMAKE_GENERATOR MATCHES "^Visual.*$")
|
2012-01-03 14:48:12 +01:00
|
|
|
|
2011-07-24 21:22:58 +02:00
|
|
|
# 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)
|
2010-05-11 19:44:00 +02:00
|
|
|
|
2011-07-24 21:22:58 +02:00
|
|
|
GET_TARGET_PROPERTY(oldProps ${_targetName} COMPILE_FLAGS)
|
|
|
|
if (oldProps MATCHES NOTFOUND)
|
|
|
|
SET(oldProps "")
|
|
|
|
endif()
|
2010-05-11 19:44:00 +02:00
|
|
|
|
2011-07-24 21:22:58 +02:00
|
|
|
SET(newProperties "${oldProps} /Yu\"${_input}\" /FI\"${_input}\"")
|
|
|
|
SET_TARGET_PROPERTIES(${_targetName} PROPERTIES COMPILE_FLAGS "${newProperties}")
|
2010-05-11 19:44:00 +02:00
|
|
|
|
2011-07-24 21:22:58 +02:00
|
|
|
#also inlude ${oldProps} to have the same compile options
|
|
|
|
SET_SOURCE_FILES_PROPERTIES(${${_targetName}_pch} PROPERTIES COMPILE_FLAGS "${oldProps} /Yc\"${_input}\"")
|
2010-05-11 19:44:00 +02:00
|
|
|
|
2011-07-24 21:22:58 +02:00
|
|
|
elseif (CMAKE_GENERATOR MATCHES Xcode)
|
2012-01-03 14:48:12 +01:00
|
|
|
|
2011-07-24 21:22:58 +02:00
|
|
|
# For Xcode, cmake needs my patch to process
|
|
|
|
# GCC_PREFIX_HEADER and GCC_PRECOMPILE_PREFIX_HEADER as target properties
|
2010-05-11 19:44:00 +02:00
|
|
|
|
2011-07-24 21:22:58 +02:00
|
|
|
# When buiding out of the tree, precompiled may not be located
|
|
|
|
# Use full path instead.
|
|
|
|
GET_FILENAME_COMPONENT(fullPath ${_input} ABSOLUTE)
|
2010-05-11 19:44:00 +02:00
|
|
|
|
2011-07-24 21:22:58 +02:00
|
|
|
SET_TARGET_PROPERTIES(${_targetName} PROPERTIES XCODE_ATTRIBUTE_GCC_PREFIX_HEADER "${fullPath}")
|
|
|
|
SET_TARGET_PROPERTIES(${_targetName} PROPERTIES XCODE_ATTRIBUTE_GCC_PRECOMPILE_PREFIX_HEADER "YES")
|
2010-05-11 19:44:00 +02:00
|
|
|
|
2011-07-24 21:22:58 +02:00
|
|
|
else()
|
2010-05-11 19:44:00 +02:00
|
|
|
|
2011-07-24 21:22:58 +02:00
|
|
|
#Fallback to the "old" precompiled suppport
|
|
|
|
#ADD_PRECOMPILED_HEADER(${_targetName} ${_input} ${_dowarn})
|
2010-05-11 19:44:00 +02:00
|
|
|
|
2011-07-24 21:22:58 +02:00
|
|
|
endif()
|
2010-05-11 19:44:00 +02:00
|
|
|
|
|
|
|
ENDMACRO(ADD_NATIVE_PRECOMPILED_HEADER)
|
2012-06-18 08:53:13 +02:00
|
|
|
|
|
|
|
macro(ocv_add_precompiled_header_to_target the_target pch_header)
|
|
|
|
if(PCHSupport_FOUND AND ENABLE_PRECOMPILED_HEADERS AND EXISTS "${pch_header}")
|
|
|
|
if(CMAKE_GENERATOR MATCHES Visual)
|
2012-06-18 11:19:57 +02:00
|
|
|
string(REGEX REPLACE "hpp$" "cpp" ${the_target}_pch "${pch_header}")
|
2012-06-18 08:53:13 +02:00
|
|
|
add_native_precompiled_header(${the_target} ${pch_header})
|
|
|
|
unset(${the_target}_pch)
|
|
|
|
elseif(CMAKE_GENERATOR MATCHES Xcode)
|
|
|
|
add_native_precompiled_header(${the_target} ${pch_header})
|
|
|
|
elseif(CMAKE_COMPILER_IS_GNUCXX AND CMAKE_GENERATOR MATCHES "Makefiles|Ninja")
|
|
|
|
add_precompiled_header(${the_target} ${pch_header})
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
endmacro()
|