forked from corrosion-rs/corrosion
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
86 lines (73 loc) · 2.42 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
cmake_minimum_required(VERSION 3.22)
project(Corrosion
# Official releases will be major.minor.patch. When the `tweak` field is
# set it indicates that we are on a commit, that is not a officially
# tagged release. Users don't need to care about this, it is mainly to
# clearly see in configure logs which version was used, without needing to
# rely on `git`, since Corrosion may be installed or otherwise packaged.
VERSION 0.99.99 # 1.0-pre-release
LANGUAGES NONE
HOMEPAGE_URL "https://corrosion-rs.github.io/corrosion/"
)
# ==== Corrosion Configuration ====
option(
CORROSION_BUILD_TESTS
"Build Corrosion test project"
${PROJECT_IS_TOP_LEVEL}
)
if (PROJECT_IS_TOP_LEVEL)
# We need to enable a language for corrosions test to work.
# For projects using corrosion this is not needed
enable_language(C)
endif()
# This little bit self-hosts the Corrosion toolchain to build the generator
# tool.
#
# It is strongly encouraged to install Corrosion separately and use
# `find_package(Corrosion REQUIRED)` instead if that works with your workflow.
option(CORROSION_INSTALL_ONLY "Only add rules for installing Corrosion itself." OFF)
if (NOT CORROSION_INSTALL_ONLY)
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
include(Corrosion)
endif()
# Testing
if (CORROSION_BUILD_TESTS)
include(CTest)
add_subdirectory(test)
endif()
# If Corrosion is a subdirectory, do not enable its install code
if (NOT PROJECT_IS_TOP_LEVEL)
return()
endif()
# Installation
include(GNUInstallDirs)
# Generate the Config file
include(CMakePackageConfigHelpers)
configure_package_config_file(
cmake/CorrosionConfig.cmake.in CorrosionConfig.cmake
INSTALL_DESTINATION
"${CMAKE_INSTALL_FULL_LIBDIR}/cmake/Corrosion"
)
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/CorrosionConfigVersion.cmake"
VERSION ${PROJECT_VERSION}
COMPATIBILITY
SameMajorVersion
ARCH_INDEPENDENT
)
install(
FILES
"${CMAKE_CURRENT_BINARY_DIR}/CorrosionConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/CorrosionConfigVersion.cmake"
DESTINATION
"${CMAKE_INSTALL_FULL_LIBDIR}/cmake/Corrosion"
)
# These CMake scripts are needed both for the install and as a subdirectory
install(
FILES
cmake/Corrosion.cmake
cmake/CorrosionGenerator.cmake
cmake/FindRust.cmake
DESTINATION
"${CMAKE_INSTALL_FULL_DATADIR}/cmake"
)