Repository for OpenCV's extra modules
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

144 lines
5.4 KiB

set(the_description "Modern Deep Learning module")
if(${CMAKE_VERSION} VERSION_LESS 3.2)
message(STATUS "Module opencv_dnn_modern disabled because CMake version is less than 3.2")
ocv_module_disable(dnn_modern)
return()
endif()
cmake_policy(SET CMP0028 OLD)
# Using cmake scripts and modules
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
# ----------------------------------------------------------------------------
# MODULE REQUIREMENTS
# ----------------------------------------------------------------------------
find_package(TinyDNN QUIET)
include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
if(NOT TinyDNN_FOUND)
message(STATUS "Module opencv_dnn_modern disabled because tiny-dnn was not found")
ocv_module_disable(dnn_modern)
return()
elseif(NOT COMPILER_SUPPORTS_CXX11)
message(STATUS "Module opencv_dnn_modern disabled because your compiler does not support C++11")
ocv_module_disable(dnn_modern)
return()
elseif(APPLE_FRAMEWORK OR ANDROID)
message(STATUS "Module opencv_dnn_modern disabled because you are not under Linux or Win")
ocv_module_disable(dnn_modern)
return()
endif()
# ----------------------------------------------------------------------------
# OPTIMIZATION OPTIONS
# ----------------------------------------------------------------------------
option(TINYDNN_USE_SSE "Build tiny-dnn with SSE library support" ON)
option(TINYDNN_USE_AVX "Build tiny-dnn with AVX library support" ON)
option(TINYDNN_USE_TBB "Build tiny-dnn with TBB library support" OFF)
option(TINYDNN_USE_OMP "Build tiny-dnn with OMP library support" OFF)
option(TINYDNN_USE_NNPACK "Build tiny-dnn with NNPACK library support" OFF)
if(TINYDNN_USE_TBB AND HAVE_TBB)
add_definitions(-DCNN_USE_TBB)
elseif(NOT TINYDNN_USE_TBB AND
TINYDNN_USE_OMP AND HAVE_OPENMP)
add_definitions(-DCNN_USE_OMP)
endif()
if(TINYDNN_USE_NNPACK)
find_package(NNPACK REQUIRED)
add_definitions(-DCNN_USE_NNPACK)
include_directories(SYSTEM ${NNPACK_INCLUDE_DIR})
include_directories(SYSTEM ${NNPACK_INCLUDE_DIR}/../third-party/pthreadpool/include)
list(APPEND REQUIRED_LIBRARIES ${NNPACK_LIB})
endif()
# we need to disable seializer unless we import cereal
add_definitions(-DCNN_NO_SERIALIZATION)
# NOTE: In case that proto files already exist,
# this is not needed anymore.
find_package(Protobuf)
list(APPEND REQUIRED_LIBRARIES ${PROTOBUF_LIBRARIES})
####
# Setup the compiler options
# set c++ standard to c++11.
# Note: not working on CMake 2.8. We assume that user has
# a compiler with C++11 support.
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
message(STATUS "C++11 support has been enabled by default.")
# Unix
if(CMAKE_COMPILER_IS_GNUCXX OR MINGW OR
CMAKE_CXX_COMPILER_ID MATCHES "Clang")
include(CheckCXXCompilerFlag)
check_cxx_compiler_flag("-msse3" COMPILER_HAS_SSE_FLAG)
check_cxx_compiler_flag("-mavx" COMPILER_HAS_AVX_FLAG)
check_cxx_compiler_flag("-mavx2" COMPILER_HAS_AVX2_FLAG)
check_cxx_compiler_flag("-mfma" COMPILER_HAS_AVX2_FLAG)
# set Streaming SIMD Extension (SSE) instructions
if(USE_SSE AND COMPILER_HAS_SSE_FLAG)
add_definitions(-DCNN_USE_SSE)
set(EXTRA_C_FLAGS "${EXTRA_C_FLAGS} -msse3")
endif(USE_SSE AND COMPILER_HAS_SSE_FLAG)
# set Advanced Vector Extensions (AVX)
if(USE_AVX AND COMPILER_HAS_AVX_FLAG)
add_definitions(-DCNN_USE_AVX)
set(EXTRA_C_FLAGS "${EXTRA_C_FLAGS} -mavx")
endif(USE_AVX AND COMPILER_HAS_AVX_FLAG)
# set Advanced Vector Extensions 2 (AVX2)
if(USE_AVX2 AND COMPILER_HAS_AVX2_FLAG)
add_definitions(-DCNN_USE_AVX2)
set(EXTRA_C_FLAGS "${EXTRA_C_FLAGS} -mavx2 -mfma -march=core-avx2")
endif(USE_AVX2 AND COMPILER_HAS_AVX2_FLAG)
# include extra flags to the compiler
# TODO: add info about those flags.
set(EXTRA_C_FLAGS "${EXTRA_C_FLAGS} -Wall -Wpedantic -Wno-narrowing")
set(EXTRA_C_FLAGS_RELEASE "${EXTRA_C_FLAGS_RELEASE} -O3")
set(EXTRA_C_FLAGS_DEBUG "${EXTRA_C_FLAGS_DEBUG} -g3 -pthread")
elseif(MSVC)
if(USE_SSE)
add_definitions(-DCNN_USE_SSE)
set(EXTRA_C_FLAGS "${EXTRA_C_FLAGS} /arch:SSE2")
endif(USE_SSE)
if(USE_AVX)
add_definitions(-DCNN_USE_AVX)
set(EXTRA_C_FLAGS "${EXTRA_C_FLAGS} /arch:AVX")
endif(USE_AVX)
if(USE_AVX2)
add_definitions(-DCNN_USE_AVX2)
set(EXTRA_C_FLAGS "${EXTRA_C_FLAGS} /arch:AVX2")
endif(USE_AVX2)
# include specific flags for release and debug modes.
set(EXTRA_C_FLAGS_RELEASE "${EXTRA_C_FLAGS_RELEASE}
/Ox /Oi /Ot /Oy /GL /fp:fast /GS-")
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /LTCG")
set(EXTRA_C_FLAGS_DEBUG "${EXTRA_C_FLAGS_DEBUG}")
set(EXTRA_C_FLAGS "${EXTRA_C_FLAGS} /W4 /bigobj")
# this is fine
add_definitions(-D _CRT_SECURE_NO_WARNINGS)
add_definitions(-D _SCL_SECURE_NO_WARNINGS)
# prolly powerless with header-only project
set(EXTRA_C_FLAGS "${EXTRA_C_FLAGS} /MP")
endif()
# ----------------------------------------------------------------------------
# DNN-MODERN MODULE
# ----------------------------------------------------------------------------
ocv_define_module(dnn_modern opencv_core opencv_imgproc opencv_imgcodecs WRAP python)
ocv_target_link_libraries(${the_module} ${REQUIRED_LIBRARIES})
ocv_target_include_directories(${the_module} ${TINYDNN_INCLUDE_DIRS})
target_compile_options(${the_module} PRIVATE "-Wno-error=non-virtual-dtor")