tinycv
Version:
Camera tiny control library
192 lines (173 loc) • 6.58 kB
Plain Text
set(SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
if(OS_WIN)
list(APPEND CUR_COMPILER_FLAGS
/MP # Multiprocess compilation
/Gy # Enable function-level linking
/GR- # Disable run-time type information
/W4 # Warning level 4
/WX # Treat warnings as errors
/wd4100 # Ignore "unreferenced formal parameter" warning
/wd4127 # Ignore "conditional expression is constant" warning
/wd4244 # Ignore "conversion possible loss of data" warning
/wd4481 # Ignore "nonstandard extension used: override" warning
/wd4512 # Ignore "assignment operator could not be generated" warning
/wd4701 # Ignore "potentially uninitialized local variable" warning
/wd4702 # Ignore "unreachable code" warning
/wd4996 # Ignore "function or variable may be unsafe" warning
/wd4389
/wd4456
/wd4275
/wd4251
/wd4189
/wd4505
)
list(APPEND CUR_COMPILER_FLAGS_DEBUG
/Zi
/RTC1 # Disable optimizations
/Od # Enable basic run-time checks
)
list(APPEND CUR_COMPILER_FLAGS_RELEASE
/O2 # Optimize for maximum speed
/Ob2 # Inline any suitable function
/GF # Enable string pooling
)
list(APPEND CUR_LINKER_FLAGS_DEBUG
/DEBUG # Generate debug information
)
list(APPEND CUR_COMPILER_DEFINES
WIN32 _WIN32 _WINDOWS # Windows platform
UNICODE _UNICODE # Unicode build
WINVER=0x0601 _WIN32_WINNT=0x601 # Targeting Windows 7
NOMINMAX # Use the standard's templated min/max
WIN32_LEAN_AND_MEAN # Exclude less common API declarations
_HAS_EXCEPTIONS=0 # Disable exceptions
TINYCV_SHARED_LIBRARY
TINYCV_COMPILE_LIBRARY
)
set(PLATFORM_SRC_DIR ${SOURCE_DIR}/windows)
set(LibLists
yuv
turbojpeg-static
strmiids)
endif()
#
# Mac OS X configuration
#
if(OS_MAC)
message("OS_MAC is")
list(APPEND CUR_COMPILER_FLAGS
-fno-strict-aliasing
-fstack-protector
-funwind-tables
-fvisibility=hidden
-Wall
-Wextra
-Wendif-labels
-Wnewline-eof
-Wno-missing-field-initializers
-Wno-unused-parameter
-Wno-unused-const-variable
)
list(APPEND CUR_CXX_COMPILER_FLAGS
-fno-exceptions # Disable exceptions
-fno-rtti # Disable real-time type information
-fobjc-call-cxx-cdtors # Call the constructor/destructor of C++ instance variables in ObjC objects
-fvisibility-inlines-hidden # Give hidden visibility to inlined class member functions
-std=gnu++11 # Use the C++11 language standard including GNU extensions
-Wno-narrowing # Don't warn about type narrowing
-Wsign-compare # Warn about mixed signed/unsigned type comparisons
)
list(APPEND CUR_COMPILER_FLAGS_DEBUG
-O0 # Disable optimizations
-g # Generate debug information
)
list(APPEND CUR_COMPILER_FLAGS_RELEASE
-O3 # Optimize for maximum speed plus a few extras
)
list(APPEND CURLINKER_FLAGS
-Wl,-search_paths_first # Search for static or shared library versions in the same pass
-Wl,-ObjC # Support creation of ObjC static libraries
-Wl,-pie # Generate position-independent code suitable for executables only
)
list(APPEND CUR_LINKER_FLAGS_RELEASE
-Wl,-dead_strip # Strip dead code
)
list(APPEND CUR_COMPILER_DEFINES
TINYCV_SHARED_LIBRARY
TINYCV_COMPILE_LIBRARY
)
set(PLATFORM_SRC_DIR ${SOURCE_DIR}/mac)
set(LibLists
yuv
turbojpeg-static
"-framework CoreFoundation"
"-framework IOKit")
execute_process(COMMAND xcode-select --print-path OUTPUT_VARIABLE XCODE_APTH OUTPUT_STRIP_TRAILING_WHITESPACE)
foreach(OS_VERSION 10.15 10.14 10.13 10.12 10.11)
set(SDK "${XCODE_PATH}/Platforms/MacOSX.platform/Developer/SDKs/MacOSX${OS_VERSION}.sdk")
if(NOT "${CMAKE_OSX_SYSROOT}" AND EXISTS "${SDK}" AND IS_DIRECTORY "${SDK}")
set(CMAKE_OSX_SYSROOT ${SDK})
endif()
endforeach()
set(TINYCV_TARGET_SDK "10.11")
list(APPEND CUR_COMPILER_FLAGS
-mmacosx-version-min=${TINYCV_TARGET_SDK})
set(CMAKE_OSX_DEPLOYMENT_TARGET ${TINYCV_TARGET_SDK})
endif()
list(APPEND CUR_COMPILER_DEFINES_RELEASE
NDEBUG _NDEBUG # Not a debug build
)
set(SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
set(BASE_DIR ${SOURCE_DIR}/base)
file(GLOB SOURCE_DIR_FILES
/base)
file(GLOB SOURCE_DIR_FILES
"${SOURCE_DIR}/*.cpp"
"${SOURCE_DIR}/*.cc"
"${SOURCE_DIR}/*.h"
"${SOURCE_DIR}/*.hpp"
)
file(GLOB BASE_FILES
"${BASE_DIR}/*.cpp"
"${BASE_DIR}/*.cc"
"${BASE_DIR}/*.h"
"${BASE_DIR}/*.hpp"
)
message("PLATFORM_SRC_DIR : ${PLATFORM_SRC_DIR}")
file(GLOB PLATFORM_SOURCE_FILES
"${PLATFORM_SRC_DIR}/*.cpp"
"${PLATFORM_SRC_DIR}/*.cc"
"${PLATFORM_SRC_DIR}/*.h"
"${PLATFORM_SRC_DIR}/*.hpp"
)
source_group("tinycv" FILES ${SOURCE_DIR_FILES})
source_group(tinycv\\\\base FILES ${BASE_FILES})
#source_group(tinycv\\\\mac FILES ${BASE_FILES})
list(APPEND SRC_FILES ${SOURCE_DIR_FILES})
list(APPEND SRC_FILES ${BASE_FILES})
list(APPEND SRC_FILES ${PLATFORM_SOURCE_FILES})
if(OS_WIN)
source_group(tinycv\\\\windows FILES ${PLATFORM_SOURCE_FILES})
set(
CMAKE_SHARED_LINKER_FLAGS_RELEASE
"${CMAKE_SHARED_LINKER_FLAGS_RELEASE} /DEBUG /OPT:REF /OPT:ICF"
)
endif()
if(OS_MAC)
source_group(tinycv\\\\mac FILES ${PLATFORM_SOURCE_FILES})
endif()
add_library(tinycv SHARED ${SRC_FILES})
set_target_properties(tinycv PROPERTIES FOLDER "tinycv")
# Compile flags
target_compile_options(tinycv PRIVATE ${CUR_COMPILER_FLAGS} ${CUR_DEMO_CXX_COMPILER_FLAGS})
target_compile_options(tinycv PRIVATE $<$<CONFIG:Debug>:${CUR_COMPILER_FLAGS_DEBUG} ${CUR_CXX_COMPILER_FLAGS_DEBUG}>)
target_compile_options(tinycv PRIVATE $<$<CONFIG:Release>:${CUR_COMPILER_FLAGS_RELEASE} ${CUR_CXX_COMPILER_FLAGS_RELEASE}>)
# Compile definitions.
target_compile_definitions(tinycv PRIVATE ${CUR_COMPILER_DEFINES})
target_compile_definitions(tinycv PRIVATE $<$<CONFIG:Debug>:${CUR_COMPILER_DEFINES_DEBUG}>)
target_compile_definitions(tinycv PRIVATE $<$<CONFIG:Release>:${CUR_COMPILER_DEFINES_RELEASE}>)
target_link_options(tinycv PRIVATE $<$<CONFIG:Debug>:${CUR_LINKER_FLAGS_DEBUG}>)
target_link_options(tinycv PRIVATE $<$<CONFIG:Release>:${CUR_LINKER_FLAGS_RELEASE}>)
message(${LibLists})
target_link_libraries(tinycv ${LibLists})
target_include_directories(tinycv PRIVATE ${SOURCE_DIR})