-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
124 lines (103 loc) · 4.66 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
123
124
cmake_minimum_required(VERSION 2.8)
# Disregard setting PROJECT_VERSION etc. through the 'project' command
if(POLICY CMP0048)
cmake_policy(SET CMP0048 OLD)
endif()
# Disregard setting @rpath on Mac OSX
if(POLICY CMP0042)
cmake_policy(SET CMP0042 OLD)
endif()
# Set up some useful aliases
set(BASE_NAME cvx)
set(PROJECT_VERSION 0.1.0)
set(CVX_FULL_NAME ${BASE_NAME}-${PROJECT_VERSION})
project(${CVX_FULL_NAME})
# Add all project sources
set(CVX_SOURCE_PREFIX ${PROJECT_SOURCE_DIR}/src/cvx)
set(CVX_SOURCES ${CVX_SOURCE_PREFIX}/color.cpp
${CVX_SOURCE_PREFIX}/connected_component.cpp
${CVX_SOURCE_PREFIX}/draw.cpp
${CVX_SOURCE_PREFIX}/exception.cpp
#${CVX_SOURCE_PREFIX}/detail/contour.cpp
${CVX_SOURCE_PREFIX}/detail/extractor.cpp
${CVX_SOURCE_PREFIX}/detail/area_extractor.cpp
${CVX_SOURCE_PREFIX}/detail/bounding_box_extractor.cpp
${CVX_SOURCE_PREFIX}/detail/centroid_extractor.cpp
${CVX_SOURCE_PREFIX}/detail/extent_extractor.cpp
${CVX_SOURCE_PREFIX}/detail/point_extractor.cpp)
# Set up options
option(CVX_STATIC_LIBRARY "Build cvx as a static library" OFF)
option(CVX_SHARED_LIBRARY "Build cvx as a shared library" ON)
option(CVX_WITH_OPENCV "Build cvx with OpenCV support" OFF)
option(CVX_GEN_DOCS "Generate offline documention" OFF)
option(CVX_BUILD_EXAMPLES "Build all examples" ON)
option(CVX_BUILD_TESTS "Build all tests" ON)
# Modify path to locate cmake Find* modules and custom functions
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")
include(EnableCXX11)
include(${PROJECT_SOURCE_DIR}/cmake/Functions.cmake)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
#if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
# list(APPEND CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")
#endif()
add_definitions(${CMAKE_CXX_FLAGS})
#--------------------------------------------------------------------
# Generate docs
#--------------------------------------------------------------------
if(CVX_GEN_DOCS)
find_package(Doxygen QUIET)
if(DOXYGEN_FOUND)
set(CVX_DOCS_DIR "${PROJECT_SOURCE_DIR}/docs")
file(MAKE_DIRECTORY ${CVX_DOCS_DIR})
configure_file()
# Run doxygen on the project
add_custom_target(docs
COMMAND ${DOXYGEN_EXECUTABLE} ${CVX_DOXYGEN_FILE}
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})
else()
message(WARNING "Doxygen was not found, cannot generate documentation")
endif()
endif()
#--------------------------------------------------------------------
# Build examples
#--------------------------------------------------------------------
# First build examples that do not require OpenCV
if(CVX_BUILD_EXAMPLES)
if(CVX_WITH_OPENCV)
find_package(OpenCV COMPONENTS opencv_core opencv_imgproc opencv_highgui)
include_directories(${OpenCV_INCLUDE_DIRS})
if(OpenCV_FOUND)
add_definitions(-DCVX_WITH_OPENCV)
else()
message(WARNING "Unable to find OpenCV, some examples will not be built")
endif()
endif()
add_subdirectory(${PROJECT_SOURCE_DIR}/examples)
endif()
#--------------------------------------------------------------------
# Build tests
#--------------------------------------------------------------------
if(CVX_BUILD_TESTS)
enable_testing()
add_subdirectory(${PROJECT_SOURCE_DIR}/tests)
endif()
#--------------------------------------------------------------------
# Build static/shared libraries
#--------------------------------------------------------------------
if(CVX_STATIC_LIBRARY OR CVX_SHARED_LIBRARY)
set(CVX_LIB_DIR "${PROJECT_SOURCE_DIR}/lib")
file(MAKE_DIRECTORY ${CVX_LIB_DIR})
if(CVX_STATIC_LIBRARY)
add_library(${CVX_FULL_NAME}_static STATIC ${CVX_SOURCES})
set_target_properties(${CVX_FULL_NAME}_static PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${CVX_LIB_DIR})
endif()
if(CVX_SHARED_LIBRARY)
add_library(${CVX_FULL_NAME} SHARED ${CVX_SOURCES})
set_target_properties(${CVX_FULL_NAME} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CVX_LIB_DIR})
add_definitions(-DCVX_SHARED_LIBRARY)
add_definitions(-DCVX_BUILING_SHARED_LIBRARY)
endif()
if(CVX_WITH_OPENCV AND OpenCV_FOUND)
target_link_libraries(${CVX_FULL_NAME} ${OpenCV_LIBRARIES})
endif()
endif()