Skip to content

Commit

Permalink
Merge pull request #970 from dimacurrentai/cmake_current_build
Browse files Browse the repository at this point in the history
  • Loading branch information
dkorolev authored Mar 12, 2024
2 parents eea24f7 + 298ef99 commit 62b7644
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
11 changes: 3 additions & 8 deletions cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,14 @@ endfunction()
UseGitOrClone(https://github.com/c5t/current)
UseGitOrClone(https://github.com/c5t/googletest)

add_custom_target(C5T_CURRENT_BUILD_H_TARGET ALL DEPENDS "${C5T_DEP_DIR_current}/current_build.h")

add_custom_command(OUTPUT "${C5T_DEP_DIR_current}/current_build.h"
COMMAND "${C5T_DEP_DIR_current}/scripts/gen-current-build.sh"
ARGS "${C5T_DEP_DIR_current}/current_build.h"
DEPENDS src)

add_custom_target(C5T_CURRENT_BUILD_INFO_H_TARGET ALL DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/inc/current_build_info.h")

add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/inc/current_build_info.h"
COMMAND "${C5T_DEP_DIR_current}/scripts/gen-current-build.sh"
ARGS "${CMAKE_CURRENT_BINARY_DIR}/inc/current_build_info.h"
DEPENDS src)
DEPENDS inc/current_build_info.h.force_rebuild)

add_custom_command(OUTPUT inc/current_build_info.h.force_rebuild COMMAND cmake -E echo >/dev/null)

set(C5T_LIBRARIES "Threads::Threads" "C5T")

Expand Down
10 changes: 7 additions & 3 deletions cmake/run-cmake-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -94,16 +94,17 @@ echo "::endgroup::"

echo

# Test that the `current_build.h` file is generated automatically for each build.
# Test that the `current_build_info.h` file is [re-]generated automatically for each build.
echo "::group::build build_info"
cat >src/build_info.cc <<EOF
#include <iostream>
#ifndef C5T_CMAKE_PROJECT
#error "'C5T_CMAKE_PROJECT' is not defined, are you using Current under 'cmake' with the proper 'CMakeLists.txt'?"
#endif
#include "current_build.h"
#include "current_build_info.h"
int main() {
std::cout << "Successfully built at: " << current::build::cmake::kBuildDateTime << std::endl;
std::cout << "Autogen .h 'date +%s': " << current::build::cmake::kCurrentBuildHeaderUnixEpochSeconds << std::endl;
}
EOF
make
Expand All @@ -117,10 +118,13 @@ echo "::endgroup::"

echo

echo "::group::re-run build_info"
echo "::group::re-build build_info after sleep 1"
sleep 1
touch src/build_info.cc
make
echo "::endgroup::"

echo "::group::re-run build_info"
.current/build_info
echo "::endgroup::"

Expand Down

0 comments on commit 62b7644

Please sign in to comment.