mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-06-26 10:54:26 +02:00
Vendor CMakeRust
This commit is contained in:
parent
37d7f3de8a
commit
7492fc48bb
28 changed files with 673 additions and 1 deletions
|
@ -1 +0,0 @@
|
|||
Subproject commit 9a4a7a19b41e58deef5efc9a7ba53a69bc40449b
|
3
cmake/CMakeRust/.github/CODEOWNERS
vendored
Normal file
3
cmake/CMakeRust/.github/CODEOWNERS
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
# File auto-generated and managed by Devops
|
||||
/.github/ @devolutions/devops
|
||||
/.github/dependabot.yml @devolutions/security-managers
|
11
cmake/CMakeRust/.gitignore
vendored
Normal file
11
cmake/CMakeRust/.gitignore
vendored
Normal file
|
@ -0,0 +1,11 @@
|
|||
|
||||
*~
|
||||
bin
|
||||
lib
|
||||
*.exe
|
||||
build
|
||||
Makefile
|
||||
CMakeFiles
|
||||
CMakeCache.txt
|
||||
cmake_install.cmake
|
||||
.vscode/
|
12
cmake/CMakeRust/CMakeLists.txt
Normal file
12
cmake/CMakeRust/CMakeLists.txt
Normal file
|
@ -0,0 +1,12 @@
|
|||
cmake_minimum_required(VERSION 3.0)
|
||||
|
||||
project(CMakeRust)
|
||||
|
||||
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
|
||||
|
||||
enable_language(Rust)
|
||||
include(CMakeCargo)
|
||||
|
||||
add_subdirectory(hello_world)
|
||||
add_subdirectory(crates)
|
||||
|
202
cmake/CMakeRust/LICENSE-APACHE
Normal file
202
cmake/CMakeRust/LICENSE-APACHE
Normal file
|
@ -0,0 +1,202 @@
|
|||
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
23
cmake/CMakeRust/LICENSE-MIT
Normal file
23
cmake/CMakeRust/LICENSE-MIT
Normal file
|
@ -0,0 +1,23 @@
|
|||
Permission is hereby granted, free of charge, to any
|
||||
person obtaining a copy of this software and associated
|
||||
documentation files (the "Software"), to deal in the
|
||||
Software without restriction, including without
|
||||
limitation the rights to use, copy, modify, merge,
|
||||
publish, distribute, sublicense, and/or sell copies of
|
||||
the Software, and to permit persons to whom the Software
|
||||
is furnished to do so, subject to the following
|
||||
conditions:
|
||||
|
||||
The above copyright notice and this permission notice
|
||||
shall be included in all copies or substantial portions
|
||||
of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
|
||||
ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
|
||||
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
|
||||
SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
|
||||
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
DEALINGS IN THE SOFTWARE.
|
70
cmake/CMakeRust/cmake/CMakeCargo.cmake
Normal file
70
cmake/CMakeRust/cmake/CMakeCargo.cmake
Normal file
|
@ -0,0 +1,70 @@
|
|||
function(cargo_build)
|
||||
cmake_parse_arguments(CARGO "" "NAME" "" ${ARGN})
|
||||
string(REPLACE "-" "_" LIB_NAME ${CARGO_NAME})
|
||||
|
||||
set(CARGO_TARGET_DIR ${CMAKE_CURRENT_BINARY_DIR})
|
||||
|
||||
if(WIN32)
|
||||
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
|
||||
set(LIB_TARGET "x86_64-pc-windows-msvc")
|
||||
else()
|
||||
set(LIB_TARGET "i686-pc-windows-msvc")
|
||||
endif()
|
||||
elseif(ANDROID)
|
||||
if(ANDROID_SYSROOT_ABI STREQUAL "x86")
|
||||
set(LIB_TARGET "i686-linux-android")
|
||||
elseif(ANDROID_SYSROOT_ABI STREQUAL "x86_64")
|
||||
set(LIB_TARGET "x86_64-linux-android")
|
||||
elseif(ANDROID_SYSROOT_ABI STREQUAL "arm")
|
||||
set(LIB_TARGET "arm-linux-androideabi")
|
||||
elseif(ANDROID_SYSROOT_ABI STREQUAL "arm64")
|
||||
set(LIB_TARGET "aarch64-linux-android")
|
||||
endif()
|
||||
elseif(IOS)
|
||||
set(LIB_TARGET "universal")
|
||||
elseif(CMAKE_SYSTEM_NAME STREQUAL Darwin)
|
||||
set(LIB_TARGET "x86_64-apple-darwin")
|
||||
else()
|
||||
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
|
||||
set(LIB_TARGET "x86_64-unknown-linux-gnu")
|
||||
else()
|
||||
set(LIB_TARGET "i686-unknown-linux-gnu")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(NOT CMAKE_BUILD_TYPE)
|
||||
set(LIB_BUILD_TYPE "debug")
|
||||
elseif(${CMAKE_BUILD_TYPE} STREQUAL "Release")
|
||||
set(LIB_BUILD_TYPE "release")
|
||||
else()
|
||||
set(LIB_BUILD_TYPE "debug")
|
||||
endif()
|
||||
|
||||
set(LIB_FILE "${CARGO_TARGET_DIR}/${LIB_TARGET}/${LIB_BUILD_TYPE}/${CMAKE_STATIC_LIBRARY_PREFIX}${LIB_NAME}${CMAKE_STATIC_LIBRARY_SUFFIX}")
|
||||
|
||||
if(IOS)
|
||||
set(CARGO_ARGS "lipo")
|
||||
else()
|
||||
set(CARGO_ARGS "build")
|
||||
list(APPEND CARGO_ARGS "--target" ${LIB_TARGET})
|
||||
endif()
|
||||
|
||||
if(${LIB_BUILD_TYPE} STREQUAL "release")
|
||||
list(APPEND CARGO_ARGS "--release")
|
||||
endif()
|
||||
|
||||
file(GLOB_RECURSE LIB_SOURCES "*.rs")
|
||||
|
||||
set(CARGO_ENV_COMMAND ${CMAKE_COMMAND} -E env "CARGO_TARGET_DIR=${CARGO_TARGET_DIR}")
|
||||
|
||||
add_custom_command(
|
||||
OUTPUT ${LIB_FILE}
|
||||
COMMAND ${CARGO_ENV_COMMAND} ${CARGO_EXECUTABLE} ARGS ${CARGO_ARGS}
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
DEPENDS ${LIB_SOURCES}
|
||||
COMMENT "running cargo")
|
||||
add_custom_target(${CARGO_NAME}_target ALL DEPENDS ${LIB_FILE})
|
||||
add_library(${CARGO_NAME} STATIC IMPORTED GLOBAL)
|
||||
add_dependencies(${CARGO_NAME} ${CARGO_NAME}_target)
|
||||
set_target_properties(${CARGO_NAME} PROPERTIES IMPORTED_LOCATION ${LIB_FILE})
|
||||
endfunction()
|
25
cmake/CMakeRust/cmake/CMakeDetermineRustCompiler.cmake
Normal file
25
cmake/CMakeRust/cmake/CMakeDetermineRustCompiler.cmake
Normal file
|
@ -0,0 +1,25 @@
|
|||
|
||||
if(NOT CMAKE_Rust_COMPILER)
|
||||
find_package(Rust)
|
||||
if(RUST_FOUND)
|
||||
set(CMAKE_Rust_COMPILER "${RUSTC_EXECUTABLE}")
|
||||
set(CMAKE_Rust_COMPILER_ID "Rust")
|
||||
set(CMAKE_Rust_COMPILER_VERSION "${RUST_VERSION}")
|
||||
set(CMAKE_Rust_PLATFORM_ID "Rust")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
message(STATUS "Cargo Home: ${CARGO_HOME}")
|
||||
message(STATUS "Rust Compiler Version: ${RUSTC_VERSION}")
|
||||
|
||||
mark_as_advanced(CMAKE_Rust_COMPILER)
|
||||
|
||||
if(CMAKE_Rust_COMPILER)
|
||||
set(CMAKE_Rust_COMPILER_LOADED 1)
|
||||
endif(CMAKE_Rust_COMPILER)
|
||||
|
||||
configure_file(${CMAKE_CURRENT_LIST_DIR}/CMakeRustCompiler.cmake.in
|
||||
${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/${CMAKE_VERSION}/CMakeRustCompiler.cmake IMMEDIATE @ONLY)
|
||||
|
||||
set(CMAKE_Rust_COMPILER_ENV_VAR "RUSTC")
|
||||
|
15
cmake/CMakeRust/cmake/CMakeRustCompiler.cmake.in
Normal file
15
cmake/CMakeRust/cmake/CMakeRustCompiler.cmake.in
Normal file
|
@ -0,0 +1,15 @@
|
|||
|
||||
set(CMAKE_Rust_COMPILER "@CMAKE_Rust_COMPILER@")
|
||||
set(CMAKE_Rust_COMPILER_ID "@CMAKE_Rust_COMPILER_ID@")
|
||||
set(CMAKE_Rust_COMPILER_VERSION "@CMAKE_Rust_COMPILER_VERSION@")
|
||||
set(CMAKE_Rust_COMPILER_LOADED @CMAKE_Rust_COMPILER_LOADED@)
|
||||
set(CMAKE_Rust_PLATFORM_ID "@CMAKE_Rust_PLATFORM_ID@")
|
||||
|
||||
SET(CMAKE_Rust_SOURCE_FILE_EXTENSIONS rs)
|
||||
SET(CMAKE_Rust_LINKER_PREFERENCE 40)
|
||||
#SET(CMAKE_Rust_OUTPUT_EXTENSION_REPLACE 1)
|
||||
SET(CMAKE_STATIC_LIBRARY_PREFIX_Rust "")
|
||||
SET(CMAKE_STATIC_LIBRARY_SUFFIX_Rust .a)
|
||||
|
||||
set(CMAKE_Rust_COMPILER_ENV_VAR "RUSTC")
|
||||
|
106
cmake/CMakeRust/cmake/CMakeRustInformation.cmake
Normal file
106
cmake/CMakeRust/cmake/CMakeRustInformation.cmake
Normal file
|
@ -0,0 +1,106 @@
|
|||
|
||||
#
|
||||
# Usage: rustc [OPTIONS] INPUT
|
||||
#
|
||||
# Options:
|
||||
# -h --help Display this message
|
||||
# --cfg SPEC Configure the compilation environment
|
||||
# -L [KIND=]PATH Add a directory to the library search path. The
|
||||
# optional KIND can be one of dependency, crate, native,
|
||||
# framework or all (the default).
|
||||
# -l [KIND=]NAME Link the generated crate(s) to the specified native
|
||||
# library NAME. The optional KIND can be one of static,
|
||||
# dylib, or framework. If omitted, dylib is assumed.
|
||||
# --crate-type [bin|lib|rlib|dylib|cdylib|staticlib|metadata]
|
||||
# Comma separated list of types of crates for the
|
||||
# compiler to emit
|
||||
# --crate-name NAME Specify the name of the crate being built
|
||||
# --emit [asm|llvm-bc|llvm-ir|obj|link|dep-info]
|
||||
# Comma separated list of types of output for the
|
||||
# compiler to emit
|
||||
# --print [crate-name|file-names|sysroot|cfg|target-list|target-cpus|target-features|relocation-models|code-models]
|
||||
# Comma separated list of compiler information to print
|
||||
# on stdout
|
||||
# -g Equivalent to -C debuginfo=2
|
||||
# -O Equivalent to -C opt-level=2
|
||||
# -o FILENAME Write output to <filename>
|
||||
# --out-dir DIR Write output to compiler-chosen filename in <dir>
|
||||
# --explain OPT Provide a detailed explanation of an error message
|
||||
# --test Build a test harness
|
||||
# --target TARGET Target triple for which the code is compiled
|
||||
# -W --warn OPT Set lint warnings
|
||||
# -A --allow OPT Set lint allowed
|
||||
# -D --deny OPT Set lint denied
|
||||
# -F --forbid OPT Set lint forbidden
|
||||
# --cap-lints LEVEL Set the most restrictive lint level. More restrictive
|
||||
# lints are capped at this level
|
||||
# -C --codegen OPT[=VALUE]
|
||||
# Set a codegen option
|
||||
# -V --version Print version info and exit
|
||||
# -v --verbose Use verbose output
|
||||
#
|
||||
# Additional help:
|
||||
# -C help Print codegen options
|
||||
# -W help Print 'lint' options and default settings
|
||||
# -Z help Print internal options for debugging rustc
|
||||
# --help -v Print the full set of options rustc accepts
|
||||
#
|
||||
|
||||
# <TARGET> <TARGET_BASE> <OBJECT> <OBJECTS> <LINK_LIBRARIES> <FLAGS> <LINK_FLAGS> <SOURCE> <SOURCES>
|
||||
|
||||
include(CMakeLanguageInformation)
|
||||
|
||||
if(UNIX)
|
||||
set(CMAKE_Rust_OUTPUT_EXTENSION .o)
|
||||
else()
|
||||
set(CMAKE_Rust_OUTPUT_EXTENSION .obj)
|
||||
endif()
|
||||
|
||||
set(CMAKE_Rust_ECHO_ALL "echo \"TARGET: <TARGET> TARGET_BASE: <TARGET_BASE> ")
|
||||
set(CMAKE_Rust_ECHO_ALL "${CMAKE_Rust_ECHO_ALL} OBJECT: <OBJECT> OBJECTS: <OBJECTS> OBJECT_DIR: <OBJECT_DIR> SOURCE: <SOURCE> SOURCES: <SOURCES> ")
|
||||
set(CMAKE_Rust_ECHO_ALL "${CMAKE_Rust_ECHO_ALL} LINK_LIBRARIES: <LINK_LIBRARIES> FLAGS: <FLAGS> LINK_FLAGS: <LINK_FLAGS> \"")
|
||||
|
||||
if(NOT CMAKE_Rust_CREATE_SHARED_LIBRARY)
|
||||
set(CMAKE_Rust_CREATE_SHARED_LIBRARY
|
||||
"echo \"CMAKE_Rust_CREATE_SHARED_LIBRARY\""
|
||||
"${CMAKE_Rust_ECHO_ALL}"
|
||||
)
|
||||
endif()
|
||||
|
||||
if(NOT CMAKE_Rust_CREATE_SHARED_MODULE)
|
||||
set(CMAKE_Rust_CREATE_SHARED_MODULE
|
||||
"echo \"CMAKE_Rust_CREATE_SHARED_MODULE\""
|
||||
"${CMAKE_Rust_ECHO_ALL}"
|
||||
)
|
||||
endif()
|
||||
|
||||
if(NOT CMAKE_Rust_CREATE_STATIC_LIBRARY)
|
||||
set(CMAKE_Rust_CREATE_STATIC_LIBRARY
|
||||
"echo \"CMAKE_Rust_CREATE_STATIC_LIBRARY\""
|
||||
"${CMAKE_Rust_ECHO_ALL}"
|
||||
)
|
||||
endif()
|
||||
|
||||
if(NOT CMAKE_Rust_COMPILE_OBJECT)
|
||||
set(CMAKE_Rust_COMPILE_OBJECT
|
||||
"echo \"CMAKE_Rust_COMPILE_OBJECT\""
|
||||
"${CMAKE_Rust_ECHO_ALL}"
|
||||
"${CMAKE_Rust_COMPILER} --emit obj <SOURCE> -o <OBJECT>")
|
||||
endif()
|
||||
|
||||
if(NOT CMAKE_Rust_LINK_EXECUTABLE)
|
||||
set(CMAKE_Rust_LINK_EXECUTABLE
|
||||
"echo \"CMAKE_Rust_LINK_EXECUTABLE\""
|
||||
"${CMAKE_Rust_ECHO_ALL}"
|
||||
)
|
||||
endif()
|
||||
|
||||
mark_as_advanced(
|
||||
CMAKE_Rust_FLAGS
|
||||
CMAKE_Rust_FLAGS_DEBUG
|
||||
CMAKE_Rust_FLAGS_MINSIZEREL
|
||||
CMAKE_Rust_FLAGS_RELEASE
|
||||
CMAKE_Rust_FLAGS_RELWITHDEBINFO)
|
||||
|
||||
set(CMAKE_Rust_INFORMATION_LOADED 1)
|
||||
|
3
cmake/CMakeRust/cmake/CMakeTestRustCompiler.cmake
Normal file
3
cmake/CMakeRust/cmake/CMakeTestRustCompiler.cmake
Normal file
|
@ -0,0 +1,3 @@
|
|||
|
||||
set(CMAKE_Rust_COMPILER_WORKS 1 CACHE INTERNAL "")
|
||||
|
64
cmake/CMakeRust/cmake/CargoLink.cmake
Normal file
64
cmake/CMakeRust/cmake/CargoLink.cmake
Normal file
|
@ -0,0 +1,64 @@
|
|||
|
||||
function(cargo_print)
|
||||
execute_process(COMMAND ${CMAKE_COMMAND} -E echo "${ARGN}")
|
||||
endfunction()
|
||||
|
||||
function(cargo_link)
|
||||
cmake_parse_arguments(CARGO_LINK "" "NAME" "TARGETS;EXCLUDE" ${ARGN})
|
||||
|
||||
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/cargo-link.c" "void cargo_link() {}")
|
||||
add_library(${CARGO_LINK_NAME} "${CMAKE_CURRENT_BINARY_DIR}/cargo-link.c")
|
||||
target_link_libraries(${CARGO_LINK_NAME} ${CARGO_LINK_TARGETS})
|
||||
|
||||
get_target_property(LINK_LIBRARIES ${CARGO_LINK_NAME} LINK_LIBRARIES)
|
||||
|
||||
foreach(LINK_LIBRARY ${LINK_LIBRARIES})
|
||||
get_target_property(_INTERFACE_LINK_LIBRARIES ${LINK_LIBRARY} INTERFACE_LINK_LIBRARIES)
|
||||
list(APPEND LINK_LIBRARIES ${_INTERFACE_LINK_LIBRARIES})
|
||||
endforeach()
|
||||
list(REMOVE_DUPLICATES LINK_LIBRARIES)
|
||||
|
||||
if(CARGO_LINK_EXCLUDE)
|
||||
list(REMOVE_ITEM LINK_LIBRARIES ${CARGO_LINK_EXCLUDE})
|
||||
endif()
|
||||
|
||||
set(LINK_DIRECTORIES "")
|
||||
foreach(LINK_LIBRARY ${LINK_LIBRARIES})
|
||||
if(TARGET ${LINK_LIBRARY})
|
||||
get_target_property(_IMPORTED_CONFIGURATIONS ${LINK_LIBRARY} IMPORTED_CONFIGURATIONS)
|
||||
list(FIND _IMPORTED_CONFIGURATIONS "RELEASE" _IMPORTED_CONFIGURATION_INDEX)
|
||||
if (NOT (${_IMPORTED_CONFIGURATION_INDEX} GREATER -1))
|
||||
set(_IMPORTED_CONFIGURATION_INDEX 0)
|
||||
endif()
|
||||
list(GET _IMPORTED_CONFIGURATIONS ${_IMPORTED_CONFIGURATION_INDEX} _IMPORTED_CONFIGURATION)
|
||||
get_target_property(_IMPORTED_LOCATION ${LINK_LIBRARY} "IMPORTED_LOCATION_${_IMPORTED_CONFIGURATION}")
|
||||
get_filename_component(_IMPORTED_DIR ${_IMPORTED_LOCATION} DIRECTORY)
|
||||
get_filename_component(_IMPORTED_NAME ${_IMPORTED_LOCATION} NAME_WE)
|
||||
if(NOT WIN32)
|
||||
string(REGEX REPLACE "^lib" "" _IMPORTED_NAME ${_IMPORTED_NAME})
|
||||
endif()
|
||||
list(APPEND LINK_DIRECTORIES ${_IMPORTED_DIR})
|
||||
cargo_print("cargo:rustc-link-lib=static=${_IMPORTED_NAME}")
|
||||
else()
|
||||
if("${LINK_LIBRARY}" MATCHES "^.*/(.+)\\.framework$")
|
||||
set(FRAMEWORK_NAME ${CMAKE_MATCH_1})
|
||||
cargo_print("cargo:rustc-link-lib=framework=${FRAMEWORK_NAME}")
|
||||
elseif("${LINK_LIBRARY}" MATCHES "^(.*)/(.+)\\.so$")
|
||||
set(LIBRARY_DIR ${CMAKE_MATCH_1})
|
||||
set(LIBRARY_NAME ${CMAKE_MATCH_2})
|
||||
if(NOT WIN32)
|
||||
string(REGEX REPLACE "^lib" "" LIBRARY_NAME ${LIBRARY_NAME})
|
||||
endif()
|
||||
list(APPEND LINK_DIRECTORIES ${LIBRARY_DIR})
|
||||
cargo_print("cargo:rustc-link-lib=${LIBRARY_NAME}")
|
||||
else()
|
||||
cargo_print("cargo:rustc-link-lib=${LINK_LIBRARY}")
|
||||
endif()
|
||||
endif()
|
||||
endforeach()
|
||||
list(REMOVE_DUPLICATES LINK_DIRECTORIES)
|
||||
|
||||
foreach(LINK_DIRECTORY ${LINK_DIRECTORIES})
|
||||
cargo_print("cargo:rustc-link-search=native=${LINK_DIRECTORY}")
|
||||
endforeach()
|
||||
endfunction()
|
73
cmake/CMakeRust/cmake/FindRust.cmake
Normal file
73
cmake/CMakeRust/cmake/FindRust.cmake
Normal file
|
@ -0,0 +1,73 @@
|
|||
|
||||
set(_CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ${CMAKE_FIND_ROOT_PATH_MODE_PROGRAM})
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM BOTH)
|
||||
set(_CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ${CMAKE_FIND_ROOT_PATH_MODE_INCLUDE})
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE BOTH)
|
||||
|
||||
if(CMAKE_HOST_WIN32)
|
||||
set(USER_HOME "$ENV{USERPROFILE}")
|
||||
else()
|
||||
set(USER_HOME "$ENV{HOME}")
|
||||
endif()
|
||||
|
||||
if(NOT DEFINED CARGO_HOME)
|
||||
if("$ENV{CARGO_HOME}" STREQUAL "")
|
||||
set(CARGO_HOME "${USER_HOME}/.cargo")
|
||||
else()
|
||||
set(CARGO_HOME "$ENV{CARGO_HOME}")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# Find cargo executable
|
||||
find_program(CARGO_EXECUTABLE cargo
|
||||
HINTS "${CARGO_HOME}"
|
||||
PATH_SUFFIXES "bin")
|
||||
mark_as_advanced(CARGO_EXECUTABLE)
|
||||
|
||||
# Find rustc executable
|
||||
find_program(RUSTC_EXECUTABLE rustc
|
||||
HINTS "${CARGO_HOME}"
|
||||
PATH_SUFFIXES "bin")
|
||||
mark_as_advanced(RUSTC_EXECUTABLE)
|
||||
|
||||
# Find rustdoc executable
|
||||
find_program(RUSTDOC_EXECUTABLE rustdoc
|
||||
HINTS "${CARGO_HOME}"
|
||||
PATH_SUFFIXES "bin")
|
||||
mark_as_advanced(RUSTDOC_EXECUTABLE)
|
||||
|
||||
# Find rust-gdb executable
|
||||
find_program(RUST_GDB_EXECUTABLE rust-gdb
|
||||
HINTS "${CARGO_HOME}"
|
||||
PATH_SUFFIXES "bin")
|
||||
mark_as_advanced(RUST_GDB_EXECUTABLE)
|
||||
|
||||
# Find rust-lldb executable
|
||||
find_program(RUST_LLDB_EXECUTABLE rust-lldb
|
||||
HINTS "${CARGO_HOME}"
|
||||
PATH_SUFFIXES "bin")
|
||||
mark_as_advanced(RUST_LLDB_EXECUTABLE)
|
||||
|
||||
# Find rustup executable
|
||||
find_program(RUSTUP_EXECUTABLE rustup
|
||||
HINTS "${CARGO_HOME}"
|
||||
PATH_SUFFIXES "bin")
|
||||
mark_as_advanced(RUSTUP_EXECUTABLE)
|
||||
|
||||
set(RUST_FOUND FALSE CACHE INTERNAL "")
|
||||
|
||||
if(CARGO_EXECUTABLE AND RUSTC_EXECUTABLE AND RUSTDOC_EXECUTABLE)
|
||||
set(RUST_FOUND TRUE CACHE INTERNAL "")
|
||||
|
||||
set(CARGO_HOME "${CARGO_HOME}" CACHE PATH "Rust Cargo Home")
|
||||
|
||||
execute_process(COMMAND ${RUSTC_EXECUTABLE} --version OUTPUT_VARIABLE RUSTC_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||
string(REGEX REPLACE "rustc ([^ ]+) .*" "\\1" RUSTC_VERSION "${RUSTC_VERSION}")
|
||||
endif()
|
||||
|
||||
if(NOT RUST_FOUND)
|
||||
message(FATAL_ERROR "Could not find Rust!")
|
||||
endif()
|
||||
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ${_CMAKE_FIND_ROOT_PATH_MODE_PROGRAM})
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ${_CMAKE_FIND_ROOT_PATH_MODE_INCLUDE})
|
1
cmake/CMakeRust/crates/CMakeLists.txt
Normal file
1
cmake/CMakeRust/crates/CMakeLists.txt
Normal file
|
@ -0,0 +1 @@
|
|||
add_subdirectory(test-lib)
|
1
cmake/CMakeRust/crates/test-bin/.gitignore
vendored
Normal file
1
cmake/CMakeRust/crates/test-bin/.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
target/
|
4
cmake/CMakeRust/crates/test-bin/Cargo.lock
generated
Normal file
4
cmake/CMakeRust/crates/test-bin/Cargo.lock
generated
Normal file
|
@ -0,0 +1,4 @@
|
|||
[[package]]
|
||||
name = "test-bin"
|
||||
version = "0.1.0"
|
||||
|
6
cmake/CMakeRust/crates/test-bin/Cargo.toml
Normal file
6
cmake/CMakeRust/crates/test-bin/Cargo.toml
Normal file
|
@ -0,0 +1,6 @@
|
|||
[package]
|
||||
name = "test-bin"
|
||||
version = "0.1.0"
|
||||
authors = ["Marc-André Moreau <marcandre.moreau@gmail.com>"]
|
||||
|
||||
[dependencies]
|
3
cmake/CMakeRust/crates/test-bin/src/main.rs
Normal file
3
cmake/CMakeRust/crates/test-bin/src/main.rs
Normal file
|
@ -0,0 +1,3 @@
|
|||
fn main() {
|
||||
println!("Hello, world!");
|
||||
}
|
1
cmake/CMakeRust/crates/test-lib/.gitignore
vendored
Normal file
1
cmake/CMakeRust/crates/test-lib/.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
target/
|
1
cmake/CMakeRust/crates/test-lib/CMakeLists.txt
Normal file
1
cmake/CMakeRust/crates/test-lib/CMakeLists.txt
Normal file
|
@ -0,0 +1 @@
|
|||
cargo_build(NAME test-lib)
|
4
cmake/CMakeRust/crates/test-lib/Cargo.lock
generated
Normal file
4
cmake/CMakeRust/crates/test-lib/Cargo.lock
generated
Normal file
|
@ -0,0 +1,4 @@
|
|||
[[package]]
|
||||
name = "test-lib"
|
||||
version = "0.1.0"
|
||||
|
9
cmake/CMakeRust/crates/test-lib/Cargo.toml
Normal file
9
cmake/CMakeRust/crates/test-lib/Cargo.toml
Normal file
|
@ -0,0 +1,9 @@
|
|||
[package]
|
||||
name = "test-lib"
|
||||
version = "0.1.0"
|
||||
authors = ["Marc-André Moreau <marcandre.moreau@gmail.com>"]
|
||||
|
||||
[lib]
|
||||
crate-type = ["staticlib"]
|
||||
|
||||
[dependencies]
|
5
cmake/CMakeRust/crates/test-lib/src/lib.rs
Normal file
5
cmake/CMakeRust/crates/test-lib/src/lib.rs
Normal file
|
@ -0,0 +1,5 @@
|
|||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn hello() {
|
||||
println!("hello world!");
|
||||
}
|
5
cmake/CMakeRust/hello/CMakeLists.txt
Normal file
5
cmake/CMakeRust/hello/CMakeLists.txt
Normal file
|
@ -0,0 +1,5 @@
|
|||
|
||||
add_executable(hello hello.rs)
|
||||
|
||||
set_target_properties(hello PROPERTIES LINKER_LANGUAGE Rust)
|
||||
|
5
cmake/CMakeRust/hello/hello.rs
Normal file
5
cmake/CMakeRust/hello/hello.rs
Normal file
|
@ -0,0 +1,5 @@
|
|||
|
||||
fn main() {
|
||||
println!("Hello, World!");
|
||||
}
|
||||
|
9
cmake/CMakeRust/hello_world/CMakeLists.txt
Normal file
9
cmake/CMakeRust/hello_world/CMakeLists.txt
Normal file
|
@ -0,0 +1,9 @@
|
|||
|
||||
add_executable(helloworld hello.c)
|
||||
if(WIN32)
|
||||
target_link_libraries(helloworld test-lib ws2_32 userenv)
|
||||
elseif(CMAKE_SYSTEM_NAME MATCHES "Darwin")
|
||||
target_link_libraries(helloworld test-lib resolv)
|
||||
else()
|
||||
target_link_libraries(helloworld test-lib pthread dl m)
|
||||
endif()
|
6
cmake/CMakeRust/hello_world/hello.c
Normal file
6
cmake/CMakeRust/hello_world/hello.c
Normal file
|
@ -0,0 +1,6 @@
|
|||
|
||||
#include "test_lib.h"
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
hello();
|
||||
}
|
6
cmake/CMakeRust/hello_world/test_lib.h
Normal file
6
cmake/CMakeRust/hello_world/test_lib.h
Normal file
|
@ -0,0 +1,6 @@
|
|||
#ifndef TEST_LIB
|
||||
#define TEST_LIB
|
||||
|
||||
void hello();
|
||||
|
||||
#endif /* TEST_LIB */
|
Loading…
Add table
Add a link
Reference in a new issue