-
Notifications
You must be signed in to change notification settings - Fork 9
/
CMakeLists.txt
152 lines (115 loc) · 4.57 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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#################################
# RobustPalmRoi library cmake #
#################################
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
PROJECT(ROBUST_PALM_ROI)
SET(PROJECT_ROOT ${CMAKE_SOURCE_DIR})
SET(LIBRARY_NAME robust-palm-roi)
SET(${PROJECT_NAME}_VERSION_MAJOR "0")
SET(${PROJECT_NAME}_VERSION_MINOR "1")
SET(${PROJECT_NAME}_VERSION_PATCH "1")
SET(${PROJECT_NAME}_VERSION
"${${PROJECT_NAME}_VERSION_MAJOR}.${${PROJECT_NAME}_VERSION_MINOR}.${${PROJECT_NAME}_VERSION_PATCH}")
# Project Options
OPTION(${PROJECT_NAME}_BUILD_TESTS "Enable testing" OFF)
OPTION(${PROJECT_NAME}_BUILD_SHARED_LIBS "Build Shared Libraries" ON)
# Required libraries
FIND_PACKAGE(OpenCV REQUIRED)
FIND_PACKAGE(yaml-cpp REQUIRED)
IF(${PROJECT_NAME}_BUILD_TESTS)
SET(GCC_COVERAGE_COMPILE_FLAGS "-ggdb -coverage -fprofile-arcs -ftest-coverage")
SET(GCC_COVERAGE_LINK_FLAGS "-coverage -lgcov")
ENDIF()
SET(CMAKE_CXX_FLAGS "--std=c++11 ${CMAKE_CXX_FLAGS} ${GCC_COVERAGE_COMPILE_FLAGS}")
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${GCC_COVERAGE_LINK_FLAGS}")
SET(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# Sources, headers, directories and libs
SET(HEADER_DIRECTORY "include/robust-palm-roi/")
FILE(GLOB_RECURSE SRC_FILES "src/[a-zA-Z]*.cpp")
FILE(GLOB_RECURSE PUBLIC_HEADER_FILES "${HEADER_DIRECTORY}[a-zA-Z]*.h")
FILE(GLOB_RECURSE PRIVATE_HEADER_FILES "src/[a-zA-Z]*.h")
SET(LIBRARY_SOURCES
${SRC_FILES}
${PUBLIC_HEADER_FILES}
${PRIVATE_HEADER_FILES}
)
IF (CMAKE_VERSION VERSION_LESS 2.8.12)
INCLUDE_DIRECTORIES(${PROJECT_ROOT}/include)
INCLUDE_DIRECTORIES(${PROJECT_ROOT}/src)
ENDIF()
# General compilation settings
SET(${PROJECT_NAME}_C_FLAGS ${CMAKE_C_FLAGS})
SET(${PROJECT_NAME}_CXX_FLAGS ${CMAKE_CXX_FLAGS})
IF(${PROJECT_NAME}_BUILD_SHARED_LIBS)
SET(LABEL_SUFFIX "SHARED")
ELSE()
SET(LABEL_SUFFIX "STATIC")
ENDIF()
# General install settings
SET(INCLUDE_INSTALL_ROOT_DIR include)
SET(INCLUDE_INSTALL_DIR ${INCLUDE_INSTALL_ROOT_DIR}/${LIBRARY_NAME})
SET(LIB_INSTALL_DIR "lib${LIB_SUFFIX}")
SET(_INSTALL_DESTINATIONS
RUNTIME DESTINATION bin
LIBRARY DESTINATION ${LIB_INSTALL_DIR}
ARCHIVE DESTINATION ${LIB_INSTALL_DIR}
)
# Library
ADD_LIBRARY(${LIBRARY_NAME} ${LABEL_SUFFIX} ${LIBRARY_SOURCES})
SET(LINK_LIBRARIES ${OpenCV_LIBS} ${YAML_CPP_LIBRARIES})
TARGET_LINK_LIBRARIES(${LIBRARY_NAME} ${LINK_LIBRARIES})
IF(NOT CMAKE_VERSION VERSION_LESS 2.8.12)
TARGET_INCLUDE_DIRECTORIES(${LIBRARY_NAME}
PUBLIC $<BUILD_INTERFACE:${PROJECT_ROOT}/include>
$<INSTALL_INTERFACE:${INCLUDE_INSTALL_ROOT_DIR}>
PRIVATE $<BUILD_INTERFACE:${PROJECT_ROOT}/src>
)
ENDIF()
SET_TARGET_PROPERTIES(${LIBRARY_NAME} PROPERTIES
COMPILE_FLAGS "${${PROJECT_NAME}_C_FLAGS} ${${PROJECT_NAME}_CXX_FLAGS}"
)
SET_TARGET_PROPERTIES(${LIBRARY_NAME} PROPERTIES
VERSION "${${PROJECT_NAME}_VERSION}"
SOVERSION "${${PROJECT_NAME}_VERSION_MAJOR}.${${PROJECT_NAME}_VERSION_MINOR}"
PROJECT_LABEL "${LIBRARY_NAME} ${LABEL_SUFFIX}"
)
INSTALL(TARGETS ${LIBRARY_NAME} EXPORT ${LIBRARY_NAME}-targets ${_INSTALL_DESTINATIONS})
INSTALL(
DIRECTORY ${HEADER_DIRECTORY}
DESTINATION ${INCLUDE_INSTALL_DIR}
FILES_MATCHING PATTERN "*.h"
)
EXPORT(
TARGETS ${LIBRARY_NAME}
FILE "${PROJECT_BINARY_DIR}/${LIBRARY_NAME}-targets.cmake"
)
EXPORT(PACKAGE RobustPalmRoi) # RobustPalmRoiConfig.cmake
SET(EXPORT_TARGETS ${LIBRARY_NAME} CACHE INTERNAL "export targets")
SET(CONFIG_INCLUDE_DIRS "${PROJECT_ROOT}/include")
CONFIGURE_FILE(${PROJECT_ROOT}/${LIBRARY_NAME}-config.cmake.in
"${PROJECT_BINARY_DIR}/${LIBRARY_NAME}.cmake" @ONLY)
SET(INSTALL_CMAKE_DIR ${LIB_INSTALL_DIR}/cmake/${LIBRARY_NAME})
FILE(RELATIVE_PATH REL_INCLUDE_DIR
"${CMAKE_INSTALL_PREFIX}/${INSTALL_CMAKE_DIR}"
"${CMAKE_INSTALL_PREFIX}/${INCLUDE_INSTALL_ROOT_DIR}")
SET(CONFIG_INCLUDE_DIRS "\${ROBUST_PALM_ROI_CMAKE_DIR}/${REL_INCLUDE_DIR}")
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/${LIBRARY_NAME}-config.cmake.in
"${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/${LIBRARY_NAME}-config.cmake" @ONLY)
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/${LIBRARY_NAME}-config-version.cmake.in
"${PROJECT_BINARY_DIR}/${LIBRARY_NAME}-config-version.cmake" @ONLY)
INSTALL(FILES
"${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/${LIBRARY_NAME}-config.cmake"
"${PROJECT_BINARY_DIR}/${LIBRARY_NAME}-config-version.cmake"
DESTINATION "${INSTALL_CMAKE_DIR}" COMPONENT dev)
INSTALL(EXPORT ${LIBRARY_NAME}-targets DESTINATION ${INSTALL_CMAKE_DIR})
# Extras
IF(${PROJECT_NAME}_BUILD_TESTS)
ENABLE_TESTING()
ADD_SUBDIRECTORY(test)
ENDIF()
# Formatting
ADD_CUSTOM_TARGET(clang-format
COMMAND clang-format --style=file -i ${LIBRARY_SOURCES}
COMMENT "Running clang-format"
VERBATIM
)