16021
|
1 |
cmake_minimum_required(VERSION 3.15)
|
|
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.
|
|
8 |
VERSION 0.5.0
|
|
9 |
LANGUAGES NONE
|
|
10 |
HOMEPAGE_URL "https://corrosion-rs.github.io/corrosion/"
|
|
11 |
)
|
|
12 |
|
|
13 |
# Default behavior:
|
|
14 |
# - If the project is being used as a subdirectory, then don't build tests and
|
|
15 |
# don't enable any languages.
|
|
16 |
# - If this is a top level project, then build tests and enable the C++ compiler
|
|
17 |
if (NOT CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
|
|
18 |
set(_CORROSION_TOP_LEVEL OFF)
|
|
19 |
else()
|
|
20 |
set(_CORROSION_TOP_LEVEL ON)
|
|
21 |
endif()
|
|
22 |
|
|
23 |
# ==== Corrosion Configuration ====
|
|
24 |
|
|
25 |
option(
|
|
26 |
CORROSION_DEV_MODE
|
|
27 |
"Enables some additional features if you're developing Corrosion"
|
|
28 |
${_CORROSION_TOP_LEVEL}
|
|
29 |
)
|
|
30 |
|
|
31 |
option(
|
|
32 |
CORROSION_BUILD_TESTS
|
|
33 |
"Build Corrosion test project"
|
|
34 |
${_CORROSION_TOP_LEVEL}
|
|
35 |
)
|
|
36 |
|
|
37 |
set(
|
|
38 |
CORROSION_GENERATOR_EXECUTABLE CACHE STRING
|
|
39 |
"Use prebuilt, non-bootstrapped corrosion-generator")
|
|
40 |
mark_as_advanced(CORROSION_GENERATOR_EXECUTABLE)
|
|
41 |
|
|
42 |
if (CORROSION_GENERATOR_EXECUTABLE)
|
|
43 |
add_executable(Corrosion::Generator IMPORTED GLOBAL)
|
|
44 |
set_property(
|
|
45 |
TARGET Corrosion::Generator
|
|
46 |
PROPERTY IMPORTED_LOCATION ${CORROSION_GENERATOR_EXECUTABLE})
|
|
47 |
set(CORROSION_INSTALL_EXECUTABLE_DEFAULT OFF)
|
|
48 |
elseif(CORROSION_NATIVE_TOOLING OR CMAKE_VERSION VERSION_LESS 3.19.0)
|
|
49 |
set(CORROSION_INSTALL_EXECUTABLE_DEFAULT "ON")
|
|
50 |
else()
|
|
51 |
set(CORROSION_INSTALL_EXECUTABLE_DEFAULT OFF)
|
|
52 |
endif()
|
|
53 |
|
|
54 |
option(
|
|
55 |
CORROSION_INSTALL_EXECUTABLE
|
|
56 |
"Controls whether corrosion-generator is installed with the package"
|
|
57 |
${CORROSION_INSTALL_EXECUTABLE_DEFAULT}
|
|
58 |
)
|
|
59 |
mark_as_advanced(CORROSION_INSTALL_EXECUTABLE)
|
|
60 |
|
|
61 |
if (_CORROSION_TOP_LEVEL)
|
|
62 |
# We need to enable a language for corrosions test to work.
|
|
63 |
# For projects using corrosion this is not needed
|
|
64 |
enable_language(C)
|
|
65 |
endif()
|
|
66 |
|
|
67 |
# This little bit self-hosts the Corrosion toolchain to build the generator
|
|
68 |
# tool.
|
|
69 |
#
|
|
70 |
# It is strongly encouraged to install Corrosion separately and use
|
|
71 |
# `find_package(Corrosion REQUIRED)` instead if that works with your workflow.
|
|
72 |
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
|
|
73 |
include(Corrosion)
|
|
74 |
|
|
75 |
# Testing
|
|
76 |
if (CORROSION_BUILD_TESTS)
|
|
77 |
include(CTest)
|
|
78 |
add_subdirectory(test)
|
|
79 |
endif()
|
|
80 |
|
|
81 |
# If Corrosion is a subdirectory, do not enable its install code
|
|
82 |
if (NOT _CORROSION_TOP_LEVEL)
|
|
83 |
return()
|
|
84 |
endif()
|
|
85 |
|
|
86 |
# Installation
|
|
87 |
|
|
88 |
include(GNUInstallDirs)
|
|
89 |
|
|
90 |
if(CORROSION_INSTALL_EXECUTABLE)
|
|
91 |
get_property(
|
|
92 |
_CORROSION_GENERATOR_EXE
|
|
93 |
TARGET Corrosion::Generator PROPERTY IMPORTED_LOCATION
|
|
94 |
)
|
|
95 |
install(PROGRAMS "${_CORROSION_GENERATOR_EXE}" DESTINATION "${CMAKE_INSTALL_FULL_LIBEXECDIR}")
|
|
96 |
else()
|
|
97 |
message(DEBUG "Not installing corrosion-generator since "
|
|
98 |
"`CORROSION_INSTALL_EXECUTABLE` is set to ${CORROSION_INSTALL_EXECUTABLE}"
|
|
99 |
)
|
|
100 |
endif()
|
|
101 |
|
|
102 |
# Generate the Config file
|
|
103 |
include(CMakePackageConfigHelpers)
|
|
104 |
|
|
105 |
configure_package_config_file(
|
|
106 |
cmake/CorrosionConfig.cmake.in CorrosionConfig.cmake
|
|
107 |
INSTALL_DESTINATION
|
|
108 |
"${CMAKE_INSTALL_FULL_LIBDIR}/cmake/Corrosion"
|
|
109 |
)
|
|
110 |
|
|
111 |
write_basic_package_version_file(
|
|
112 |
"${CMAKE_CURRENT_BINARY_DIR}/CorrosionConfigVersion.cmake"
|
|
113 |
VERSION ${PROJECT_VERSION}
|
|
114 |
COMPATIBILITY
|
|
115 |
SameMinorVersion # TODO: Should be SameMajorVersion when 1.0 is released
|
|
116 |
ARCH_INDEPENDENT
|
|
117 |
)
|
|
118 |
|
|
119 |
install(
|
|
120 |
FILES
|
|
121 |
"${CMAKE_CURRENT_BINARY_DIR}/CorrosionConfig.cmake"
|
|
122 |
"${CMAKE_CURRENT_BINARY_DIR}/CorrosionConfigVersion.cmake"
|
|
123 |
DESTINATION
|
|
124 |
"${CMAKE_INSTALL_FULL_LIBDIR}/cmake/Corrosion"
|
|
125 |
)
|
|
126 |
|
|
127 |
# These CMake scripts are needed both for the install and as a subdirectory
|
|
128 |
install(
|
|
129 |
FILES
|
|
130 |
cmake/Corrosion.cmake
|
|
131 |
cmake/CorrosionGenerator.cmake
|
|
132 |
cmake/FindRust.cmake
|
|
133 |
DESTINATION
|
|
134 |
"${CMAKE_INSTALL_FULL_DATADIR}/cmake"
|
|
135 |
)
|