Commit 3aea74d4 authored by Andrey Kamaev's avatar Andrey Kamaev

Fixed precompiled headers support (fixed formatting, fixed dependencies generation)

parent 22142246
#opencv precompiled headers macro (can add pch to modules and tests)
#this macro must be called after any "add_definitions" commands, otherwise precompiled headers will not work
macro(add_opencv_precompiled_headers the_target)
if(the_target MATCHES opencv_test_)
SET(pch_name "test/test_precomp")
else()
SET(pch_name "src/precomp")
endif()
set(pch_header "${CMAKE_CURRENT_SOURCE_DIR}/${pch_name}.hpp")
if(PCHSupport_FOUND AND USE_PRECOMPILED_HEADERS AND EXISTS "${pch_header}")
if(CMAKE_GENERATOR MATCHES Visual)
set(${the_target}_pch "${CMAKE_CURRENT_SOURCE_DIR}/${pch_name}.cpp")
add_native_precompiled_header(${the_target} ${pch_header})
elseif(CMAKE_GENERATOR MATCHES Xcode)
add_native_precompiled_header(${the_target} ${pch_header})
elseif(CMAKE_COMPILER_IS_GNUCXX AND CMAKE_GENERATOR MATCHES Makefiles)
add_precompiled_header(${the_target} ${pch_header})
endif()
endif()
endmacro()
# this is template for a OpenCV module # this is template for a OpenCV module
macro(define_opencv_module name) macro(define_opencv_module name)
...@@ -8,20 +29,19 @@ macro(define_opencv_module name) ...@@ -8,20 +29,19 @@ macro(define_opencv_module name)
"${CMAKE_CURRENT_BINARY_DIR}") "${CMAKE_CURRENT_BINARY_DIR}")
foreach(d ${ARGN}) foreach(d ${ARGN})
if(${d} MATCHES "opencv_") if(d MATCHES "opencv_")
if(${d} MATCHES "opencv_lapack") string(REPLACE "opencv_" "${CMAKE_CURRENT_SOURCE_DIR}/../" d_dir ${d})
else() include_directories("${d_dir}/include")
string(REPLACE "opencv_" "${CMAKE_CURRENT_SOURCE_DIR}/../" d_dir ${d})
include_directories("${d_dir}/include")
endif()
endif() endif()
endforeach() endforeach()
file(GLOB lib_srcs "src/*.cpp") file(GLOB lib_srcs "src/*.cpp")
file(GLOB lib_int_hdrs "src/*.h*") file(GLOB lib_int_hdrs "src/*.h*")
if(COMMAND get_module_external_sources) if(COMMAND get_module_external_sources)
get_module_external_sources(${name}) get_module_external_sources(${name})
endif() endif()
source_group("Src" FILES ${lib_srcs} ${lib_int_hdrs}) source_group("Src" FILES ${lib_srcs} ${lib_int_hdrs})
file(GLOB lib_hdrs "include/opencv2/${name}/*.h*") file(GLOB lib_hdrs "include/opencv2/${name}/*.h*")
...@@ -66,17 +86,7 @@ macro(define_opencv_module name) ...@@ -66,17 +86,7 @@ macro(define_opencv_module name)
INSTALL_NAME_DIR lib INSTALL_NAME_DIR lib
) )
if(PCHSupport_FOUND AND USE_PRECOMPILED_HEADERS) add_opencv_precompiled_headers(${the_target})
set(pch_header ${CMAKE_CURRENT_SOURCE_DIR}/src/precomp.hpp)
if(${CMAKE_GENERATOR} MATCHES "Visual*" OR ${CMAKE_GENERATOR} MATCHES "Xcode*")
if(${CMAKE_GENERATOR} MATCHES "Visual*")
set(${the_target}_pch "src/precomp.cpp")
endif()
add_native_precompiled_header(${the_target} ${pch_header})
elseif(CMAKE_COMPILER_IS_GNUCXX AND ${CMAKE_GENERATOR} MATCHES ".*Makefiles")
add_precompiled_header(${the_target} ${pch_header})
endif()
endif()
# Add the required libraries for linking: # Add the required libraries for linking:
target_link_libraries(${the_target} ${OPENCV_LINKER_LIBS} ${IPP_LIBS} ${ARGN}) target_link_libraries(${the_target} ${OPENCV_LINKER_LIBS} ${IPP_LIBS} ${ARGN})
...@@ -111,12 +121,9 @@ macro(define_opencv_module name) ...@@ -111,12 +121,9 @@ macro(define_opencv_module name)
set(test_deps opencv_${name} ${ARGN} opencv_ts opencv_highgui ${EXTRA_${the_target}_DEPS}) set(test_deps opencv_${name} ${ARGN} opencv_ts opencv_highgui ${EXTRA_${the_target}_DEPS})
foreach(d ${test_deps}) foreach(d ${test_deps})
if(${d} MATCHES "opencv_") if(d MATCHES "opencv_")
if(${d} MATCHES "opencv_lapack") string(REPLACE "opencv_" "${CMAKE_CURRENT_SOURCE_DIR}/../" d_dir ${d})
else() include_directories("${d_dir}/include")
string(REPLACE "opencv_" "${CMAKE_CURRENT_SOURCE_DIR}/../" d_dir ${d})
include_directories("${d_dir}/include")
endif()
endif() endif()
endforeach() endforeach()
...@@ -130,24 +137,14 @@ macro(define_opencv_module name) ...@@ -130,24 +137,14 @@ macro(define_opencv_module name)
add_executable(${the_target} ${test_srcs} ${test_hdrs}) add_executable(${the_target} ${test_srcs} ${test_hdrs})
if(PCHSupport_FOUND AND USE_PRECOMPILED_HEADERS) add_opencv_precompiled_headers(${the_target})
set(pch_header ${CMAKE_CURRENT_SOURCE_DIR}/test/test_precomp.hpp)
if(${CMAKE_GENERATOR} MATCHES "Visual*" OR ${CMAKE_GENERATOR} MATCHES "Xcode*")
if(${CMAKE_GENERATOR} MATCHES "Visual*")
set(${the_target}_pch "test/test_precomp.cpp")
endif()
add_native_precompiled_header(${the_target} ${pch_header})
elseif(CMAKE_COMPILER_IS_GNUCXX AND ${CMAKE_GENERATOR} MATCHES ".*Makefiles")
add_precompiled_header(${the_target} ${pch_header})
endif()
endif()
# Additional target properties # Additional target properties
set_target_properties(${the_target} PROPERTIES set_target_properties(${the_target} PROPERTIES
DEBUG_POSTFIX "${OPENCV_DEBUG_POSTFIX}" DEBUG_POSTFIX "${OPENCV_DEBUG_POSTFIX}"
RUNTIME_OUTPUT_DIRECTORY "${EXECUTABLE_OUTPUT_PATH}" RUNTIME_OUTPUT_DIRECTORY "${EXECUTABLE_OUTPUT_PATH}"
) )
if(ENABLE_SOLUTION_FOLDERS) if(ENABLE_SOLUTION_FOLDERS)
set_target_properties(${the_target} PROPERTIES FOLDER "tests") set_target_properties(${the_target} PROPERTIES FOLDER "tests")
endif() endif()
...@@ -165,5 +162,5 @@ macro(define_opencv_module name) ...@@ -165,5 +162,5 @@ macro(define_opencv_module name)
# install(TARGETS ${the_target} RUNTIME DESTINATION bin COMPONENT main) # install(TARGETS ${the_target} RUNTIME DESTINATION bin COMPONENT main)
#endif() #endif()
endif() endif()
endmacro() endmacro()
This diff is collapsed.
...@@ -6,8 +6,8 @@ project(${the_target}) ...@@ -6,8 +6,8 @@ project(${the_target})
set(DEPS "opencv_core" "opencv_imgproc" "opencv_objdetect" "opencv_features2d" "opencv_flann" "opencv_calib3d") #"opencv_features2d" "opencv_flann" "opencv_objdetect" - only headers needed set(DEPS "opencv_core" "opencv_imgproc" "opencv_objdetect" "opencv_features2d" "opencv_flann" "opencv_calib3d") #"opencv_features2d" "opencv_flann" "opencv_objdetect" - only headers needed
set(OPENCV_LINKER_LIBS ${OPENCV_LINKER_LIBS} opencv_gpu) set(OPENCV_LINKER_LIBS ${OPENCV_LINKER_LIBS} opencv_gpu)
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/include" include_directories("${CMAKE_CURRENT_SOURCE_DIR}/include"
"${CMAKE_CURRENT_SOURCE_DIR}/src/cuda" "${CMAKE_CURRENT_SOURCE_DIR}/src/cuda"
"${CMAKE_CURRENT_SOURCE_DIR}/src" "${CMAKE_CURRENT_SOURCE_DIR}/src"
"${CMAKE_CURRENT_BINARY_DIR}") "${CMAKE_CURRENT_BINARY_DIR}")
...@@ -85,18 +85,6 @@ endforeach() ...@@ -85,18 +85,6 @@ endforeach()
add_library(${the_target} ${lib_srcs} ${lib_hdrs} ${lib_int_hdrs} ${lib_cuda} ${lib_cuda_hdrs} ${lib_device_hdrs} ${ncv_srcs} ${ncv_hdrs} ${ncv_cuda} ${cuda_objs}) add_library(${the_target} ${lib_srcs} ${lib_hdrs} ${lib_int_hdrs} ${lib_cuda} ${lib_cuda_hdrs} ${lib_device_hdrs} ${ncv_srcs} ${ncv_hdrs} ${ncv_cuda} ${cuda_objs})
if(PCHSupport_FOUND)
set(pch_header ${CMAKE_CURRENT_SOURCE_DIR}/src/precomp.hpp)
if(${CMAKE_GENERATOR} MATCHES "Visual*" OR ${CMAKE_GENERATOR} MATCHES "Xcode*")
if(${CMAKE_GENERATOR} MATCHES "Visual*")
set(${the_target}_pch "src/precomp.cpp")
endif()
add_native_precompiled_header(${the_target} ${pch_header})
elseif(CMAKE_COMPILER_IS_GNUCXX AND ${CMAKE_GENERATOR} MATCHES ".*Makefiles")
add_precompiled_header(${the_target} ${pch_header})
endif()
endif()
# For dynamic link numbering convenions # For dynamic link numbering convenions
set_target_properties(${the_target} PROPERTIES set_target_properties(${the_target} PROPERTIES
VERSION ${OPENCV_VERSION} VERSION ${OPENCV_VERSION}
...@@ -112,36 +100,38 @@ if (BUILD_SHARED_LIBS) ...@@ -112,36 +100,38 @@ if (BUILD_SHARED_LIBS)
if (MSVC) if (MSVC)
set_target_properties(${the_target} PROPERTIES DEFINE_SYMBOL CVAPI_EXPORTS) set_target_properties(${the_target} PROPERTIES DEFINE_SYMBOL CVAPI_EXPORTS)
else() else()
add_definitions(-DCVAPI_EXPORTS) add_definitions(-DCVAPI_EXPORTS)
endif() endif()
endif() endif()
add_opencv_precompiled_headers(${the_target})
# Additional target properties # Additional target properties
set_target_properties(${the_target} PROPERTIES set_target_properties(${the_target} PROPERTIES
DEBUG_POSTFIX "${OPENCV_DEBUG_POSTFIX}" DEBUG_POSTFIX "${OPENCV_DEBUG_POSTFIX}"
ARCHIVE_OUTPUT_DIRECTORY ${LIBRARY_OUTPUT_PATH} ARCHIVE_OUTPUT_DIRECTORY ${LIBRARY_OUTPUT_PATH}
RUNTIME_OUTPUT_DIRECTORY ${EXECUTABLE_OUTPUT_PATH} RUNTIME_OUTPUT_DIRECTORY ${EXECUTABLE_OUTPUT_PATH}
INSTALL_NAME_DIR lib INSTALL_NAME_DIR lib
) )
# Add the required libraries for linking: # Add the required libraries for linking:
target_link_libraries(${the_target} ${OPENCV_LINKER_LIBS} ${IPP_LIBS} ${DEPS} ) target_link_libraries(${the_target} ${OPENCV_LINKER_LIBS} ${IPP_LIBS} ${DEPS} )
if (HAVE_CUDA) if (HAVE_CUDA)
target_link_libraries(${the_target} ${CUDA_LIBRARIES}) target_link_libraries(${the_target} ${CUDA_LIBRARIES})
CUDA_ADD_CUFFT_TO_TARGET(${the_target}) CUDA_ADD_CUFFT_TO_TARGET(${the_target})
unset(CUDA_npp_LIBRARY CACHE) unset(CUDA_npp_LIBRARY CACHE)
find_cuda_helper_libs(npp) find_cuda_helper_libs(npp)
target_link_libraries(${the_target} ${CUDA_npp_LIBRARY}) target_link_libraries(${the_target} ${CUDA_npp_LIBRARY})
endif() endif()
if(MSVC) if(MSVC)
if(CMAKE_CROSSCOMPILING) if(CMAKE_CROSSCOMPILING)
set_target_properties(${the_target} PROPERTIES LINK_FLAGS "/NODEFAULTLIB:secchk") set_target_properties(${the_target} PROPERTIES LINK_FLAGS "/NODEFAULTLIB:secchk")
endif() endif()
set_target_properties(${the_target} PROPERTIES LINK_FLAGS "/NODEFAULTLIB:libc") set_target_properties(${the_target} PROPERTIES LINK_FLAGS "/NODEFAULTLIB:libc")
endif() endif()
# Dependencies of this target: # Dependencies of this target:
...@@ -181,11 +171,8 @@ if(BUILD_TESTS AND EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/test) ...@@ -181,11 +171,8 @@ if(BUILD_TESTS AND EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/test)
set(test_deps opencv_${name} opencv_ts opencv_highgui opencv_calib3d ${DEPS}) set(test_deps opencv_${name} opencv_ts opencv_highgui opencv_calib3d ${DEPS})
foreach(d ${test_deps}) foreach(d ${test_deps})
if(${d} MATCHES "opencv_") if(${d} MATCHES "opencv_")
if(${d} MATCHES "opencv_lapack") string(REPLACE "opencv_" "${CMAKE_CURRENT_SOURCE_DIR}/../" d_dir ${d})
else() include_directories("${d_dir}/include")
string(REPLACE "opencv_" "${CMAKE_CURRENT_SOURCE_DIR}/../" d_dir ${d})
include_directories("${d_dir}/include")
endif()
endif() endif()
endforeach() endforeach()
...@@ -203,17 +190,7 @@ if(BUILD_TESTS AND EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/test) ...@@ -203,17 +190,7 @@ if(BUILD_TESTS AND EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/test)
add_executable(${the_test_target} ${test_srcs} ${test_hdrs} ${nvidia}) add_executable(${the_test_target} ${test_srcs} ${test_hdrs} ${nvidia})
if(PCHSupport_FOUND) add_opencv_precompiled_headers(${the_test_target})
set(pch_header ${CMAKE_CURRENT_SOURCE_DIR}/test/test_precomp.hpp)
if(${CMAKE_GENERATOR} MATCHES "Visual*" OR ${CMAKE_GENERATOR} MATCHES "Xcode*")
if(${CMAKE_GENERATOR} MATCHES "Visual*")
set(${the_test_target}_pch "test/test_precomp.cpp")
endif()
add_native_precompiled_header(${the_test_target} ${pch_header})
elseif(CMAKE_COMPILER_IS_GNUCXX AND ${CMAKE_GENERATOR} MATCHES ".*Makefiles")
add_precompiled_header(${the_test_target} ${pch_header})
endif()
endif()
# Additional target properties # Additional target properties
set_target_properties(${the_test_target} PROPERTIES set_target_properties(${the_test_target} PROPERTIES
...@@ -223,7 +200,7 @@ if(BUILD_TESTS AND EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/test) ...@@ -223,7 +200,7 @@ if(BUILD_TESTS AND EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/test)
if(ENABLE_SOLUTION_FOLDERS) if(ENABLE_SOLUTION_FOLDERS)
set_target_properties(${the_test_target} PROPERTIES FOLDER "tests") set_target_properties(${the_test_target} PROPERTIES FOLDER "tests")
endif() endif()
add_dependencies(${the_test_target} ${test_deps}) add_dependencies(${the_test_target} ${test_deps})
......
...@@ -263,21 +263,11 @@ if (BUILD_SHARED_LIBS) ...@@ -263,21 +263,11 @@ if (BUILD_SHARED_LIBS)
if(MSVC) if(MSVC)
set_target_properties(${the_target} PROPERTIES DEFINE_SYMBOL CVAPI_EXPORTS) set_target_properties(${the_target} PROPERTIES DEFINE_SYMBOL CVAPI_EXPORTS)
else() else()
add_definitions(-DCVAPI_EXPORTS) add_definitions(-DCVAPI_EXPORTS)
endif() endif()
endif() endif()
if(PCHSupport_FOUND AND USE_PRECOMPILED_HEADERS) add_opencv_precompiled_headers(${the_target})
set(pch_header ${CMAKE_CURRENT_SOURCE_DIR}/src/precomp.hpp)
if(${CMAKE_GENERATOR} MATCHES "Visual*" OR ${CMAKE_GENERATOR} MATCHES "Xcode*")
if(${CMAKE_GENERATOR} MATCHES "Visual*")
set(${the_target}_pch "src/precomp.cpp")
endif()
add_native_precompiled_header(${the_target} ${pch_header})
elseif(CMAKE_COMPILER_IS_GNUCXX AND ${CMAKE_GENERATOR} MATCHES ".*Makefiles")
add_precompiled_header(${the_target} ${pch_header})
endif()
endif()
# For dynamic link numbering convenions # For dynamic link numbering convenions
if(NOT ANDROID) if(NOT ANDROID)
...@@ -288,7 +278,7 @@ if(NOT ANDROID) ...@@ -288,7 +278,7 @@ if(NOT ANDROID)
) )
endif() endif()
set_target_properties(${the_target} PROPERTIES OUTPUT_NAME "${the_target}${OPENCV_DLLVERSION}" ) set_target_properties(${the_target} PROPERTIES OUTPUT_NAME "${the_target}${OPENCV_DLLVERSION}" )
# Additional target properties # Additional target properties
set_target_properties(${the_target} PROPERTIES set_target_properties(${the_target} PROPERTIES
...@@ -398,27 +388,17 @@ if(BUILD_TESTS) ...@@ -398,27 +388,17 @@ if(BUILD_TESTS)
add_executable(${the_target} ${test_srcs} ${test_hdrs}) add_executable(${the_target} ${test_srcs} ${test_hdrs})
if(PCHSupport_FOUND AND USE_PRECOMPILED_HEADERS) add_opencv_precompiled_headers(${the_target})
set(pch_header ${CMAKE_CURRENT_SOURCE_DIR}/test/test_precomp.hpp)
if(${CMAKE_GENERATOR} MATCHES "Visual*" OR ${CMAKE_GENERATOR} MATCHES "Xcode*")
if(${CMAKE_GENERATOR} MATCHES "Visual*")
set(${the_target}_pch "test/test_precomp.cpp")
endif()
add_native_precompiled_header(${the_target} ${pch_header})
elseif(CMAKE_COMPILER_IS_GNUCXX AND ${CMAKE_GENERATOR} MATCHES ".*Makefiles")
add_precompiled_header(${the_target} ${pch_header})
endif()
endif()
# Additional target properties # Additional target properties
set_target_properties(${the_target} PROPERTIES set_target_properties(${the_target} PROPERTIES
DEBUG_POSTFIX "${OPENCV_DEBUG_POSTFIX}" DEBUG_POSTFIX "${OPENCV_DEBUG_POSTFIX}"
RUNTIME_OUTPUT_DIRECTORY "${EXECUTABLE_OUTPUT_PATH}" RUNTIME_OUTPUT_DIRECTORY "${EXECUTABLE_OUTPUT_PATH}"
) )
if(ENABLE_SOLUTION_FOLDERS) if(ENABLE_SOLUTION_FOLDERS)
set_target_properties(${the_target} PROPERTIES FOLDER "tests") set_target_properties(${the_target} PROPERTIES FOLDER "tests")
endif() endif()
add_dependencies(${the_target} ${test_deps}) add_dependencies(${the_target} ${test_deps})
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment