-
Notifications
You must be signed in to change notification settings - Fork 37
/
CMakeLists.txt
110 lines (92 loc) · 4.21 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
# --------------------------------------------------------------
# SRBA project
# See docs online: https://github.com/MRPT/srba
# --------------------------------------------------------------
# Root CMake script
cmake_minimum_required(VERSION 2.8.3)
project(SRBA_ALL)
# =====================================
# 1. Set-up CMake and find pkgs
# =====================================
SET(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS 1)
# Declare lib version:
# Look for: "#define SRBA_VERSION 0xABC"
file(READ "${SRBA_ALL_SOURCE_DIR}/include/srba/version.h" STR_HPP)
STRING(REGEX MATCHALL "SRBA_VERSION.*0x[0-9,A-F]+" CMAKE_VERSION_LINE "${STR_HPP}")
STRING(REGEX MATCHALL "0x[0-9,A-F]+" SRBA_VERSION_HEX "${CMAKE_VERSION_LINE}")
STRING(REGEX REPLACE "0x(.).*" "\\1" CMAKE_SRBA_VERSION_NUMBER_MAJOR "${SRBA_VERSION_HEX}" )
STRING(REGEX REPLACE "0x.(.).*" "\\1" CMAKE_SRBA_VERSION_NUMBER_MINOR "${SRBA_VERSION_HEX}" )
STRING(REGEX REPLACE "0x..(.).*" "\\1" CMAKE_SRBA_VERSION_NUMBER_PATCH "${SRBA_VERSION_HEX}" )
SET(CMAKE_SRBA_FULL_VERSION "${CMAKE_SRBA_VERSION_NUMBER_MAJOR}.${CMAKE_SRBA_VERSION_NUMBER_MINOR}.${CMAKE_SRBA_VERSION_NUMBER_PATCH}")
MESSAGE(STATUS "Configuring for SRBA v${CMAKE_SRBA_FULL_VERSION}")
file(WRITE "${SRBA_ALL_SOURCE_DIR}/docs/version" ${CMAKE_SRBA_FULL_VERSION}) # For use in Latex docs
IF (CMAKE_VERSION VERSION_GREATER 2.8.0)
SET(ENABLE_SOLUTION_FOLDERS ON CACHE BOOL "Group projects under virtual folders of the compiler IDE (e.g. VisualStudio)")
MARK_AS_ADVANCED(ENABLE_SOLUTION_FOLDERS)
ENDIF ()
if (ENABLE_SOLUTION_FOLDERS)
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
set_property(GLOBAL PROPERTY PREDEFINED_TARGETS_FOLDER "CMakeTargets")
endif ()
if(COMMAND cmake_policy)
cmake_policy(SET CMP0003 NEW) # Required by CMake 2.7+
endif(COMMAND cmake_policy)
SET(EXECUTABLE_OUTPUT_PATH "${${PROJECT_NAME}_BINARY_DIR}/bin")
# Shared options between GCC and CLANG:
if (${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang" OR CMAKE_COMPILER_IS_GNUCXX)
# We need pthread's
IF (UNIX AND NOT APPLE)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
ENDIF()
IF(NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2")
ENDIF()
endif()
# =====================================
# 2. Install, config files, etc.
# =====================================
# Generate CMake config file for usage without "make install"
# ---------------------------------------------------------------
SET(THE_INCLUDE_DIRECTORIES "${SRBA_ALL_SOURCE_DIR}/include")
CONFIGURE_FILE(
"${SRBA_ALL_SOURCE_DIR}/srba-config.cmake.in"
"${SRBA_ALL_BINARY_DIR}/srba-config.cmake" @ONLY IMMEDIATE )
SET(SRBA_DIR ${SRBA_ALL_BINARY_DIR} CACHE PATH "Directory for SRBA-config.cmake" )
MARK_AS_ADVANCED(SRBA_DIR)
# =====================================
# 3. Declare targets
# =====================================
# C++ Library: It's hdr only, so we don't need to compile it!
include_directories("${SRBA_ALL_SOURCE_DIR}/include/")
# Anyway, we define a "dummy" target so all headers appear in the Development GUI (Visual Studio, QtCreator,...)
# A custom target (needs no real compiling)
FILE(GLOB srba_hdrs
"${SRBA_ALL_SOURCE_DIR}/include/*.h"
"${SRBA_ALL_SOURCE_DIR}/include/srba/*.h"
)
SOURCE_GROUP("Hdrs: Public API" FILES ${srba_hdrs})
FILE(GLOB srba_hdrs_models "${SRBA_ALL_SOURCE_DIR}/include/srba/models/*.h")
SOURCE_GROUP("Hdrs: models" FILES ${srba_hdrs_models})
FILE(GLOB srba_hdrs_impl "${SRBA_ALL_SOURCE_DIR}/include/srba/impl/*.h")
SOURCE_GROUP("Hdrs: impl" FILES ${srba_hdrs_impl})
FILE(GLOB srba_hdrs_ecps "${SRBA_ALL_SOURCE_DIR}/include/srba/ecps/*.h")
SOURCE_GROUP("Hdrs: ecps" FILES ${srba_hdrs_ecps})
set(srba_all_srcs ${srba_hdrs} ${srba_hdrs_models} ${srba_hdrs_impl} ${srba_hdrs_ecps})
add_custom_target(srba DEPENDS ${srba_all_srcs} SOURCES ${srba_all_srcs})
set_target_properties(srba PROPERTIES FOLDER "SRBA lib")
# Install!
# Apps
SET(BUILD_SRBA_APPS ON CACHE BOOL "Build SRBA apps?")
if (BUILD_SRBA_APPS)
add_subdirectory(apps)
endif()
# Examples
SET(BUILD_SRBA_EXAMPLES ON CACHE BOOL "Build SRBA tutorial and example C++ programs?")
if (BUILD_SRBA_EXAMPLES)
add_subdirectory(examples)
endif()
# tests
SET(BUILD_SRBA_TESTS ON CACHE BOOL "Build SRBA unit tests?")
if (BUILD_SRBA_TESTS)
add_subdirectory(tests)
endif()