Skip to content

Commit

Permalink
try to make sure that object files depending on the version header re…
Browse files Browse the repository at this point in the history
…build every time
  • Loading branch information
adam-ce committed Nov 16, 2023
1 parent 1929657 commit 7131954
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 20 deletions.
2 changes: 1 addition & 1 deletion app/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ int main(int argc, char **argv)
engine.rootContext()->setContextProperty("_hotreloader", &hotreloader);
engine.rootContext()->setContextProperty("_qmlPath", "");
engine.rootContext()->setContextProperty("_positionList", QVariant::fromValue(nucleus::camera::PositionStorage::instance()->getPositionList()));
engine.rootContext()->setContextProperty("_alpine_renderer_version", nucleus::version);
engine.rootContext()->setContextProperty("_alpine_renderer_version", QString::fromStdString(nucleus::version()));

RenderThreadNotifier::instance();
QObject::connect(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@

find_package(Git 2.22 REQUIRED)

get_filename_component(ALP_VERSION_HEADER_SRC_DIR ${ALP_VERSION_HEADER_SRC} DIRECTORY)
get_filename_component(ALP_VERSION_TEMPLATE_DIR ${ALP_VERSION_TEMPLATE} DIRECTORY)

execute_process(COMMAND ${GIT_EXECUTABLE} describe --tags --dirty=-d --abbrev=1
WORKING_DIRECTORY ${ALP_VERSION_HEADER_SRC_DIR}
WORKING_DIRECTORY ${ALP_VERSION_TEMPLATE_DIR}
RESULT_VARIABLE git_version_result
OUTPUT_STRIP_TRAILING_WHITESPACE
OUTPUT_VARIABLE ALP_VERSION)
Expand All @@ -31,7 +31,8 @@ if (${git_version_result})
message(WARNING "Retrieving version string from git was not successfull. Setting it to 'vUnknown'")
set(${output_variable} "vUnknown" PARENT_SCOPE)
else()
string(REPLACE "-g" "." ALP_VERSION ${ALP_VERSION})
string(REPLACE "-" "." ALP_VERSION ${ALP_VERSION})
endif()

configure_file(${ALP_VERSION_HEADER_SRC} ${ALP_VERSION_HEADER_DST} @ONLY)
configure_file(${ALP_VERSION_TEMPLATE} ${ALP_VERSION_DESTINATION} @ONLY)
29 changes: 14 additions & 15 deletions nucleus/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,23 @@ target_include_directories(zppbits INTERFACE ${zppbits_SOURCE_DIR})
add_library(tl_expected INTERFACE)
target_include_directories(tl_expected INTERFACE ${tl_expected_SOURCE_DIR}/include)

execute_process(COMMAND ${CMAKE_COMMAND}
-D ALP_VERSION_HEADER_SRC=${CMAKE_CURRENT_SOURCE_DIR}/version.h.in
-D ALP_VERSION_HEADER_DST=${CMAKE_BINARY_DIR}/alp_version_header_include/nucleus/version.h
-P ${CMAKE_SOURCE_DIR}/cmake/alp_generate_version_header.cmake
RESULT_VARIABLE alp_version_header_result)
if (${alp_version_header_result})
message(FATAL_ERROR "Generating the version header failed")
endif()
set(alp_version_out ${CMAKE_BINARY_DIR}/alp_version/nucleus/version.cpp)

add_custom_target(version_header
${CMAKE_COMMAND} -D ALP_VERSION_HEADER_SRC=${CMAKE_CURRENT_SOURCE_DIR}/version.h.in
-D ALP_VERSION_HEADER_DST=${CMAKE_BINARY_DIR}/alp_version_header_include/nucleus/version.h
-P ${CMAKE_SOURCE_DIR}/cmake/alp_generate_version_header.cmake
# cmake tests for existance of ${alp_version_out}.do_always_run. since it's always missing, cmake tries to generate it using this command.
# this makes sure, that the command is always run. ${alp_version_out} is not always updated, so nucleus_version is only recompiled
# if the version really changes.
add_custom_command(
OUTPUT ${alp_version_out} ${alp_version_out}.do_always_run
COMMAND ${CMAKE_COMMAND} -D ALP_VERSION_TEMPLATE=${CMAKE_CURRENT_SOURCE_DIR}/version.cpp.in
-D ALP_VERSION_DESTINATION=${alp_version_out}
-P ${CMAKE_SOURCE_DIR}/cmake/alp_generate_version_file.cmake
COMMENT "Updating ${alp_version_out}"
)

add_library(nucleus_version STATIC ${CMAKE_BINARY_DIR}/alp_version_header_include/nucleus/version.h)
add_dependencies(nucleus_version version_header)
target_include_directories(nucleus_version PUBLIC ${CMAKE_BINARY_DIR}/alp_version_header_include)
add_library(nucleus_version STATIC
version.h
${alp_version_out}
)

qt_add_library(nucleus STATIC
AbstractRenderWindow.h AbstractRenderWindow.cpp
Expand Down
27 changes: 27 additions & 0 deletions nucleus/version.cpp.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*****************************************************************************
* Alpine Terrain Builder
* Copyright (C) 2023 Adam Celarek
* Copyright (C) 2015 Taylor Braun-Jones (via github.com/nocnokneo/cmake-git-versioning-example)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/

#include <string>

namespace nucleus {
// constexpr auto version = "@ALP_VERSION@";
std::string version() {
return "@ALP_VERSION@";
}
}
4 changes: 3 additions & 1 deletion nucleus/version.h.in → nucleus/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

#pragma once

#include <string>

namespace nucleus {
constexpr auto version = "@ALP_VERSION@";
std::string version();
}

0 comments on commit 7131954

Please sign in to comment.