Skip to content

Commit

Permalink
Get version from git automatically
Browse files Browse the repository at this point in the history
Additionally, feeder now prints its version on start.
  • Loading branch information
kitlith committed Mar 10, 2022
1 parent 6b9263f commit c0284a9
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 4 deletions.
27 changes: 23 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
cmake_minimum_required(VERSION 3.15)
#set(CMAKE_TOOLCHAIN_FILE "${CMAKE_CURRENT_SOURCE_DIR}/vcpkg/scripts/buildsystems/vcpkg.cmake")
include("${CMAKE_CURRENT_SOURCE_DIR}/vcpkg/scripts/buildsystems/vcpkg.cmake")
project(SlimeVR-Feeder-App LANGUAGES CXX VERSION 0.2.3)

project(SlimeVR-Feeder-App LANGUAGES CXX)

set_property(GLOBAL PROPERTY USE_FOLDERS ON)

Expand All @@ -15,13 +16,21 @@ set(protos_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR}/protos)
add_executable("${PROJECT_NAME}" "src/main.cpp" "src/pathtools_excerpt.cpp" "src/pathtools_excerpt.h" "src/matrix_utils.cpp" "src/matrix_utils.h" "src/bridge.cpp" "src/bridge.hpp" "src/setup.cpp" "src/setup.hpp" "ProtobufMessages.proto")
target_link_libraries("${PROJECT_NAME}" PRIVATE "${OPENVR_LIB}" fmt::fmt protobuf::libprotobuf)
protobuf_generate(TARGET "${PROJECT_NAME}" LANGUAGE cpp PROTOC_OUT_DIR ${protos_OUTPUT_DIR})
target_include_directories("${PROJECT_NAME}" PUBLIC ${protos_OUTPUT_DIR})
target_include_directories("${PROJECT_NAME}" PUBLIC ${protos_OUTPUT_DIR} PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
target_compile_features("${PROJECT_NAME}" PRIVATE cxx_std_17)

# IDE Config
source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}/src" PREFIX "Header Files" FILES ${HEADERS})
source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}/src" PREFIX "Source Files" FILES ${SOURCES})

add_custom_command(TARGET SlimeVR-Feeder-App
PRE_BUILD
COMMAND ${CMAKE_COMMAND}
-Dlocal_dir="${CMAKE_CURRENT_SOURCE_DIR}"
-Doutput_dir="${CMAKE_CURRENT_BINARY_DIR}"
-P "${CMAKE_CURRENT_SOURCE_DIR}/cmake/gitversion.cmake"
)

install(DIRECTORY "${PROJECT_SOURCE_DIR}/bindings"
DESTINATION "."
)
Expand All @@ -38,9 +47,19 @@ install(TARGETS "${PROJECT_NAME}"
DESTINATION .
)

set(CPACK_SYSTEM_NAME ${CMAKE_SYSTEM_NAME})
if(${CPACK_SYSTEM_NAME} MATCHES Windows)
if(CMAKE_CL_64)
set(CPACK_SYSTEM_NAME win64)
set(CPACK_IFW_TARGET_DIRECTORY "@RootDir@/Program Files/${CMAKE_PROJECT_NAME}")
else()
set(CPACK_SYSTEM_NAME win32)
endif()
endif()

set(CPACK_PROJECT_NAME ${PROJECT_NAME})
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
set(CPACK_PACKAGE_FILE_NAME ${CPACK_PROJECT_NAME}-${CPACK_SYSTEM_NAME})
set(CPACK_GENERATOR "ZIP")
set(CPACK_INCLUDE_TOPLEVEL_DIRECTORY ON)
set(CPACK_VERBATIM_VARIABLES YES)
include(CPack)
include(CPack)
19 changes: 19 additions & 0 deletions cmake/gitversion.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
cmake_minimum_required(VERSION 3.15)

set(_build_version "unknown")

find_package(Git)
if (GIT_FOUND)
execute_process(
COMMAND ${GIT_EXECUTABLE} describe --tags
WORKING_DIRECTORY "${local_dir}"
OUTPUT_VARIABLE _build_version
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE
)
message(STATUS "version in git: ${_build_version}")
else()
message(STATUS "git not found")
endif()

configure_file("${local_dir}/cmake/version.h.in" "${output_dir}/version.h" @ONLY)
3 changes: 3 additions & 0 deletions cmake/version.h.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#pragma once

static constexpr char *version = "@_build_version@";
3 changes: 3 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "matrix_utils.h"
#include "bridge.hpp"
#include "setup.hpp"
#include "version.h"
#include <ProtobufMessages.pb.h>

using namespace vr;
Expand Down Expand Up @@ -445,6 +446,8 @@ int main(int argc, char* argv[]) {
return handle_setup(install);
}

fmt::print("SlimeVR-Feeder-App version {}\n\n", version);

EVRInitError init_error = VRInitError_None;
EVRInputError input_error = VRInputError_None;

Expand Down

0 comments on commit c0284a9

Please sign in to comment.