forked from rxi/uuid4
-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
104 lines (85 loc) · 2.66 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
cmake_minimum_required(VERSION 3.24)
set(UUID4_SOURCES
${CMAKE_CURRENT_LIST_DIR}/src/uuid4.c
)
set(UUID4_INCLUDE_DIR
${CMAKE_CURRENT_LIST_DIR}/include
)
if(ESP_PLATFORM)
# Run special CMake commands for ESP32
idf_component_register(
SRCS ${UUID4_SOURCES}
INCLUDE_DIRS ${UUID4_INCLUDE_DIR}
)
# Copy header files to include directory and libraries to lib directory
add_custom_command(
TARGET ${COMPONENT_LIB}
POST_BUILD
COMMAND
${CMAKE_COMMAND} -E copy_directory ${UUID4_INCLUDE_DIR}
${CMAKE_SOURCE_DIR}/include
COMMAND
${CMAKE_COMMAND} -E copy $<TARGET_FILE:${COMPONENT_LIB}>
${CMAKE_SOURCE_DIR}/lib/lib${COMPONENT_NAME}.a
COMMENT "Copying built archive file and header to lib directory..."
)
endif()
project(
uuid4
VERSION 1.0.4
LANGUAGES C
)
if(NOT ESP_PLATFORM)
include(GNUInstallDirs)
add_library(uuid4-static STATIC ${UUID4_SOURCES})
add_library(uuid4-shared SHARED ${UUID4_SOURCES})
target_include_directories(uuid4-static PUBLIC
$<BUILD_INTERFACE:${UUID4_HEADERS}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)
target_include_directories(uuid4-shared PUBLIC
$<BUILD_INTERFACE:${UUID4_HEADERS}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)
# ==============
# configures the install function
# installs the lib targets (.a and .dylib to /usr/local/lib)
install(
TARGETS uuid4-static uuid4-shared
EXPORT uuid4-config
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
# installs the headers (/usr/local/include/uuid4)
install(
DIRECTORY ${UUID4_HEADERS}/${RPOJECT_NAME}
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
# ==============
# ==============
if(NOT DEFINED UUID4_AS_SUBPROJECT)
set(UUID4_AS_SUBPROJECT ON)
if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
set(UUID4_AS_SUBPROJECT OFF)
endif()
endif()
if(NOT UUID4_AS_SUBPROJECT)
export(
PACKAGE uuid4
)
# installs the cmake config file (/usr/local/lib/cmake/uuid4/uuid4-config.cmake), which is used by find_package
install(
EXPORT uuid4-config
NAMESPACE uuid4::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/uuid4
FILE uuid4-config.cmake
)
export(
EXPORT uuid4-config
NAMESPACE uuid4::
FILE uuid4-config.cmake
)
endif()
add_library(uuid4::uuid4-static ALIAS uuid4-static)
add_library(uuid4::uuid4-shared ALIAS uuid4-shared)
# ==============
endif()