cmake: Do add dependencies

Unfortunately ninja does not want to be tricked.

I tried `touch`ing a file and writing the date to a file,
and even removing that file before cargo runs, it doesn't work.

So instead we'll do the imperfect solution of enumerating sources.

And yes, we use a GLOB because listing source files is terrible.
Any build system that wants you not to glob is a build system made for
build system people who like touching build systems, not me.
This commit is contained in:
Fabian Boehm
2024-02-03 09:55:16 +01:00
parent d9381d1ab6
commit 8e73a4c5af

View File

@@ -93,16 +93,10 @@ add_definitions(-DCMAKE_SOURCE_DIR="${REAL_CMAKE_SOURCE_DIR}")
# Enable thread-safe errno on Solaris (#5611)
add_definitions(-D_REENTRANT)
# Cmake doesn't know when cargo should be rerun.
# We could enumerate when (source files changed, Cargo.toml/lock, cargo update, ...),
# but that's a pain and cargo takes <100ms when there's nothing to do,
# so we can just always rerun it.
# So this adds a dummy command that is successful but creates no output,
# and then depend on it.
add_custom_command(
OUTPUT always_rebuild
COMMAND echo
)
# cargo needs to be rerun when the sources change.
# This is imperfect, but the ninja generator really wants to
# not run cargo, so we need to tell it *something*
FILE(GLOB sources src/*)
add_custom_command(
OUTPUT ${rust_target_dir}/${rust_profile}/libfish.rlib
@@ -117,7 +111,8 @@ add_custom_command(
${FEATURES_ARG}
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
USES_TERMINAL
DEPENDS always_rebuild
DEPENDS ${sources}
DEPENDS Cargo.toml Cargo.lock build.rs
# Don't use VERBATIM here, to allow the generator expressions above to expand to nothing rather than an empty string
)
add_custom_target(libfish DEPENDS ${rust_target_dir}/${rust_profile}/libfish.rlib)