mirror of
https://github.com/opencv/opencv.git
synced 2024-11-25 11:40:44 +08:00
Merge pull request #7393 from alalek:cmake_pch_update
This commit is contained in:
commit
bdf82149e9
@ -62,7 +62,8 @@ MACRO(_PCH_GET_COMPILE_FLAGS _out_compile_flags)
|
|||||||
|
|
||||||
GET_DIRECTORY_PROPERTY(DIRINC INCLUDE_DIRECTORIES )
|
GET_DIRECTORY_PROPERTY(DIRINC INCLUDE_DIRECTORIES )
|
||||||
FOREACH(item ${DIRINC})
|
FOREACH(item ${DIRINC})
|
||||||
if(item MATCHES "^${OpenCV_SOURCE_DIR}/modules/")
|
ocv_is_opencv_directory(__result ${item})
|
||||||
|
if(__result)
|
||||||
LIST(APPEND ${_out_compile_flags} "${_PCH_include_prefix}\"${item}\"")
|
LIST(APPEND ${_out_compile_flags} "${_PCH_include_prefix}\"${item}\"")
|
||||||
else()
|
else()
|
||||||
LIST(APPEND ${_out_compile_flags} "${_PCH_isystem_prefix}\"${item}\"")
|
LIST(APPEND ${_out_compile_flags} "${_PCH_isystem_prefix}\"${item}\"")
|
||||||
@ -71,7 +72,8 @@ MACRO(_PCH_GET_COMPILE_FLAGS _out_compile_flags)
|
|||||||
|
|
||||||
get_target_property(DIRINC ${_PCH_current_target} INCLUDE_DIRECTORIES )
|
get_target_property(DIRINC ${_PCH_current_target} INCLUDE_DIRECTORIES )
|
||||||
FOREACH(item ${DIRINC})
|
FOREACH(item ${DIRINC})
|
||||||
if(item MATCHES "^${OpenCV_SOURCE_DIR}/modules/")
|
ocv_is_opencv_directory(__result ${item})
|
||||||
|
if(__result)
|
||||||
LIST(APPEND ${_out_compile_flags} "${_PCH_include_prefix}\"${item}\"")
|
LIST(APPEND ${_out_compile_flags} "${_PCH_include_prefix}\"${item}\"")
|
||||||
else()
|
else()
|
||||||
LIST(APPEND ${_out_compile_flags} "${_PCH_isystem_prefix}\"${item}\"")
|
LIST(APPEND ${_out_compile_flags} "${_PCH_isystem_prefix}\"${item}\"")
|
||||||
@ -87,29 +89,21 @@ ENDMACRO(_PCH_GET_COMPILE_FLAGS)
|
|||||||
|
|
||||||
MACRO(_PCH_WRITE_PCHDEP_CXX _targetName _include_file _dephelp)
|
MACRO(_PCH_WRITE_PCHDEP_CXX _targetName _include_file _dephelp)
|
||||||
|
|
||||||
SET(${_dephelp} ${CMAKE_CURRENT_BINARY_DIR}/${_targetName}_pch_dephelp.cxx)
|
set(${_dephelp} "${CMAKE_CURRENT_BINARY_DIR}/${_targetName}_pch_dephelp.cxx")
|
||||||
IF(CMAKE_HOST_WIN32)
|
set(_content "")
|
||||||
ADD_CUSTOM_COMMAND(
|
if(EXISTS "${_dephelp}")
|
||||||
OUTPUT "${${_dephelp}}"
|
file(READ "${_dephelp}" _content)
|
||||||
COMMAND ${CMAKE_COMMAND} -E echo "#include \\\"${_include_file}\\\"" > "${${_dephelp}}"
|
endif()
|
||||||
COMMAND ${CMAKE_COMMAND} -E echo "int testfunction();" >> "${${_dephelp}}"
|
set(_dummy_str
|
||||||
COMMAND ${CMAKE_COMMAND} -E echo "int testfunction()" >> "${${_dephelp}}"
|
"#include \"${_include_file}\"
|
||||||
COMMAND ${CMAKE_COMMAND} -E echo "{" >> "${${_dephelp}}"
|
int testfunction();
|
||||||
COMMAND ${CMAKE_COMMAND} -E echo " return 0;" >> "${${_dephelp}}"
|
int testfunction()
|
||||||
COMMAND ${CMAKE_COMMAND} -E echo "}" >> "${${_dephelp}}"
|
{
|
||||||
DEPENDS "${_include_file}"
|
return 0;
|
||||||
)
|
}
|
||||||
else()
|
")
|
||||||
ADD_CUSTOM_COMMAND(
|
if(NOT _content STREQUAL _dummy_str)
|
||||||
OUTPUT "${${_dephelp}}"
|
file(WRITE "${${_dephelp}}" "${_dummy_str}")
|
||||||
COMMAND ${CMAKE_COMMAND} -E echo "\\#include \\\"${_include_file}\\\"" > "${${_dephelp}}"
|
|
||||||
COMMAND ${CMAKE_COMMAND} -E echo "int testfunction\\(\\)\\;" >> "${${_dephelp}}"
|
|
||||||
COMMAND ${CMAKE_COMMAND} -E echo "int testfunction\\(\\)" >> "${${_dephelp}}"
|
|
||||||
COMMAND ${CMAKE_COMMAND} -E echo "{" >> "${${_dephelp}}"
|
|
||||||
COMMAND ${CMAKE_COMMAND} -E echo " \\return 0\\;" >> "${${_dephelp}}"
|
|
||||||
COMMAND ${CMAKE_COMMAND} -E echo "}" >> "${${_dephelp}}"
|
|
||||||
DEPENDS "${_include_file}"
|
|
||||||
)
|
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
ENDMACRO(_PCH_WRITE_PCHDEP_CXX )
|
ENDMACRO(_PCH_WRITE_PCHDEP_CXX )
|
||||||
@ -284,16 +278,21 @@ MACRO(ADD_PRECOMPILED_HEADER _targetName _input)
|
|||||||
DEPENDS ${_targetName}_pch_dephelp
|
DEPENDS ${_targetName}_pch_dephelp
|
||||||
)
|
)
|
||||||
|
|
||||||
|
get_target_property(_sources ${_targetName} SOURCES)
|
||||||
|
foreach(src ${_sources})
|
||||||
|
if(NOT "${src}" MATCHES "\\.mm$")
|
||||||
|
get_source_file_property(oldProps "${src}" COMPILE_FLAGS)
|
||||||
|
if(NOT oldProps)
|
||||||
|
set(newProperties "-include \"${CMAKE_CURRENT_BINARY_DIR}/${_name}\"")
|
||||||
|
set_source_files_properties("${src}" PROPERTIES COMPILE_FLAGS "${newProperties}")
|
||||||
|
else()
|
||||||
|
ocv_debug_message("Skip PCH, flags: ${oldProps} , file: ${src}")
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
endforeach()
|
||||||
|
|
||||||
ADD_PRECOMPILED_HEADER_TO_TARGET(${_targetName} ${_input} ${_output} ${_dowarn})
|
ADD_PRECOMPILED_HEADER_TO_TARGET(${_targetName} ${_input} ${_output} ${_dowarn})
|
||||||
|
|
||||||
|
|
||||||
GET_TARGET_PROPERTY(oldProps ${_targetName} COMPILE_FLAGS)
|
|
||||||
if (oldProps MATCHES NOTFOUND)
|
|
||||||
SET(oldProps "")
|
|
||||||
endif()
|
|
||||||
SET(newProperties "${oldProps} -include \"${CMAKE_CURRENT_BINARY_DIR}/${_name}\"")
|
|
||||||
SET_TARGET_PROPERTIES(${_targetName} PROPERTIES COMPILE_FLAGS "${newProperties}")
|
|
||||||
|
|
||||||
ENDMACRO(ADD_PRECOMPILED_HEADER)
|
ENDMACRO(ADD_PRECOMPILED_HEADER)
|
||||||
|
|
||||||
|
|
||||||
@ -305,15 +304,7 @@ ENDMACRO(ADD_PRECOMPILED_HEADER)
|
|||||||
MACRO(GET_NATIVE_PRECOMPILED_HEADER _targetName _input)
|
MACRO(GET_NATIVE_PRECOMPILED_HEADER _targetName _input)
|
||||||
|
|
||||||
if(CMAKE_GENERATOR MATCHES "^Visual.*$")
|
if(CMAKE_GENERATOR MATCHES "^Visual.*$")
|
||||||
set(_dummy_str "#include \"${_input}\"\n")
|
|
||||||
|
|
||||||
set(${_targetName}_pch ${CMAKE_CURRENT_BINARY_DIR}/${_targetName}_pch.cpp)
|
set(${_targetName}_pch ${CMAKE_CURRENT_BINARY_DIR}/${_targetName}_pch.cpp)
|
||||||
if(EXISTS ${${_targetName}_pch})
|
|
||||||
# Check if contents is the same, if not rewrite
|
|
||||||
# todo
|
|
||||||
else()
|
|
||||||
FILE(WRITE ${${_targetName}_pch} ${_dummy_str})
|
|
||||||
endif()
|
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
ENDMACRO(GET_NATIVE_PRECOMPILED_HEADER)
|
ENDMACRO(GET_NATIVE_PRECOMPILED_HEADER)
|
||||||
@ -333,17 +324,35 @@ MACRO(ADD_NATIVE_PRECOMPILED_HEADER _targetName _input)
|
|||||||
# precompiled is specified at the target level
|
# precompiled is specified at the target level
|
||||||
# and I don't want to specifiy /F- for each moc/res/ui generated files (using Qt)
|
# and I don't want to specifiy /F- for each moc/res/ui generated files (using Qt)
|
||||||
|
|
||||||
|
get_target_property(_sources ${_targetName} SOURCES)
|
||||||
|
foreach(src ${_sources})
|
||||||
|
if(NOT "${src}" MATCHES "\\.mm$")
|
||||||
|
get_source_file_property(oldProps "${src}" COMPILE_FLAGS)
|
||||||
|
if(NOT oldProps)
|
||||||
|
set(newProperties "/Yu\"${_input}\" /FI\"${_input}\"")
|
||||||
|
set_source_files_properties("${src}" PROPERTIES COMPILE_FLAGS "${newProperties}")
|
||||||
|
else()
|
||||||
|
ocv_debug_message("Skip PCH, flags: ${oldProps} , file: ${src}")
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
endforeach()
|
||||||
|
|
||||||
|
#also inlude ${oldProps} to have the same compile options
|
||||||
GET_TARGET_PROPERTY(oldProps ${_targetName} COMPILE_FLAGS)
|
GET_TARGET_PROPERTY(oldProps ${_targetName} COMPILE_FLAGS)
|
||||||
if (oldProps MATCHES NOTFOUND)
|
if (oldProps MATCHES NOTFOUND)
|
||||||
SET(oldProps "")
|
SET(oldProps "")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
SET(newProperties "${oldProps} /Yu\"${_input}\" /FI\"${_input}\"")
|
|
||||||
SET_TARGET_PROPERTIES(${_targetName} PROPERTIES COMPILE_FLAGS "${newProperties}")
|
|
||||||
|
|
||||||
#also inlude ${oldProps} to have the same compile options
|
|
||||||
SET_SOURCE_FILES_PROPERTIES(${${_targetName}_pch} PROPERTIES COMPILE_FLAGS "${oldProps} /Yc\"${_input}\"")
|
SET_SOURCE_FILES_PROPERTIES(${${_targetName}_pch} PROPERTIES COMPILE_FLAGS "${oldProps} /Yc\"${_input}\"")
|
||||||
|
|
||||||
|
set(_dummy_str "#include \"${_input}\"\n")
|
||||||
|
set(${_targetName}_pch ${CMAKE_CURRENT_BINARY_DIR}/${_targetName}_pch.cpp)
|
||||||
|
if(EXISTS ${${_targetName}_pch})
|
||||||
|
file(READ "${${_targetName}_pch}" _contents)
|
||||||
|
endif()
|
||||||
|
if(NOT _dummy_str STREQUAL "${_contents}")
|
||||||
|
file(WRITE ${${_targetName}_pch} ${_dummy_str})
|
||||||
|
endif()
|
||||||
|
|
||||||
elseif (CMAKE_GENERATOR MATCHES Xcode)
|
elseif (CMAKE_GENERATOR MATCHES Xcode)
|
||||||
|
|
||||||
# For Xcode, cmake needs my patch to process
|
# For Xcode, cmake needs my patch to process
|
||||||
|
@ -111,15 +111,25 @@ macro(_ocv_fix_target target_var)
|
|||||||
endif()
|
endif()
|
||||||
endmacro()
|
endmacro()
|
||||||
|
|
||||||
|
function(ocv_is_opencv_directory result_var dir)
|
||||||
|
get_filename_component(__abs_dir "${dir}" ABSOLUTE)
|
||||||
|
if("${__abs_dir}" MATCHES "^${OpenCV_SOURCE_DIR}"
|
||||||
|
OR "${__abs_dir}" MATCHES "^${OpenCV_BINARY_DIR}"
|
||||||
|
OR (OPENCV_EXTRA_MODULES_PATH AND "${__abs_dir}" MATCHES "^${OPENCV_EXTRA_MODULES_PATH}"))
|
||||||
|
set(${result_var} 1 PARENT_SCOPE)
|
||||||
|
else()
|
||||||
|
set(${result_var} 0 PARENT_SCOPE)
|
||||||
|
endif()
|
||||||
|
endfunction()
|
||||||
|
|
||||||
|
|
||||||
# adds include directories in such way that directories from the OpenCV source tree go first
|
# adds include directories in such way that directories from the OpenCV source tree go first
|
||||||
function(ocv_include_directories)
|
function(ocv_include_directories)
|
||||||
ocv_debug_message("ocv_include_directories( ${ARGN} )")
|
ocv_debug_message("ocv_include_directories( ${ARGN} )")
|
||||||
set(__add_before "")
|
set(__add_before "")
|
||||||
foreach(dir ${ARGN})
|
foreach(dir ${ARGN})
|
||||||
get_filename_component(__abs_dir "${dir}" ABSOLUTE)
|
ocv_is_opencv_directory(__is_opencv_dir "${dir}")
|
||||||
if("${__abs_dir}" MATCHES "^${OpenCV_SOURCE_DIR}"
|
if(__is_opencv_dir)
|
||||||
OR "${__abs_dir}" MATCHES "^${OpenCV_BINARY_DIR}"
|
|
||||||
OR (OPENCV_EXTRA_MODULES_PATH AND "${__abs_dir}" MATCHES "^${OPENCV_EXTRA_MODULES_PATH}"))
|
|
||||||
list(APPEND __add_before "${dir}")
|
list(APPEND __add_before "${dir}")
|
||||||
elseif(CMAKE_COMPILER_IS_GNUCXX AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS "6.0" AND
|
elseif(CMAKE_COMPILER_IS_GNUCXX AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS "6.0" AND
|
||||||
dir MATCHES "/usr/include$")
|
dir MATCHES "/usr/include$")
|
||||||
@ -151,9 +161,8 @@ function(ocv_target_include_directories target)
|
|||||||
endif()
|
endif()
|
||||||
foreach(dir ${ARGN})
|
foreach(dir ${ARGN})
|
||||||
get_filename_component(__abs_dir "${dir}" ABSOLUTE)
|
get_filename_component(__abs_dir "${dir}" ABSOLUTE)
|
||||||
if("${__abs_dir}" MATCHES "^${OpenCV_SOURCE_DIR}"
|
ocv_is_opencv_directory(__is_opencv_dir "${dir}")
|
||||||
OR "${__abs_dir}" MATCHES "^${OpenCV_BINARY_DIR}"
|
if(__is_opencv_dir)
|
||||||
OR (OPENCV_EXTRA_MODULES_PATH AND "${__abs_dir}" MATCHES "^${OPENCV_EXTRA_MODULES_PATH}"))
|
|
||||||
list(APPEND __params "${__abs_dir}")
|
list(APPEND __params "${__abs_dir}")
|
||||||
else()
|
else()
|
||||||
list(APPEND __params "${dir}")
|
list(APPEND __params "${dir}")
|
||||||
|
Loading…
Reference in New Issue
Block a user