Skip to content

Commit

Permalink
build stamp in its own cu and make it a cmake dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
cpichard committed Mar 11, 2023
1 parent 1779405 commit 944074d
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 10 deletions.
9 changes: 5 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ else ()
endif (DEFINED glfw3_DIR)

# Get the stamp informations, git hash, time stamp, stuff like that
add_custom_command(
OUTPUT src/Stamp.h
add_custom_target(stamp
BYPRODUCTS src/Stamp.h src/Stamp.cpp
COMMAND ${CMAKE_COMMAND}
-DSRC_DIR="${CMAKE_CURRENT_SOURCE_DIR}"
-DDST_DIR="${CMAKE_CURRENT_SOURCE_DIR}/src"
Expand All @@ -42,14 +42,15 @@ if (APPLE)
set(myApp_ICON ${CMAKE_CURRENT_SOURCE_DIR}/src/resources/icon.icns)
set_source_files_properties(${myApp_ICON} PROPERTIES MACOSX_PACKAGE_LOCATION "Resources")

add_executable(usdtweak MACOSX_BUNDLE src/Stamp.h ${myApp_ICON})
add_executable(usdtweak MACOSX_BUNDLE ${myApp_ICON})

set_target_properties(usdtweak PROPERTIES
OUTPUT_NAME "usdtweak"
MACOSX_BUNDLE TRUE)
else()
add_executable(usdtweak src/Stamp.h)
add_executable(usdtweak)
endif()
add_dependencies(usdtweak stamp)

add_subdirectory(src)

Expand Down
6 changes: 5 additions & 1 deletion cmake/stamp.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ endif()

# Get the current time
string(TIMESTAMP BUILD_DATE "%Y.%m.%d")
configure_file(${SRC_DIR}/cmake/stamp.h.in ${DST_DIR}/Stamp.h @ONLY)
if(NOT EXISTS ${DST_DIR}/Stamp.h)
execute_process(COMMAND ${CMAKE_COMMAND} -E copy ${SRC_DIR}/cmake/stamp.h.in ${DST_DIR}/Stamp.h)
endif()

configure_file(${SRC_DIR}/cmake/stamp.cpp.in ${DST_DIR}/Stamp.cpp @ONLY)


4 changes: 4 additions & 0 deletions cmake/stamp.cpp.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#include "Stamp.h"

const char *GetGitHash() { return "@GIT_HASH@"; }
const char *GetBuildDate() { return "@BUILD_DATE@"; }
7 changes: 4 additions & 3 deletions cmake/stamp.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

#define STRINGIFY2(s) #s
#define STRINGIFY(s) STRINGIFY2(s)

#define GIT_HASH "@GIT_HASH@"
#define BUILD_DATE "@BUILD_DATE@"
#define USD_VERSION "" STRINGIFY(PXR_MINOR_VERSION) "." STRINGIFY(PXR_PATCH_VERSION)

const char *GetGitHash();
const char *GetBuildDate();

2 changes: 2 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ target_sources(usdtweak PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/UsdHelpers.h
${CMAKE_CURRENT_SOURCE_DIR}/Selection.cpp
${CMAKE_CURRENT_SOURCE_DIR}/Selection.h
${CMAKE_CURRENT_SOURCE_DIR}/Stamp.cpp
${CMAKE_CURRENT_SOURCE_DIR}/Stamp.h
${CMAKE_CURRENT_SOURCE_DIR}/main.cpp
)

Expand Down
4 changes: 2 additions & 2 deletions src/Editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ inline void BringWindowToTabFront(const char *windowName) {
struct AboutModalDialog : public ModalDialog {
AboutModalDialog(Editor& editor) : editor(editor) {}
void Draw() override {
ImGui::Text("usdtweak pre-alpha version " BUILD_DATE);
ImGui::Text(" revision " GIT_HASH);
ImGui::Text("usdtweak pre-alpha version %s", GetBuildDate());
ImGui::Text(" revision %s", GetGitHash());
ImGui::Text("");
ImGui::Text("This is a pre-alpha version for testing purpose.");
ImGui::Text("Please send your feedbacks as github issues:");
Expand Down

0 comments on commit 944074d

Please sign in to comment.