Skip to content

Commit

Permalink
Develop (#86)
Browse files Browse the repository at this point in the history
* trying to fix auto-versioning from git

* tweaking autoversioning

* HDRVIEW_DEPLOY no longer neeed

* Update VersionFromGit.cmake
  • Loading branch information
wkjarosz authored Jul 21, 2022
1 parent 575ce6d commit 73a9722
Show file tree
Hide file tree
Showing 12 changed files with 219 additions and 102 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci-mac.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ jobs:
- name: Configure CMake (Metal backend)
run: |
MACOSX_DEPLOYMENT_TARGET=10.15
cmake -B ${{github.workspace}}/build-metal -DHDRVIEW_DEPLOY=1 -DCMAKE_OSX_DEPLOYMENT_TARGET=10.15 -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DNANOGUI_BACKEND=Metal -DCMAKE_OSX_ARCHITECTURES="arm64;x86_64"
cmake -B ${{github.workspace}}/build-metal -DHDRVIEW_DEPLOY=1 -DCMAKE_OSX_DEPLOYMENT_TARGET=10.15 -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DNANOGUI_BACKEND=Metal -DCMAKE_OSX_ARCHITECTURES="arm64;x86_64"
cmake -B ${{github.workspace}}/build-metal -DCMAKE_OSX_DEPLOYMENT_TARGET=10.15 -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DNANOGUI_BACKEND=Metal -DCMAKE_OSX_ARCHITECTURES="arm64;x86_64"
cmake -B ${{github.workspace}}/build-metal -DCMAKE_OSX_DEPLOYMENT_TARGET=10.15 -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DNANOGUI_BACKEND=Metal -DCMAKE_OSX_ARCHITECTURES="arm64;x86_64"
- name: Build (Metal backend)
run: cmake --build ${{github.workspace}}/build-metal --parallel --config ${{env.BUILD_TYPE}}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ jobs:
- name: Configure CMake (Metal backend)
run: |
MACOSX_DEPLOYMENT_TARGET=10.15
cmake -B ${{github.workspace}}/build-metal -DHDRVIEW_DEPLOY=1 -DCMAKE_OSX_DEPLOYMENT_TARGET=10.15 -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DNANOGUI_BACKEND=Metal -DCMAKE_OSX_ARCHITECTURES="arm64;x86_64"
cmake -B ${{github.workspace}}/build-metal -DHDRVIEW_DEPLOY=1 -DCMAKE_OSX_DEPLOYMENT_TARGET=10.15 -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DNANOGUI_BACKEND=Metal -DCMAKE_OSX_ARCHITECTURES="arm64;x86_64"
cmake -B ${{github.workspace}}/build-metal -DCMAKE_OSX_DEPLOYMENT_TARGET=10.15 -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DNANOGUI_BACKEND=Metal -DCMAKE_OSX_ARCHITECTURES="arm64;x86_64"
cmake -B ${{github.workspace}}/build-metal -DCMAKE_OSX_DEPLOYMENT_TARGET=10.15 -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DNANOGUI_BACKEND=Metal -DCMAKE_OSX_ARCHITECTURES="arm64;x86_64"
- name: Build (Metal backend)
run: cmake --build ${{github.workspace}}/build-metal --parallel --config ${{env.BUILD_TYPE}}
Expand Down
37 changes: 19 additions & 18 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,31 +1,35 @@
cmake_minimum_required(VERSION 3.13)

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/" "${CMAKE_SOURCE_DIR}/resources")

include(VersionFromGit)

STRING(TIMESTAMP BUILD_TIME "%Y-%m-%d %H:%M")
message(STATUS "Saving build timestamp: ${BUILD_TIME}")

version_from_git(
LOG ON
TIMESTAMP "%Y-%m-%d-%H:%M:%S"
)

project(
hdrview
DESCRIPTION "A simple research-oriented image viewer with an emphasis on examining and comparing high-dynamic range (HDR) images."
VERSION ${VERSION}
LANGUAGES C CXX
)

# Add a custom command that produces hdrview_version.cpp, plus a dummy output that's not actually produced, in order to
# force version.cmake to always be re-run before the build
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/hdrview_version.cpp ${CMAKE_CURRENT_BINARY_DIR}/_hdrview_version.cpp
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_SOURCE_DIR}/resources/version.cmake
COMMENT "Generating timestamp and git version info")

