CMake: Fix version generation: regenare on every build
This commit is contained in:
parent
742266fe82
commit
7699b20498
2 changed files with 33 additions and 34 deletions
|
@ -1,25 +1,6 @@
|
|||
cmake_minimum_required(VERSION 3.16)
|
||||
project(endgame-analyzer CXX)
|
||||
|
||||
execute_process(
|
||||
COMMAND git describe
|
||||
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
||||
OUTPUT_VARIABLE GIT_DESCRIPTION
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
)
|
||||
|
||||
execute_process(
|
||||
COMMAND git -c log.showsignature=false log -1 --format=%h
|
||||
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
||||
OUTPUT_VARIABLE GIT_COMMIT_HASH
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
)
|
||||
|
||||
configure_file(
|
||||
${CMAKE_SOURCE_DIR}/include/version.h.in
|
||||
${CMAKE_BINARY_DIR}/generated/version.h
|
||||
)
|
||||
include_directories(${CMAKE_BINARY_DIR}/generated)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wpedantic -Werror")
|
||||
|
@ -41,26 +22,39 @@ set(Boost_USE_STATIC_LIBS ON)
|
|||
include_directories(.)
|
||||
include_directories(${Boost_INCLUDE_DIR})
|
||||
|
||||
set(SOURCES
|
||||
src/state_explorer.cpp
|
||||
src/download.cpp
|
||||
src/command_line_interface.cpp
|
||||
src/parse_game.cpp
|
||||
src/hanabi_types.cpp
|
||||
src/game_interface.cpp
|
||||
src/make_state.cpp
|
||||
)
|
||||
|
||||
# Include git module from https://github.com/rpavlik/cmake-modules to
|
||||
# dynamically include git revisions into the build.
|
||||
# This re-generates the file version.cpp whenever the git HEAD changes.
|
||||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake-modules/")
|
||||
include(GetGitRevisionDescription)
|
||||
get_git_head_revision(GIT_REFSPEC GIT_SHA1)
|
||||
git_describe(GIT_DESCRIPTION)
|
||||
git_local_changes(GIT_LOCAL_CHANGES)
|
||||
configure_file(
|
||||
${CMAKE_SOURCE_DIR}/src/version.cpp.in
|
||||
${CMAKE_CURRENT_BINARY_DIR}/generated/version.cpp
|
||||
)
|
||||
list(APPEND SOURCES ${CMAKE_CURRENT_BINARY_DIR}/generated/version.cpp)
|
||||
|
||||
|
||||
add_executable(endgame-analyzer
|
||||
src/main.cpp
|
||||
src/state_explorer.cpp
|
||||
src/download.cpp
|
||||
src/command_line_interface.cpp
|
||||
src/parse_game.cpp
|
||||
src/hanabi_types.cpp
|
||||
src/game_interface.cpp
|
||||
src/make_state.cpp
|
||||
${SOURCES}
|
||||
)
|
||||
|
||||
add_executable(unit-tests
|
||||
test/unit_test.cpp
|
||||
src/state_explorer.cpp
|
||||
src/download.cpp
|
||||
src/command_line_interface.cpp
|
||||
src/parse_game.cpp
|
||||
src/hanabi_types.cpp
|
||||
src/game_interface.cpp
|
||||
src/make_state.cpp
|
||||
${SOURCES}
|
||||
)
|
||||
|
||||
target_link_libraries(endgame-analyzer cpr)
|
||||
|
|
|
@ -39,7 +39,12 @@ namespace Hanabi
|
|||
int run_cli(CLIParms const & parms)
|
||||
{
|
||||
if (parms.version_info) {
|
||||
std::cout << "endgame-analyzer " << VERSION_GIT_DESCRIPTION << " (commit " << VERSION_GIT_COMMIT_HASH << ")";
|
||||
std::cout << "endgame-analyzer " << Version::git_description << " (commit ";
|
||||
std::cout.write(Version::git_sha1.data(), 8) << ")" << std::endl;
|
||||
if (Version::is_dirty())
|
||||
{
|
||||
std::cout << "Warning: The repository contains local changes that are not part of the build." << std::endl;
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
// We want to do this sanity check here again,
|
||||
|
|
Loading…
Reference in a new issue