-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathCMakeLists.txt
122 lines (103 loc) · 3.58 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
cmake_minimum_required(VERSION 3.15)
# Disable inplace builds to prevent source tree corruption.
if(" ${CMAKE_SOURCE_DIR}" STREQUAL " ${CMAKE_BINARY_DIR}")
message(FATAL_ERROR "FATAL: Building inplace are not allowed. You should create a separate directory for Building.")
endif()
# Set cmake_install_prefix path
if(NOT DEFINED CMAKE_INSTALL_PREFIX)
set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/install" CACHE PATH "Installation Directory")
endif()
message(STATUS "CMAKE_INSTALL_PREFIX = ${CMAKE_INSTALL_PREFIX}")
if(NOT DEFINED CMAKE_INSTALL_PREFIX)
set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/install" CACHE PATH "Installation Directory")
endif()
if(NOT DEFINED SHUFACV_VERSION)
string(TIMESTAMP SHUFACV_VERSION "%Y%m%d")
endif()
set(SHUFACV_VERSION_MAJOR 0)
set(SHUFACV_VERSION_MINOR 0)
#set(SHUFACV_VERSION_PATCH ${SHUFACV_VERSION})
set(SHUFACV_VERSION_PATCH 0)
set(SHUFACV_VERSION_STRING ${SHUFACV_VERSION_MAJOR}.${SHUFACV_VERSION_MINOR}.${SHUFACV_VERSION_PATCH})
if(APPLE OR IOS)
# macos / ios only accepts a.b.c.d.e where a=24bit b/c/d/e=10bit
# 20201228 to 20.12.28
set(SHUFACV_VERSION_STRING ${SHUFACV_VERSION_MAJOR}.${SHUFACV_VERSION_MINOR}.${SHUFACV_VERSION_YEAR}.0.0)
endif()
message(STATUS "SHUFACV_VERSION_STRING = ${SHUFACV_VERSION_STRING}")
configure_file(version.h.in ${CMAKE_CURRENT_BINARY_DIR}/version.h)
if(CMAKE_TOOLCHAIN_FILE)
# get absolute path, but get_filename_component ABSOLUTE only refer with source dir, so find_file here :(
get_filename_component(CMAKE_TOOLCHAIN_FILE_NAME ${CMAKE_TOOLCHAIN_FILE} NAME)
find_file(CMAKE_TOOLCHAIN_FILE ${CMAKE_TOOLCHAIN_FILE_NAME} PATHS ${CMAKE_SOURCE_DIR} NO_DEFAULT_PATH)
message(STATUS "CMAKE_TOOLCHAIN_FILE = ${CMAKE_TOOLCHAIN_FILE}")
endif()
if(NOT DEFINED CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release CACHE STRING "Set build type")
endif()
project(shufacv)
option(SHUFACV_TEST "Build unit tests?" OFF)
option(SHUFACV_COVERAGE "Build for coverage?" OFF)
if( (CMAKE_CXX_COMPILER_ID MATCHES "GNU") OR (CMAKE_CXX_COMPILER_ID MATCHES "Clang"))
add_compile_options(-Wextra -Wall -Wno-unused)
endif()
set(CMAKE_CXX_STANDARD 11)
aux_source_directory(${CMAKE_SOURCE_DIR}/shufaCV SHUFACV_SRCS)
# Build sfcv shared library
add_library(
${PROJECT_NAME}
SHARED
${SHUFACV_SRCS}
)
target_include_directories(
${PROJECT_NAME}
PUBLIC ${CMAKE_SOURCE_DIR}/shufaCV ${CMAKE_CURRENT_BINARY_DIR}
)
# Build sfcv static library
add_library(
${PROJECT_NAME}_static
STATIC
${SHUFACV_SRCS}
)
target_include_directories(
${PROJECT_NAME}_static
PUBLIC ${CMAKE_SOURCE_DIR}/shufaCV ${CMAKE_CURRENT_BINARY_DIR}
)
if(SHUFACV_COVERAGE)
target_compile_options(shufacv_static PUBLIC -coverage -fprofile-arcs -ftest-coverage)
target_link_libraries(shufacv_static PUBLIC -coverage -lgcov)
endif()
# Report summary
include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/summary.cmake")
# Add install files
set_target_properties(
${PROJECT_NAME}_static
PROPERTIES
OUTPUT_NAME ${PROJECT_NAME}
)
set_target_properties(
${PROJECT_NAME}
PROPERTIES
SOVERSION ${SHUFACV_VERSION_STRING}
)
install(
TARGETS ${PROJECT_NAME}
DESTINATION lib
)
install(
TARGETS ${PROJECT_NAME}_static
DESTINATION lib
)
# Unit tests
if(SHUFACV_TEST)
enable_testing()
find_package(GTest REQUIRED)
macro(shufacv_add_test name)
add_executable(test_${name} tests/test_${name}.cpp)
target_link_libraries(test_${name} PRIVATE shufacv_static GTest::gtest GTest::gtest_main)
target_include_directories(test_${name} PUBLIC ${CMAKE_CURRENT_BINARY_DIR})
gtest_add_tests(TARGET test_${name})
endmacro()
shufacv_add_test(mat)
shufacv_add_test(version)
endif()