2010-05-12 01:44:00 +08:00
|
|
|
# this is template for a OpenCV module
|
|
|
|
macro(define_opencv_module name)
|
2010-12-29 00:24:23 +08:00
|
|
|
|
|
|
|
project(opencv_${name})
|
2010-05-12 01:44:00 +08:00
|
|
|
|
2010-12-29 00:24:23 +08:00
|
|
|
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/include"
|
|
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/src"
|
|
|
|
"${CMAKE_CURRENT_BINARY_DIR}")
|
|
|
|
|
|
|
|
foreach(d ${ARGN})
|
|
|
|
if(${d} MATCHES "opencv_")
|
|
|
|
if(${d} MATCHES "opencv_lapack")
|
|
|
|
else()
|
|
|
|
string(REPLACE "opencv_" "${CMAKE_CURRENT_SOURCE_DIR}/../" d_dir ${d})
|
|
|
|
include_directories("${d_dir}/include")
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
endforeach()
|
|
|
|
|
|
|
|
file(GLOB lib_srcs "src/*.cpp")
|
|
|
|
file(GLOB lib_int_hdrs "src/*.h*")
|
2011-05-03 16:13:50 +08:00
|
|
|
if(COMMAND get_module_external_sources)
|
|
|
|
get_module_external_sources(${name})
|
|
|
|
endif()
|
2010-12-29 00:24:23 +08:00
|
|
|
source_group("Src" FILES ${lib_srcs} ${lib_int_hdrs})
|
|
|
|
|
|
|
|
file(GLOB lib_hdrs "include/opencv2/${name}/*.h*")
|
|
|
|
source_group("Include" FILES ${lib_hdrs})
|
|
|
|
|
|
|
|
set(the_target "opencv_${name}")
|
|
|
|
|
|
|
|
add_library(${the_target} ${lib_srcs} ${lib_hdrs} ${lib_int_hdrs})
|
|
|
|
|
|
|
|
# For dynamic link numbering convenions
|
|
|
|
set_target_properties(${the_target} PROPERTIES
|
|
|
|
VERSION ${OPENCV_VERSION}
|
|
|
|
SOVERSION ${OPENCV_SOVERSION}
|
2011-05-07 05:45:48 +08:00
|
|
|
OUTPUT_NAME "${the_target}${OPENCV_DLLVERSION}"
|
|
|
|
)
|
2011-05-11 21:37:20 +08:00
|
|
|
if(SOLUTION_FOLDERS_ENABLED)
|
|
|
|
set_target_properties(${the_target} PROPERTIES FOLDER "modules")
|
|
|
|
endif()
|
2011-05-07 05:45:48 +08:00
|
|
|
|
2011-05-11 21:50:17 +08:00
|
|
|
if (OPENCV_BUILD_SHARED_LIB)
|
|
|
|
if(MSVC)
|
|
|
|
set_target_properties(${the_target} PROPERTIES DEFINE_SYMBOL CVAPI_EXPORTS)
|
|
|
|
else()
|
|
|
|
add_definitions(-DCVAPI_EXPORTS)
|
|
|
|
endif()
|
2011-05-07 05:45:48 +08:00
|
|
|
endif()
|
2010-12-29 00:24:23 +08:00
|
|
|
|
|
|
|
# Additional target properties
|
|
|
|
set_target_properties(${the_target} PROPERTIES
|
|
|
|
DEBUG_POSTFIX "${OPENCV_DEBUG_POSTFIX}"
|
|
|
|
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib/"
|
|
|
|
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin/"
|
|
|
|
INSTALL_NAME_DIR "${CMAKE_INSTALL_PREFIX}/lib"
|
|
|
|
)
|
|
|
|
|
2011-04-30 18:42:33 +08:00
|
|
|
if(PCHSupport_FOUND AND USE_PRECOMPILED_HEADERS)
|
2011-04-06 22:31:03 +08:00
|
|
|
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()
|
|
|
|
|
2010-12-29 00:24:23 +08:00
|
|
|
# Add the required libraries for linking:
|
|
|
|
target_link_libraries(${the_target} ${OPENCV_LINKER_LIBS} ${IPP_LIBS} ${ARGN})
|
|
|
|
|
|
|
|
if(MSVC)
|
|
|
|
if(CMAKE_CROSSCOMPILING)
|
|
|
|
set_target_properties(${the_target} PROPERTIES
|
|
|
|
LINK_FLAGS "/NODEFAULTLIB:secchk"
|
|
|
|
)
|
|
|
|
endif()
|
|
|
|
set_target_properties(${the_target} PROPERTIES
|
2011-04-26 20:09:27 +08:00
|
|
|
LINK_FLAGS "/NODEFAULTLIB:libc /DEBUG"
|
2010-12-29 00:24:23 +08:00
|
|
|
)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# Dependencies of this target:
|
|
|
|
add_dependencies(${the_target} ${ARGN})
|
|
|
|
|
|
|
|
install(TARGETS ${the_target}
|
|
|
|
RUNTIME DESTINATION bin COMPONENT main
|
|
|
|
LIBRARY DESTINATION lib COMPONENT main
|
|
|
|
ARCHIVE DESTINATION lib COMPONENT main)
|
|
|
|
|
|
|
|
install(FILES ${lib_hdrs}
|
|
|
|
DESTINATION include/opencv2/${name}
|
|
|
|
COMPONENT main)
|
|
|
|
|
2011-04-11 22:47:06 +08:00
|
|
|
if(BUILD_TESTS AND EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/test)
|
2010-12-29 00:24:23 +08:00
|
|
|
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/include"
|
|
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/test"
|
2011-02-10 04:55:11 +08:00
|
|
|
"${CMAKE_CURRENT_BINARY_DIR}")
|
2010-12-29 00:24:23 +08:00
|
|
|
|
2011-02-10 04:55:11 +08:00
|
|
|
set(test_deps opencv_${name} ${ARGN} opencv_ts opencv_highgui ${EXTRA_${the_target}_DEPS})
|
|
|
|
foreach(d ${test_deps})
|
2010-12-29 00:24:23 +08:00
|
|
|
if(${d} MATCHES "opencv_")
|
|
|
|
if(${d} MATCHES "opencv_lapack")
|
|
|
|
else()
|
|
|
|
string(REPLACE "opencv_" "${CMAKE_CURRENT_SOURCE_DIR}/../" d_dir ${d})
|
|
|
|
include_directories("${d_dir}/include")
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
endforeach()
|
|
|
|
|
|
|
|
file(GLOB test_srcs "test/*.cpp")
|
|
|
|
file(GLOB test_hdrs "test/*.h*")
|
2011-02-18 20:23:18 +08:00
|
|
|
|
|
|
|
source_group("Src" FILES ${test_srcs})
|
|
|
|
source_group("Include" FILES ${test_hdrs})
|
2010-12-29 00:24:23 +08:00
|
|
|
|
2011-02-10 04:55:11 +08:00
|
|
|
set(the_target "opencv_test_${name}")
|
2010-12-29 00:24:23 +08:00
|
|
|
|
|
|
|
add_executable(${the_target} ${test_srcs} ${test_hdrs})
|
|
|
|
|
2011-04-30 18:42:33 +08:00
|
|
|
if(PCHSupport_FOUND AND USE_PRECOMPILED_HEADERS)
|
2011-01-11 20:14:31 +08:00
|
|
|
set(pch_header ${CMAKE_CURRENT_SOURCE_DIR}/test/test_precomp.hpp)
|
2010-12-29 00:24:23 +08:00
|
|
|
if(${CMAKE_GENERATOR} MATCHES "Visual*" OR ${CMAKE_GENERATOR} MATCHES "Xcode*")
|
|
|
|
if(${CMAKE_GENERATOR} MATCHES "Visual*")
|
2011-01-11 20:14:31 +08:00
|
|
|
set(${the_target}_pch "test/test_precomp.cpp")
|
2010-12-29 00:24:23 +08:00
|
|
|
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
|
|
|
|
set_target_properties(${the_target} PROPERTIES
|
|
|
|
DEBUG_POSTFIX "${OPENCV_DEBUG_POSTFIX}"
|
|
|
|
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin/"
|
|
|
|
)
|
2011-05-11 21:37:20 +08:00
|
|
|
|
|
|
|
if(SOLUTION_FOLDERS_ENABLED)
|
|
|
|
set_target_properties(${the_target} PROPERTIES FOLDER "tests")
|
|
|
|
endif()
|
2010-12-29 00:24:23 +08:00
|
|
|
|
2011-02-10 04:55:11 +08:00
|
|
|
add_dependencies(${the_target} ${test_deps})
|
2010-12-29 00:24:23 +08:00
|
|
|
|
|
|
|
# Add the required libraries for linking:
|
2011-02-10 04:55:11 +08:00
|
|
|
target_link_libraries(${the_target} ${OPENCV_LINKER_LIBS} ${test_deps})
|
2010-12-29 00:24:23 +08:00
|
|
|
|
|
|
|
enable_testing()
|
|
|
|
get_target_property(LOC ${the_target} LOCATION)
|
|
|
|
add_test(${the_target} "${LOC}")
|
|
|
|
|
|
|
|
if(WIN32)
|
|
|
|
install(TARGETS ${the_target} RUNTIME DESTINATION bin COMPONENT main)
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
2010-05-12 01:44:00 +08:00
|
|
|
endmacro()
|