This repository has been archived by the owner on Feb 27, 2024. It is now read-only.
forked from graeme-hill/crossguid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
97 lines (80 loc) · 3.43 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
cmake_minimum_required(VERSION 3.5.1)
project(CrossGuid VERSION 0.2.3)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/cmake")
option(CROSSGUID_TESTS "Build test runner" ON)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_DEBUG_POSTFIX "-dgb")
# Set the build type if not set
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release")
endif()
add_library(crossguid ${CMAKE_CURRENT_SOURCE_DIR}/src/guid.cpp)
set_property(TARGET crossguid PROPERTY POSITION_INDEPENDENT_CODE ON)
target_include_directories(crossguid PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>)
if(WIN32)
target_compile_definitions(crossguid PRIVATE GUID_WINDOWS)
elseif(APPLE)
find_library(CFLIB CoreFoundation)
target_link_libraries(crossguid ${CFLIB})
target_compile_definitions(crossguid PRIVATE GUID_CFUUID)
elseif(ANDROID)
# GUID_ANDROID is used in the headers, so make PUBLIC
target_compile_definitions(crossguid PUBLIC GUID_ANDROID)
else()
find_package(Libuuid REQUIRED)
if (NOT LIBUUID_FOUND)
message(FATAL_ERROR
"You might need to run 'sudo apt-get install uuid-dev' or similar")
endif()
target_include_directories(crossguid PRIVATE ${LIBUUID_INCLUDE_DIR})
target_link_libraries(crossguid ${LIBUUID_LIBRARY})
target_compile_definitions(crossguid PRIVATE GUID_LIBUUID)
endif()
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set(WARNINGS "-Wall")
elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
set(WARNINGS "-Wall")
elseif(MSVC)
set(WARNINGS "/W4")
endif()
target_compile_options(crossguid PRIVATE ${WARNINGS})
set_target_properties(crossguid
PROPERTIES
VERSION ${PROJECT_VERSION}
SOVERSION ${PROJECT_VERSION_MAJOR}
DEBUG_POSTFIX ${CMAKE_DEBUG_POSTFIX})
if (${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR})
include(GNUInstallDirs)
set(CROSSGUID_INC_INSTALL_DIR "${CMAKE_INSTALL_INCLUDEDIR}")
set(CROSSGUID_RUNTIME_INSTALL_DIR "${CMAKE_INSTALL_BINDIR}")
set(CROSSGUID_LIBRARY_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}")
set(CROSSGUID_ARCHIVE_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}")
set(CROSSGUID_FRAMEWORK_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}")
set(CROSSGUID_CMAKE_CONFIG_INSTALL_DIR "${CMAKE_INSTALL_DATADIR}/crossguid/cmake")
set(CROSSGUID_ADDITIONAL_FILES_INSTALL_DIR "${CMAKE_INSTALL_DATADIR}/crossguid")
# Install target
install(TARGETS crossguid EXPORT crossguidTargets
RUNTIME DESTINATION ${CROSSGUID_RUNTIME_INSTALL_DIR}
LIBRARY DESTINATION ${CROSSGUID_LIBRARY_INSTALL_DIR}
ARCHIVE DESTINATION ${CROSSGUID_ARCHIVE_INSTALL_DIR}
FRAMEWORK DESTINATION ${CROSSGUID_FRAMEWORK_INSTALL_DIR})
# Install headers
install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/include/"
DESTINATION ${CROSSGUID_INC_INSTALL_DIR})
# Make cmake config files for all targets
install(EXPORT crossguidTargets
DESTINATION ${CROSSGUID_CMAKE_CONFIG_INSTALL_DIR}
FILE crossguid-config.cmake)
# Install readme and license
install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE" "${CMAKE_CURRENT_SOURCE_DIR}/README.md"
DESTINATION ${CROSSGUID_ADDITIONAL_FILES_INSTALL_DIR})
configure_file(crossguid.pc.in ${PROJECT_BINARY_DIR}/crossguid.pc @ONLY)
install(FILES ${PROJECT_BINARY_DIR}/crossguid.pc DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR}/pkgconfig)
endif()
if (CROSSGUID_TESTS)
add_executable(crossguid-test test/TestMain.cpp test/Test.cpp)
target_link_libraries(crossguid-test crossguid)
endif()