2023-03-30 12:01:23 +08:00
|
|
|
if(EXISTS "${CMAKE_SOURCE_DIR}/corrosion-vendor/")
|
|
|
|
add_subdirectory("${CMAKE_SOURCE_DIR}/corrosion-vendor/")
|
|
|
|
else()
|
|
|
|
include(FetchContent)
|
|
|
|
|
|
|
|
# Don't let Corrosion's tests interfere with ours.
|
|
|
|
set(CORROSION_TESTS OFF CACHE BOOL "" FORCE)
|
|
|
|
|
|
|
|
FetchContent_Declare(
|
|
|
|
Corrosion
|
|
|
|
GIT_REPOSITORY https://github.com/mqudsi/corrosion
|
|
|
|
GIT_TAG fish
|
|
|
|
)
|
|
|
|
|
|
|
|
FetchContent_MakeAvailable(Corrosion)
|
|
|
|
|
|
|
|
add_custom_target(corrosion-vendor.tar.gz
|
|
|
|
COMMAND git archive --format tar.gz --output "${CMAKE_BINARY_DIR}/corrosion-vendor.tar.gz"
|
|
|
|
--prefix corrosion-vendor/ HEAD
|
|
|
|
WORKING_DIRECTORY ${corrosion_SOURCE_DIR}
|
|
|
|
)
|
|
|
|
endif()
|
2023-01-15 06:56:24 +08:00
|
|
|
|
2024-01-12 20:08:41 +08:00
|
|
|
set(fish_rust_target "fish")
|
2023-01-15 06:56:24 +08:00
|
|
|
|
2024-01-04 03:57:28 +08:00
|
|
|
set(FISH_CRATE_FEATURES)
|
2023-03-08 02:47:30 +08:00
|
|
|
if(NOT DEFINED CARGO_FLAGS)
|
|
|
|
# Corrosion doesn't like an empty string as FLAGS. This is basically a no-op alternative.
|
|
|
|
# See https://github.com/corrosion-rs/corrosion/issues/356
|
|
|
|
set(CARGO_FLAGS "--config" "foo=0")
|
|
|
|
endif()
|
|
|
|
if(DEFINED ASAN)
|
|
|
|
list(APPEND CARGO_FLAGS "-Z" "build-std")
|
2024-01-04 03:57:28 +08:00
|
|
|
list(APPEND FISH_CRATE_FEATURES FEATURES "asan")
|
2023-03-08 02:47:30 +08:00
|
|
|
endif()
|
|
|
|
|
2023-01-15 06:56:24 +08:00
|
|
|
corrosion_import_crate(
|
2023-08-13 21:33:36 +08:00
|
|
|
MANIFEST_PATH "${CMAKE_SOURCE_DIR}/Cargo.toml"
|
2024-01-12 20:08:41 +08:00
|
|
|
CRATES "fish"
|
2024-01-04 03:57:28 +08:00
|
|
|
"${FISH_CRATE_FEATURES}"
|
2023-03-08 02:47:30 +08:00
|
|
|
FLAGS "${CARGO_FLAGS}"
|
2023-01-15 06:56:24 +08:00
|
|
|
)
|
|
|
|
|
2024-01-12 15:25:06 +08:00
|
|
|
if (Rust_CARGO_TARGET)
|
|
|
|
set(rust_target_dir "${CMAKE_BINARY_DIR}/cargo/build/${_CORROSION_RUST_CARGO_TARGET}")
|
|
|
|
else()
|
|
|
|
set(rust_target_dir "${CMAKE_BINARY_DIR}/cargo/build/${_CORROSION_RUST_CARGO_HOST_TARGET}")
|
|
|
|
endif()
|
|
|
|
|
2023-05-17 02:02:22 +08:00
|
|
|
# Temporary hack to propogate CMake flags/options to build.rs. We need to get CMake to evaluate the
|
|
|
|
# truthiness of the strings if they are set.
|
|
|
|
set(CMAKE_WITH_GETTEXT "1")
|
|
|
|
if(DEFINED WITH_GETTEXT AND NOT "${WITH_GETTEXT}")
|
|
|
|
set(CMAKE_WITH_GETTEXT "0")
|
|
|
|
endif()
|
|
|
|
|
2023-09-28 23:30:40 +08:00
|
|
|
# CMAKE_BINARY_DIR can include symlinks, since we want to compare this to the dir fish is executed in we need to canonicalize it.
|
|
|
|
file(REAL_PATH "${CMAKE_BINARY_DIR}" fish_binary_dir)
|
2024-01-04 03:02:32 +08:00
|
|
|
string(JOIN "," CURSES_LIBRARY_LIST ${CURSES_LIBRARY} ${CURSES_EXTRA_LIBRARY})
|
|
|
|
|
2023-01-15 06:56:24 +08:00
|
|
|
# Tell Cargo where our build directory is so it can find config.h.
|
2024-01-12 19:00:38 +08:00
|
|
|
set(VARS_FOR_CARGO
|
2023-09-28 23:30:40 +08:00
|
|
|
"FISH_BUILD_DIR=${fish_binary_dir}"
|
2023-04-09 20:33:20 +08:00
|
|
|
"PREFIX=${CMAKE_INSTALL_PREFIX}"
|
2023-05-17 02:02:22 +08:00
|
|
|
# Temporary hack to propogate CMake flags/options to build.rs.
|
|
|
|
"CMAKE_WITH_GETTEXT=${CMAKE_WITH_GETTEXT}"
|
2023-09-06 15:35:56 +08:00
|
|
|
"DOCDIR=${CMAKE_INSTALL_FULL_DOCDIR}"
|
|
|
|
"DATADIR=${CMAKE_INSTALL_FULL_DATADIR}"
|
|
|
|
"SYSCONFDIR=${CMAKE_INSTALL_FULL_SYSCONFDIR}"
|
|
|
|
"BINDIR=${CMAKE_INSTALL_FULL_BINDIR}"
|
2024-01-02 03:39:38 +08:00
|
|
|
"LOCALEDIR=${CMAKE_INSTALL_FULL_LOCALEDIR}"
|
2024-01-04 03:02:32 +08:00
|
|
|
"CURSES_LIBRARY_LIST=${CURSES_LIBRARY_LIST}"
|
2024-01-13 14:17:50 +08:00
|
|
|
"${FISH_PCRE2_BUILDFLAG}"
|
2023-04-19 22:45:25 +08:00
|
|
|
)
|