forked from leapmotion/autowiring
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
156 lines (139 loc) · 6.09 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
153
154
155
156
cmake_minimum_required(VERSION 2.8)
project(autowiring)
include(CTest)
# TODO: Use the VERSION attribute for the "project" setting instead after upgrading
# the cmake_minimum_required to version 3.0
set(autowiring_VERSION_MAJOR 0)
set(autowiring_VERSION_MINOR 1)
set(autowiring_VERSION_PATCH 1)
# Determine whether Autowiring has been embedded in another project
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
set(AUTOWIRING_IS_EMBEDDED)
else()
set(AUTOWIRING_IS_EMBEDDED "TRUE")
endif()
# If there's an external libraries directory path, use it as a search prefix
if(EXTERNAL_LIBRARY_DIR)
list(APPEND CMAKE_PREFIX_PATH ${EXTERNAL_LIBRARY_DIR})
list(APPEND CMAKE_INCLUDE_PATH ${EXTERNAL_LIBRARY_DIR})
endif()
# Offer option for USE_LIBCXX only if not defined by enclosing project
# Check for existing definition of USE_LIBCXX
if(NOT DEFINED USE_LIBCXX)
option(USE_LIBCXX "Build Autowiring using c++11" ON)
else()
if(NOT USE_LIBCXX)
message("Parent project has set USE_LIBCXX = OFF -> Build Autowiring using c++98")
endif()
endif()
if(USE_LIBCXX)
# Clang needs special additional flags to build with C++11
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
message("Clang C++11")
if (APPLE)
# Apple needs us to tell it that we're using libc++, or it will try to use libstdc++ instead
set(CMAKE_CXX_FLAGS "-std=c++11 -stdlib=libc++")
else()
set(CMAKE_CXX_FLAGS "-std=c++11")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lstdc++")
endif()
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
message("GCC C++11")
set(CMAKE_CXX_FLAGS "-std=c++11")
endif()
endif()
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
include(CMakeModules/pch.cmake)
set(AUTOWIRING_BUILD_AUTONET_DEFAULT ON)
# We don't build tests unless we're being built by ourselves in our own source tree
# When we're embedded in someone else's subtree, it's not likely that they will want
# us to bring all of our unit tests in with us. Though, if they do desire this, they
# can always set the AUTOWIRING_BUILD_TESTS flag
get_filename_component(AUTOWIRING_ROOT_DIR . ABSOLUTE)
if(AUTOWIRING_IS_EMBEDDED)
set(AUTOWIRING_BUILD_TESTS_DEFAULT OFF)
set(AUTOWIRING_BUILD_EXAMPLES_DEFAULT OFF)
else()
set(AUTOWIRING_BUILD_TESTS_DEFAULT ON)
set(AUTOWIRING_BUILD_EXAMPLES_DEFAULT ON)
# All of our binaries go to one place: The binaries output directory. We only want to tinker
# with this if we're building by ourselves, otherwise we just do whatever the enclosing project
# wants us to do.
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
endif()
option(AUTOWIRING_BUILD_TESTS "Build Autowiring unit tests" ${AUTOWIRING_BUILD_TESTS_DEFAULT})
function(add_googletest dirname)
if(AUTOWIRING_BUILD_TESTS)
add_subdirectory(${dirname})
endif()
endfunction()
function(rewrite_header_paths target_SRC_VAR)
# All include files are located in /autowiring from here, so prepend that to all sources
set(SRCS_TEMP ${${target_SRC_VAR}})
set(SRCS)
foreach(i ${SRCS_TEMP})
string(REGEX MATCH ".*\\.h$" hfile ${i})
if(hfile)
list(APPEND SRCS ${PROJECT_SOURCE_DIR}/autowiring/${i})
else()
list(APPEND SRCS ${i})
endif()
endforeach()
set(${target_SRC_VAR} ${SRCS} PARENT_SCOPE)
endfunction()
# We have unit test projects via googletest, they're added in the places where they are defined
enable_testing()
# We want everyone to be compilable as though they have this root project in their search tree,
# because external entities will likely have just that
include_directories(
.
contrib
contrib/websocketpp
)
add_subdirectory(src)
add_subdirectory(contrib)
# Build examples
option(AUTOWIRING_BUILD_EXAMPLES "Build Autowiring examples" ${AUTOWIRING_BUILD_EXAMPLES_DEFAULT})
if(AUTOWIRING_BUILD_EXAMPLES)
add_subdirectory(examples)
endif()
# CMake configurations
configure_file(autowiring-config.cmake.in autowiring-config.cmake @ONLY)
configure_file(autowiring-configVersion.cmake.in autowiring-configVersion.cmake @ONLY)
configure_file(autowiring-config.h.in ${PROJECT_SOURCE_DIR}/autowiring/AutowiringConfig.h @ONLY)
# Only attempt to do anything with cpack if we're being built stand-alone
if(NOT AUTOWIRING_IS_EMBEDDED)
# Install autowiring-config.cmake and autowiring-configVersion.cmake
install (FILES
"${CMAKE_CURRENT_BINARY_DIR}/autowiring-config.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/autowiring-configVersion.cmake"
DESTINATION "cmake"
COMPONENT autowiring
)
install(EXPORT AutowiringTargets FILE AutowiringTargets.cmake NAMESPACE Autowiring:: DESTINATION cmake)
# This is the upgrade GUID. Part of the GUID is derived from the major version number. Any time
# the major version number is adjusted, the upgrade GUID changes. This allows multiple versions
# of the same product to be installed on a user's system at the same time, but also means that
# manual uninstallation of older versions is required.
#
# For more information on the rationale for this process, see the discussion on semantic versioning
# found at http://semver.org/
SET(CPACK_WIX_UPGRADE_GUID "{060E5EDD-229${autowiring_VERSION_MAJOR}-4AD8-BAFA-A303D5696A2D}")
# Need a custom wix installation template so that we update the CMake package registry correctly
# Only really needed on Windows; Mac and Linux have pretty good default search behavior, so we
# leave those alone.
SET(CPACK_WIX_TEMPLATE autowiring.wxs)
# Packaging stuff, if an installer is being made instead
INCLUDE(InstallRequiredSystemLibraries)
SET(CPACK_PACKAGE_VENDOR "Leap Motion")
SET(CPACK_PACKAGE_CONTACT "cmercenary@gmail.com")
SET(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/README.md")
SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Autowiring")
SET(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE.txt")
SET(CPACK_PACKAGE_VERSION_MAJOR "${autowiring_VERSION_MAJOR}")
SET(CPACK_PACKAGE_VERSION_MINOR "${autowiring_VERSION_MINOR}")
SET(CPACK_PACKAGE_VERSION_PATCH "${autowiring_VERSION_PATCH}")
SET(CPACK_PACKAGE_INSTALL_REGISTRY_KEY "autowiring")
SET(CPACK_PACKAGE_INSTALL_DIRECTORY "autowiring ${CMake_VERSION_MAJOR}.${CMake_VERSION_MINOR}")
INCLUDE(CPack)
endif()