1- cmake_minimum_required (VERSION 2.8)
2- project (autowiring)
1+ cmake_minimum_required (VERSION 3.0)
2+ include (version .cmake)
3+ project (autowiring VERSION ${autowiring_VERSION} )
34include (CTest)
45
5- # TODO: Use the VERSION attribute for the "project" setting instead after upgrading
6- # the cmake_minimum_required to version 3.0
7- set (autowiring_VERSION_MAJOR 0)
8- set (autowiring_VERSION_MINOR 1)
9- set (autowiring_VERSION_PATCH 0)
10-
116# Determine whether Autowiring has been embedded in another project
127if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR )
138 set (AUTOWIRING_IS_EMBEDDED)
@@ -31,25 +26,22 @@ else()
3126 endif ()
3227endif ()
3328
34- # Macro for deprecated functionality needed to comply with c++98 std implementations
35- if ( NOT USE_LIBCXX )
36- add_definitions (-DAUTOWIRING_UNSAFE_HASHTABLE )
29+ if ( NOT WIN32 )
30+ set ( CMAKE_CXX_FLAGS "-std=c++11" )
31+ set (CMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LIBRARY "libstdc++" )
3732endif ()
38-
3933if (USE_LIBCXX)
4034 # Clang needs special additional flags to build with C++11
41- if ("${CMAKE_CXX_COMPILER_ID} " STREQUAL "Clang" )
35+ if ("${CMAKE_CXX_COMPILER_ID} " STREQUAL "AppleClang" )
36+ # Apple needs us to tell it that we're using libc++, or it will try to use libstdc++ instead
37+ message ("AppleClang C++11" )
38+ set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++" )
39+ set (CMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LIBRARY "libc++" )
40+ elseif ("${CMAKE_CXX_COMPILER_ID} " STREQUAL "Clang" )
4241 message ("Clang C++11" )
43- if (APPLE )
44- # Apple needs us to tell it that we're using libc++, or it will try to use libstdc++ instead
45- set (CMAKE_CXX_FLAGS "-std=c++11 -stdlib=libc++" )
46- else ()
47- set (CMAKE_CXX_FLAGS "-std=c++11" )
48- set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lstdc++" )
49- endif ()
42+ set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lstdc++" )
5043 elseif ("${CMAKE_CXX_COMPILER_ID} " STREQUAL "GNU" )
5144 message ("GCC C++11" )
52- set (CMAKE_CXX_FLAGS "-std=c++11" )
5345 endif ()
5446endif ()
5547
@@ -64,17 +56,34 @@ set(AUTOWIRING_BUILD_AUTONET_DEFAULT ON)
6456get_filename_component (AUTOWIRING_ROOT_DIR . ABSOLUTE )
6557if (AUTOWIRING_IS_EMBEDDED)
6658 set (AUTOWIRING_BUILD_TESTS_DEFAULT OFF )
67- set (AUTOWIRING_BUILD_EXAMPLES_DEFAULT OFF )
6859else ()
6960 set (AUTOWIRING_BUILD_TESTS_DEFAULT ON )
70- set (AUTOWIRING_BUILD_EXAMPLES_DEFAULT ON )
7161
7262 # All of our binaries go to one place: The binaries output directory. We only want to tinker
7363 # with this if we're building by ourselves, otherwise we just do whatever the enclosing project
7464 # wants us to do.
75- set (EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR} /bin)
65+ set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR} /bin)
66+
67+ # Libraries not only all wind up in the libraries directory, but we also keep them all together
68+ # here by putting them in the same place, regardless of whether they are debug or release. This
69+ # makes globbing them together much easier.
70+ set (CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR} /lib)
71+ set (CMAKE_LIBRARY_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR} /lib)
72+ set (CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR} /lib)
73+ set (CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR} /lib)
74+ set (CMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR} /lib)
75+ set (CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR} /lib)
76+ endif ()
77+
78+ # 64-bit installations should suffix with 64
79+ if (${CMAKE_SIZEOF_VOID_P} STREQUAL 8)
80+ set (CMAKE_DEBUG_POSTFIX "64" )
81+ set (CMAKE_RELEASE_POSTFIX "64" )
7682endif ()
7783
84+ # Postfix on all debug libraries should be "d"
85+ set (CMAKE_DEBUG_POSTFIX d${CMAKE_DEBUG_POSTFIX} )
86+
7887option (AUTOWIRING_BUILD_TESTS "Build Autowiring unit tests" ${AUTOWIRING_BUILD_TESTS_DEFAULT} )
7988function (add_googletest dirname)
8089 if (AUTOWIRING_BUILD_TESTS)
@@ -107,45 +116,85 @@ include_directories(
107116 contrib
108117 contrib/websocketpp
109118)
110- add_subdirectory (src)
111- add_subdirectory (contrib)
112-
113- # Build examples
114- option (AUTOWIRING_BUILD_EXAMPLES "Build Autowiring examples" ${AUTOWIRING_BUILD_EXAMPLES_DEFAULT} )
115- if (AUTOWIRING_BUILD_EXAMPLES)
116- add_subdirectory (examples)
117- endif ()
118119
119120# CMake configurations
121+ if (${CMAKE_SIZEOF_VOID_P} STREQUAL 8)
122+ set (autowiring_ARCHITECTURE "64" )
123+ else ()
124+ set (autowiring_ARCHITECTURE "32" )
125+ endif ()
120126configure_file (autowiring-config.cmake.in autowiring-config.cmake @ONLY)
121127configure_file (autowiring-configVersion.cmake.in autowiring-configVersion.cmake @ONLY)
128+ configure_file (AutowiringConfig.h.in ${PROJECT_SOURCE_DIR} /autowiring/AutowiringConfig.h @ONLY)
129+
130+ # Recurse through source directories
131+ add_subdirectory (src)
132+
133+ # Export library
134+ export (EXPORT AutowiringTargets FILE AutowiringTargets.cmake NAMESPACE Autowiring::)
122135
123136# Only attempt to do anything with cpack if we're being built stand-alone
124137if (NOT AUTOWIRING_IS_EMBEDDED)
125138 # Install autowiring-config.cmake and autowiring-configVersion.cmake
126- install (FILES
127- "${CMAKE_BINARY_DIR} /contrib/autowiring/autowiring-config.cmake"
128- "${CMAKE_BINARY_DIR} /contrib/autowiring/autowiring-configVersion.cmake"
129- DESTINATION "${CMAKE_SOURCE_DIR} /cmake"
139+ install (FILES
140+ "${CMAKE_CURRENT_BINARY_DIR} /autowiring-config.cmake"
141+ "${CMAKE_CURRENT_BINARY_DIR} /autowiring-configVersion.cmake"
142+ DESTINATION "cmake"
143+ COMPONENT autowiring
144+ )
145+
146+ # Install public header files
147+ install (
148+ DIRECTORY ${PROJECT_SOURCE_DIR} /autowiring/
149+ DESTINATION include /autowiring
130150 COMPONENT autowiring
151+ FILES_MATCHING PATTERN "*.h"
131152 )
132153
154+ # Targets file is needed in order to describe how to link Autowiring to the rest of the system
155+ install (EXPORT AutowiringTargets FILE AutowiringTargets.cmake COMPONENT autowiring NAMESPACE Autowiring:: DESTINATION cmake CONFIGURATIONS ${CMAKE_CONFIGURATION_TYPES} )
156+
157+ # 64-bit installations get a different upgrade GUID
158+ if (CMAKE_SIZEOF_VOID_P STREQUAL 8)
159+ set (autowiring_GUID_LAST_CHAR E)
160+ else ()
161+ set (autowiring_GUID_LAST_CHAR D)
162+ endif ()
163+
133164 # This is the upgrade GUID. Part of the GUID is derived from the major version number. Any time
134165 # the major version number is adjusted, the upgrade GUID changes. This allows multiple versions
135166 # of the same product to be installed on a user's system at the same time, but also means that
136167 # manual uninstallation of older versions is required.
137168 #
138169 # For more information on the rationale for this process, see the discussion on semantic versioning
139170 # found at http://semver.org/
140- SET (CPACK_WIX_UPGRADE_GUID "{060E5EDD-229${autowiring_VERSION_MAJOR} -4AD8-BAFA-A303D5696A2D }" )
171+ SET (CPACK_WIX_UPGRADE_GUID "{060E5EDD-229${autowiring_VERSION_MAJOR} -4AD8-BAFA-A303D5696A2 ${autowiring_GUID_LAST_CHAR} }" )
141172
142173 # Need a custom wix installation template so that we update the CMake package registry correctly
143174 # Only really needed on Windows; Mac and Linux have pretty good default search behavior, so we
144175 # leave those alone.
145- SET (CPACK_WIX_TEMPLATE autowiring.wxs)
176+ SET (CPACK_WIX_TEMPLATE "${CMAKE_SOURCE_DIR} /autowiring.wxs" )
177+ SET (CPACK_MONOLITHIC_INSTALL ON )
178+
179+ # Run the script that will grab the debug and release configurations and install them during packaging
180+ set (CPACK_INSTALL_COMMANDS
181+ "${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR} --config Debug"
182+ "${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR} --config Release"
183+ "${CMAKE_COMMAND} -DBUILD_TYPE=Debug -P \\\" ${CMAKE_SOURCE_DIR} /cmake_package.cmake\\\" "
184+ "${CMAKE_COMMAND} -DBUILD_TYPE=Release -P \\\" ${CMAKE_SOURCE_DIR} /cmake_package.cmake\\\" "
185+ )
186+
187+ # Pick the generator in an appropriate way
188+ if (WIN32 )
189+ set (CPACK_GENERATOR WIX ZIP)
190+ elseif (APPLE )
191+ # TODO: Add Bundle as a generator here
192+ set (CPACK_GENERATOR TGZ)
193+ else ()
194+ set (CPACK_GENERATOR TGZ DEB)
195+ endif ()
146196
147- # Packaging stuff, if an installer is being made insteadINCLUDE(InstallRequiredSystemLibraries)
148- SET (CPACK_GENERATOR "WIX" )
197+ # Packaging stuff, if an installer is being made instead
149198 SET (CPACK_PACKAGE_VENDOR "Leap Motion" )
150199 SET (CPACK_PACKAGE_CONTACT "cmercenary@gmail.com" )
151200 SET (CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR} /README.md" )
@@ -155,6 +204,6 @@ if(NOT AUTOWIRING_IS_EMBEDDED)
155204 SET (CPACK_PACKAGE_VERSION_MINOR "${autowiring_VERSION_MINOR} " )
156205 SET (CPACK_PACKAGE_VERSION_PATCH "${autowiring_VERSION_PATCH} " )
157206 SET (CPACK_PACKAGE_INSTALL_REGISTRY_KEY "autowiring" )
158- SET (CPACK_PACKAGE_INSTALL_DIRECTORY "autowiring ${CMake_VERSION_MAJOR} . ${CMake_VERSION_MINOR} " )
207+ SET (CPACK_PACKAGE_INSTALL_DIRECTORY "autowiring" )
159208 INCLUDE (CPack)
160209endif ()
0 commit comments