set(HDRVIEW_VERSION "${GIT_TAG}")

if (NOT HDRVIEW_DEPLOY)
set(HDRVIEW_VERSION "${HDRVIEW_VERSION}dev")
endif()
set(HDRVIEW_VERSION "${GIT_DESCRIBE}")

if (CMAKE_SIZEOF_VOID_P EQUAL 8)
set(HDRVIEW_VERSION "${HDRVIEW_VERSION} (64 bit)")
elseif (CMAKE_SIZEOF_VOID_P EQUAL 4)
set(HDRVIEW_VERSION "${HDRVIEW_VERSION} (32 bit)")
endif()

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/cmake/" "${CMAKE_SOURCE_DIR}/resources")
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/common.cpp.in ${CMAKE_CURRENT_BINARY_DIR}/common.cpp @ONLY)


include(sanitizers)

# Set ourselves as the startup project in visual studio.
Expand Down Expand Up @@ -340,7 +344,6 @@ include_directories(${CMAKE_CURRENT_BINARY_DIR})

add_executable(
HDRView
hdrview_version.cpp
hdrview_resources.cpp
src/filters/bilateral.cpp
src/filters/box_blur.cpp
Expand Down Expand Up @@ -375,7 +378,7 @@ add_executable(
src/colorwheel.cpp
src/colorwheel.h
src/commandhistory.h
src/common.cpp
common.cpp
src/common.h
src/dialog.cpp
src/dialog.h
Expand Down Expand Up @@ -435,7 +438,6 @@ add_executable(
src/well.h
${EXTRA_SOURCE})

set(HDRVIEW_DEFINITIONS -DHDRVIEW_VERSION="${HDRVIEW_VERSION}")
if(WIN32)
set(HDRVIEW_DEFINITIONS ${HDRVIEW_DEFINITIONS} -DNOMINMAX)
endif()
Expand Down Expand Up @@ -475,12 +477,11 @@ endif()

add_executable(
hdrbatch
hdrview_version.cpp
src/cliformatter.h
src/color.h
src/colorspace.cpp
src/colorspace.h
src/common.cpp
common.cpp
src/common.h
src/envmap.cpp
src/envmap.h
Expand Down
169 changes: 169 additions & 0 deletions cmake/VersionFromGit.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
# The MIT License (MIT)
#
# Copyright (c) 2016-2017 Theo Willows
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

cmake_minimum_required( VERSION 3.0.0 )

include( CMakeParseArguments )

function( version_from_git )
# Parse arguments
set( options OPTIONAL FAST )
set( oneValueArgs
GIT_EXECUTABLE
INCLUDE_HASH
LOG
TIMESTAMP
)
set( multiValueArgs )
cmake_parse_arguments( ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} )

# Defaults
if( NOT DEFINED ARG_INCLUDE_HASH )
set( ARG_INCLUDE_HASH ON )
endif()

if( DEFINED ARG_GIT_EXECUTABLE )
set( GIT_EXECUTABLE "${ARG_GIT_EXECUTABLE}" )
else ()
# Find Git or bail out
find_package( Git )
if( NOT GIT_FOUND )
message( FATAL_ERROR "[VersionFromGit] Git not found" )
endif( NOT GIT_FOUND )
endif()

# Git describe
execute_process(
COMMAND "${GIT_EXECUTABLE}" describe --tags
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
RESULT_VARIABLE git_result
OUTPUT_VARIABLE git_describe
ERROR_VARIABLE git_error
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_STRIP_TRAILING_WHITESPACE
)
if( NOT git_result EQUAL 0 )
message( FATAL_ERROR
"[VersionFromGit] Failed to execute Git: ${git_error}"
)
endif()

# Get Git tag
execute_process(
COMMAND "${GIT_EXECUTABLE}" describe --tags --abbrev=0
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
RESULT_VARIABLE git_result
OUTPUT_VARIABLE git_tag
ERROR_VARIABLE git_error
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_STRIP_TRAILING_WHITESPACE
)
if( NOT git_result EQUAL 0 )
message( FATAL_ERROR
"[VersionFromGit] Failed to execute Git: ${git_error}"
)
endif()

if( git_tag MATCHES "^v(0|[1-9][0-9]*)[.](0|[1-9][0-9]*)[.](0|[1-9][0-9]*)(-[.0-9A-Za-z-]+)?([+][.0-9A-Za-z-]+)?$" )
set( version_major "${CMAKE_MATCH_1}" )
set( version_minor "${CMAKE_MATCH_2}" )
set( version_patch "${CMAKE_MATCH_3}" )
set( identifiers "${CMAKE_MATCH_4}" )
set( metadata "${CMAKE_MATCH_5}" )
else()
message( FATAL_ERROR
"[VersionFromGit] Git tag isn't valid semantic version: [${git_tag}]"
)
endif()

if( "${git_tag}" STREQUAL "${git_describe}" )
set( git_at_a_tag ON )
endif()

if( NOT git_at_a_tag )
# Extract the Git hash (if one exists)
string( REGEX MATCH "g[0-9a-f]+$" git_hash "${git_describe}" )
endif()

# Construct the version variables
set( version ${version_major}.${version_minor}.${version_patch} )
set( semver ${version} )

# Identifiers
if( identifiers MATCHES ".+" )
string( SUBSTRING "${identifiers}" 1 -1 identifiers )
set( semver "${semver}-${identifiers}")
endif()

# Metadata
# TODO Split and join (add Git hash inbetween)
if( metadata MATCHES ".+" )
string( SUBSTRING "${metadata}" 1 -1 metadata )
# Split
string( REPLACE "." ";" metadata "${metadata}" )
endif()

if( NOT git_at_a_tag )

if( ARG_INCLUDE_HASH )
list( APPEND metadata "${git_hash}" )
endif( ARG_INCLUDE_HASH )

# Timestamp
if( DEFINED ARG_TIMESTAMP )
string( TIMESTAMP timestamp "${ARG_TIMESTAMP}" ${ARG_UTC} )
list( APPEND metadata "${timestamp}" )
endif( DEFINED ARG_TIMESTAMP )

endif()

# Join
string( REPLACE ";" "." metadata "${metadata}" )

if( metadata MATCHES ".+" )
set( semver "${semver}+${metadata}")
endif()

# Log the results
if( ARG_LOG )
message( STATUS
"Version: ${version}
Git tag: [${git_tag}]
Git hash: [${git_hash}]
Decorated: [${git_describe}]
Identifiers: [${identifiers}]
Metadata: [${metadata}]
SemVer: [${semver}]"
)
endif( ARG_LOG )

# Set parent scope variables
set( GIT_TAG ${git_tag} PARENT_SCOPE )
set( GIT_HASH ${git_hash} PARENT_SCOPE )
set( GIT_DESCRIBE ${git_describe} PARENT_SCOPE )
set( SEMVER ${semver} PARENT_SCOPE )
set( VERSION ${version} PARENT_SCOPE )
set( VERSION_MAJOR ${version_major} PARENT_SCOPE )
set( VERSION_MINOR ${version_minor} PARENT_SCOPE )
set( VERSION_PATCH ${version_patch} PARENT_SCOPE )

endfunction( version_from_git )
4 changes: 2 additions & 2 deletions resources/create-dmg.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ BUILD_DIR="build-dmg"

mkdir $BUILD_DIR
MACOSX_DEPLOYMENT_TARGET=10.15
cmake -B $BUILD_DIR -DHDRVIEW_DEPLOY=1 -DCMAKE_OSX_DEPLOYMENT_TARGET=10.15 -DCMAKE_BUILD_TYPE=Release -DNANOGUI_BACKEND=Metal -DCMAKE_OSX_ARCHITECTURES="arm64;x86_64"
cmake -B $BUILD_DIR -DHDRVIEW_DEPLOY=1 -DCMAKE_OSX_DEPLOYMENT_TARGET=10.15 -DCMAKE_BUILD_TYPE=Release -DNANOGUI_BACKEND=Metal -DCMAKE_OSX_ARCHITECTURES="arm64;x86_64"
cmake -B $BUILD_DIR -DCMAKE_OSX_DEPLOYMENT_TARGET=10.15 -DCMAKE_BUILD_TYPE=Release -DNANOGUI_BACKEND=Metal -DCMAKE_OSX_ARCHITECTURES="arm64;x86_64"
cmake -B $BUILD_DIR -DCMAKE_OSX_DEPLOYMENT_TARGET=10.15 -DCMAKE_BUILD_TYPE=Release -DNANOGUI_BACKEND=Metal -DCMAKE_OSX_ARCHITECTURES="arm64;x86_64"
cmake --build $BUILD_DIR --parallel --config Release

echo "Creating dmg..."
Expand Down
4 changes: 2 additions & 2 deletions resources/create-exe.bat
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ call %DevCmd%
echo Building 64-bit hdrview...
mkdir %BuildDir64%
cd %BuildDir64%
cmake -DHDRVIEW_DEPLOY=1 -G "Visual Studio 15 2017 Win64" ..\..
cmake -G "Visual Studio 15 2017 Win64" ..\..
msbuild %MSBuildOptions% hdrview.sln
move "Release\HDRView.exe" "..\..\HDRView.exe"
cd ..
Expand All @@ -22,7 +22,7 @@ rmdir /S /Q %BuildDir64%
echo Building 32-bit hdrview...
mkdir %BuildDir32%
cd %BuildDir32%
cmake -DHDRVIEW_DEPLOY=1 -G "Visual Studio 15 2017" ..\..
cmake -G "Visual Studio 15 2017" ..\..
msbuild %MSBuildOptions% hdrview.sln
move "Release\HDRView.exe" "..\..\HDRView-32bit.exe"
cd ..
Expand Down
53 changes: 0 additions & 53 deletions resources/version.cmake

This file was deleted.

22 changes: 10 additions & 12 deletions src/common.cpp → src/common.cpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,18 @@

using namespace std;

// These variables are autogenerated and compiled
// into the project by the version.cmake script
extern const char *GIT_TAG;
extern const char *GIT_REV;
extern const char *GIT_BRANCH;
extern const char *HDRVIEW_BUILD_TIME;

const char *hdrview_git_version() { return GIT_TAG; }
const char *hdrview_git_revision() { return GIT_REV; }
const char *hdrview_git_branch() { return GIT_BRANCH; }
const char *hdrview_timestamp() { return HDRVIEW_BUILD_TIME; }

string config_directory() { return sago::getConfigHome() + "/HDRView/"; }

// These constants and strings are autogenerated and compiled
// into the project by cmake
int hdrview_version_major() { return @VERSION_MAJOR@; }
int hdrview_version_minor() { return @VERSION_MINOR@; }
int hdrview_version_patch() { return @VERSION_PATCH@; }
string hdrview_version() { return string("@HDRVIEW_VERSION@");}
string hdrview_git_hash() { return string("@GIT_HASH@"); }
string hdrview_git_describe() { return string("@GIT_DESCRIBE@"); }
string hdrview_build_timestamp() { return string("@BUILD_TIME@"); }

string get_extension(const string &filename)
{
if (filename.find_last_of(".") != string::npos)
Expand Down
Loading

0 comments on commit 73a9722

Please sign in to comment.