Browse Source

Add some compile options, add vulkan dependency export (#2062)

* vulkan cmake export templete

* 1) vulkan cmake dependency export. 2) support opencv_world import. 3) add BUILD_WITH_STATIC_CRT option

* Threads dependency

* NCNN_BUILD_WITH_STATIC_CRT option

* we do not support cmake before version 3.15 for option NCNN_BUILD_WITH_STATIC_CRT
tags/20200916
youzainn GitHub 5 years ago
parent
commit
3b1b41ec0b
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 50 additions and 4 deletions
  1. +13
    -0
      CMakeLists.txt
  2. +22
    -1
      cmake/ncnnConfig.cmake.in
  3. +10
    -2
      examples/CMakeLists.txt
  4. +5
    -1
      tools/quantize/CMakeLists.txt

+ 13
- 0
CMakeLists.txt View File

@@ -17,8 +17,21 @@ if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE release CACHE STRING "Choose the type of build" FORCE)
endif()

if(CMAKE_MAJOR_VERSION GREATER_EQUAL 3 AND CMAKE_MINOR_VERSION GREATER_EQUAL 15)
# enable CMAKE_MSVC_RUNTIME_LIBRARY
cmake_policy(SET CMP0091 NEW)
endif()

project(ncnn)

if(MSVC AND CMAKE_MAJOR_VERSION GREATER_EQUAL 3 AND CMAKE_MINOR_VERSION GREATER_EQUAL 15)
option(NCNN_BUILD_WITH_STATIC_CRT "Enables use of statically linked CRT for statically linked ncnn" OFF)
if(NCNN_BUILD_WITH_STATIC_CRT)
# cmake before version 3.15 not work
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
endif()
endif()

option(NCNN_OPENMP "openmp support" ON)
option(NCNN_STDIO "load model from external file" ON)
option(NCNN_STRING "plain and verbose string" ON)


+ 22
- 1
cmake/ncnnConfig.cmake.in View File

@@ -1,5 +1,7 @@
set(NCNN_OPENMP @NCNN_OPENMP@)
set(NCNN_VULKAN @NCNN_VULKAN@)
set(NCNN_VULKAN_ONLINE_SPIRV @NCNN_VULKAN_ONLINE_SPIRV@)
set(NCNN_SYSTEM_GLSLANG @NCNN_SYSTEM_GLSLANG@)

if(NCNN_OPENMP)
find_package(OpenMP)
@@ -7,6 +9,25 @@ endif()

if(NCNN_VULKAN)
find_package(Vulkan REQUIRED)
endif()
if(NCNN_VULKAN_ONLINE_SPIRV)
if(NCNN_SYSTEM_GLSLANG)
set(GLSLANG_TARGET_DIR "@GLSLANG_TARGET_DIR@")
else()
set(GLSLANG_TARGET_DIR "${CMAKE_CURRENT_LIST_DIR}/..")
endif(NCNN_SYSTEM_GLSLANG)
find_package(Threads)
include(${GLSLANG_TARGET_DIR}/OSDependentTargets.cmake)
include(${GLSLANG_TARGET_DIR}/OGLCompilerTargets.cmake)
if(EXISTS "${GLSLANG_TARGET_DIR}/HLSLTargets.cmake")
# hlsl support can be optional
include("${GLSLANG_TARGET_DIR}/HLSLTargets.cmake")
endif()
include(${GLSLANG_TARGET_DIR}/glslangTargets.cmake)
include(${GLSLANG_TARGET_DIR}/SPIRVTargets.cmake)
endif(NCNN_VULKAN_ONLINE_SPIRV)
endif(NCNN_VULKAN)

include(${CMAKE_CURRENT_LIST_DIR}/ncnn.cmake)

+ 10
- 2
examples/CMakeLists.txt View File

@@ -1,18 +1,26 @@

macro(ncnn_add_example name)
add_executable(${name} ${name}.cpp)
target_include_directories(${name} PRIVATE ${OpenCV_INCLUDE_DIRS})
target_link_libraries(${name} PRIVATE ncnn ${OpenCV_LIBS})

# add test to a virtual project group
set_property(TARGET ${name} PROPERTY FOLDER "examples")
endmacro()

find_package(OpenCV QUIET COMPONENTS core highgui imgproc imgcodecs videoio)
find_package(OpenCV QUIET COMPONENTS opencv_world)
if(NOT OpenCV_FOUND)
find_package(OpenCV QUIET COMPONENTS core highgui imgproc imgcodecs videoio)
endif()
if(NOT OpenCV_FOUND)
find_package(OpenCV QUIET COMPONENTS core highgui imgproc)
endif()

if(OpenCV_FOUND)
message(STATUS "OpenCV library: ${OpenCV_INSTALL_PATH}")
message(STATUS " version: ${OpenCV_VERSION}")
message(STATUS " libraries: ${OpenCV_LIBS}")
message(STATUS " include path: ${OpenCV_INCLUDE_DIRS}")
if(${OpenCV_VERSION_MAJOR} GREATER 3)
set(CMAKE_CXX_STANDARD 11)
endif()


+ 5
- 1
tools/quantize/CMakeLists.txt View File

@@ -1,4 +1,7 @@
find_package(OpenCV QUIET COMPONENTS core highgui imgproc imgcodecs)
find_package(OpenCV QUIET COMPONENTS opencv_world)
if(NOT OpenCV_FOUND)
find_package(OpenCV QUIET COMPONENTS core highgui imgproc imgcodecs)
endif()
if(NOT OpenCV_FOUND)
find_package(OpenCV QUIET COMPONENTS core highgui imgproc)
endif()
@@ -6,6 +9,7 @@ endif()
if(OpenCV_FOUND)
add_executable(ncnn2table ncnn2table.cpp)
target_compile_definitions(ncnn2table PRIVATE -DOpenCV_VERSION_MAJOR=${OpenCV_VERSION_MAJOR})
target_include_directories(ncnn2table PRIVATE ${OpenCV_INCLUDE_DIRS})
target_link_libraries(ncnn2table PRIVATE ncnn ${OpenCV_LIBS})

add_executable(ncnn2int8 ncnn2int8.cpp)


Loading…
Cancel
Save