16038
|
1 |
cmake_minimum_required(VERSION 3.22)
|
16021
|
2 |
project(Corrosion
|
|
3 |
# Official releases will be major.minor.patch. When the `tweak` field is
|
|
4 |
# set it indicates that we are on a commit, that is not a officially
|
|
5 |
# tagged release. Users don't need to care about this, it is mainly to
|
|
6 |
# clearly see in configure logs which version was used, without needing to
|
|
7 |
# rely on `git`, since Corrosion may be installed or otherwise packaged.
|
16038
|
8 |
VERSION 0.99.99 # 1.0-pre-release
|
16021
|
9 |
LANGUAGES NONE
|
|
10 |
HOMEPAGE_URL "https://corrosion-rs.github.io/corrosion/"
|
|
11 |
)
|
|
12 |
|
|
13 |
# ==== Corrosion Configuration ====
|
|
14 |
|
|
15 |
option(
|
|
16 |
CORROSION_BUILD_TESTS
|
|
17 |
"Build Corrosion test project"
|
16038
|
18 |
${PROJECT_IS_TOP_LEVEL}
|
16021
|
19 |
)
|
|
20 |
|
16038
|
21 |
if (PROJECT_IS_TOP_LEVEL)
|
16021
|
22 |
# We need to enable a language for corrosions test to work.
|
|
23 |
# For projects using corrosion this is not needed
|
|
24 |
enable_language(C)
|
|
25 |
endif()
|
|
26 |
|
|
27 |
# This little bit self-hosts the Corrosion toolchain to build the generator
|
|
28 |
# tool.
|
|
29 |
#
|
|
30 |
# It is strongly encouraged to install Corrosion separately and use
|
|
31 |
# `find_package(Corrosion REQUIRED)` instead if that works with your workflow.
|
16038
|
32 |
option(CORROSION_INSTALL_ONLY "Only add rules for installing Corrosion itself." OFF)
|
|
33 |
if (NOT CORROSION_INSTALL_ONLY)
|
|
34 |
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
|
|
35 |
include(Corrosion)
|
|
36 |
endif()
|
16021
|
37 |
|
|
38 |
# Testing
|
|
39 |
if (CORROSION_BUILD_TESTS)
|
|
40 |
include(CTest)
|
|
41 |
add_subdirectory(test)
|
|
42 |
endif()
|
|
43 |
|
|
44 |
# If Corrosion is a subdirectory, do not enable its install code
|
16038
|
45 |
if (NOT PROJECT_IS_TOP_LEVEL)
|
16021
|
46 |
return()
|
|
47 |
endif()
|
|
48 |
|
|
49 |
# Installation
|
|
50 |
|
|
51 |
include(GNUInstallDirs)
|
|
52 |
|
|
53 |
# Generate the Config file
|
|
54 |
include(CMakePackageConfigHelpers)
|
|
55 |
|
|
56 |
configure_package_config_file(
|
|
57 |
cmake/CorrosionConfig.cmake.in CorrosionConfig.cmake
|
|
58 |
INSTALL_DESTINATION
|
|
59 |
"${CMAKE_INSTALL_FULL_LIBDIR}/cmake/Corrosion"
|
|
60 |
)
|
|
61 |
|
|
62 |
write_basic_package_version_file(
|
|
63 |
"${CMAKE_CURRENT_BINARY_DIR}/CorrosionConfigVersion.cmake"
|
|
64 |
VERSION ${PROJECT_VERSION}
|
|
65 |
COMPATIBILITY
|
16038
|
66 |
SameMajorVersion
|
16021
|
67 |
ARCH_INDEPENDENT
|
|
68 |
)
|
|
69 |
|
|
70 |
install(
|
|
71 |
FILES
|
|
72 |
"${CMAKE_CURRENT_BINARY_DIR}/CorrosionConfig.cmake"
|
|
73 |
"${CMAKE_CURRENT_BINARY_DIR}/CorrosionConfigVersion.cmake"
|
|
74 |
DESTINATION
|
|
75 |
"${CMAKE_INSTALL_FULL_LIBDIR}/cmake/Corrosion"
|
|
76 |
)
|
|
77 |
|
|
78 |
# These CMake scripts are needed both for the install and as a subdirectory
|
|
79 |
install(
|
|
80 |
FILES
|
|
81 |
cmake/Corrosion.cmake
|
|
82 |
cmake/CorrosionGenerator.cmake
|
|
83 |
cmake/FindRust.cmake
|
|
84 |
DESTINATION
|
|
85 |
"${CMAKE_INSTALL_FULL_DATADIR}/cmake"
|
|
86 |
)
|