Skip to content

Commit

Permalink
ci: Use modern CMake command options in ci_verify_cmake.sh
Browse files Browse the repository at this point in the history
Due to raising the minimum CMake version to 3.14, we can now run the
CMake build verification (ci_verify_cmake.sh) from the libpng source
dir, just as in the other scripts (ci_verify_*.sh). This is possible
thanks to the modern CMake command options `cmake -B` and `cmake -S`.

We can finally simplify the implementation of ci_verify_cmake.sh by
removing a code complication that was annoying, and yet, necessary in
peculiar Bash-on-Windows setups.

Fun fact:
CMake version 3.14 was released on 2019-03-14. Reportedly, on purpose!
  • Loading branch information
ctruta committed Oct 6, 2024
1 parent 2e416c6 commit 558dfbb
Showing 1 changed file with 9 additions and 22 deletions.
31 changes: 9 additions & 22 deletions ci/ci_verify_cmake.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,6 @@ CI_OUT_DIR="$CI_TOPLEVEL_DIR/out"
CI_BUILD_DIR="$CI_OUT_DIR/ci_verify_cmake.$CI_TARGET_SYSTEM.$CI_TARGET_ARCH.build"
CI_INSTALL_DIR="$CI_OUT_DIR/ci_verify_cmake.$CI_TARGET_SYSTEM.$CI_TARGET_ARCH.install"

# Keep the following relative paths in sync with the absolute paths.
# We use them for the benefit of native Windows tools that might be
# otherwise confused by the path encoding used by Bash-on-Windows.
CI_BUILD_TO_SRC_RELDIR="../.."
CI_BUILD_TO_INSTALL_RELDIR="../ci_verify_cmake.$CI_TARGET_SYSTEM.$CI_TARGET_ARCH.install"

function ci_init_build {
# Ensure that the mandatory variables are initialized.
CI_CMAKE="${CI_CMAKE:-cmake}"
Expand Down Expand Up @@ -148,40 +142,33 @@ function ci_build {
all_cmake_build_flags+=($CI_CMAKE_BUILD_FLAGS)
all_ctest_flags+=($CI_CTEST_FLAGS)
# And... build!
# Use $CI_BUILD_TO_SRC_RELDIR and $CI_BUILD_TO_INSTALL_RELDIR
# instead of $CI_SRC_DIR and $CI_INSTALL_DIR from this point onwards.
ci_spawn mkdir -p "$CI_BUILD_DIR"
ci_spawn cd "$CI_BUILD_DIR"
[[ $CI_BUILD_TO_SRC_RELDIR -ef $CI_SRC_DIR ]] || {
ci_err_internal "bad or missing \$CI_BUILD_TO_SRC_RELDIR"
}
ci_spawn mkdir -p "$CI_INSTALL_DIR"
[[ $CI_BUILD_TO_INSTALL_RELDIR -ef $CI_INSTALL_DIR ]] || {
ci_err_internal "bad or missing \$CI_BUILD_TO_INSTALL_RELDIR"
}
# Spawn "cmake ...".
ci_spawn "$CI_CMAKE" -DCMAKE_INSTALL_PREFIX="$CI_BUILD_TO_INSTALL_RELDIR" \
"${all_cmake_vars[@]}" \
"$CI_BUILD_TO_SRC_RELDIR"
ci_spawn "$CI_CMAKE" -B "$CI_BUILD_DIR" \
-S . \
-DCMAKE_INSTALL_PREFIX="$CI_INSTALL_DIR" \
"${all_cmake_vars[@]}"
# Spawn "cmake --build ...".
ci_spawn "$CI_CMAKE" --build . \
ci_spawn "$CI_CMAKE" --build "$CI_BUILD_DIR" \
--config "$CI_CMAKE_BUILD_TYPE" \
"${all_cmake_build_flags[@]}"
ci_expr $((CI_NO_TEST)) || {
# Spawn "ctest" if testing is not disabled.
ci_spawn pushd "$CI_BUILD_DIR"
ci_spawn "$CI_CTEST" --build-config "$CI_CMAKE_BUILD_TYPE" \
"${all_ctest_flags[@]}"
ci_spawn popd
}
ci_expr $((CI_NO_INSTALL)) || {
# Spawn "cmake --build ... --target install" if installation is not disabled.
ci_spawn "$CI_CMAKE" --build . \
ci_spawn "$CI_CMAKE" --build "$CI_BUILD_DIR" \
--config "$CI_CMAKE_BUILD_TYPE" \
--target install \
"${all_cmake_build_flags[@]}"
}
ci_expr $((CI_NO_CLEAN)) || {
# Spawn "make --build ... --target clean" if cleaning is not disabled.
ci_spawn "$CI_CMAKE" --build . \
ci_spawn "$CI_CMAKE" --build "$CI_BUILD_DIR" \
--config "$CI_CMAKE_BUILD_TYPE" \
--target clean \
"${all_cmake_build_flags[@]}"
Expand Down

0 comments on commit 558dfbb

Please sign in to comment.