2
0
Эх сурвалжийг харах

Fixes an issue where the engine cmake version wasn't pulled from engine.json (#14183)

Signed-off-by: Alex Peterson <[email protected]>
Alex Peterson 2 жил өмнө
parent
commit
cca0eb1b4e

+ 3 - 3
CMakeLists.txt

@@ -17,6 +17,8 @@ if(NOT ${CMAKE_VERSION} VERSION_LESS "3.24")
 endif()
 
 include(cmake/LySet.cmake)
+include(cmake/GeneralSettings.cmake)
+include(cmake/FileUtil.cmake)
 include(cmake/Version.cmake)
 include(cmake/OutputDirectory.cmake)
 
@@ -24,7 +26,7 @@ if(NOT PROJECT_NAME)
     include(cmake/CompilerSettings.cmake)
     project(O3DE
         LANGUAGES C CXX
-        VERSION ${O3DE_VERSION_STRING}
+        VERSION ${O3DE_INSTALL_VERSION_STRING}
     )
 endif()
 
@@ -32,8 +34,6 @@ endif()
 # Initialize
 ################################################################################
 include(CTest)
-include(cmake/GeneralSettings.cmake)
-include(cmake/FileUtil.cmake)
 include(cmake/PAL.cmake)
 include(cmake/PALTools.cmake)
 include(cmake/RuntimeDependencies.cmake)

+ 1 - 1
Code/Editor/CMakeLists.txt

@@ -129,7 +129,7 @@ ly_add_source_properties(
     PROPERTY COMPILE_DEFINITIONS 
     VALUES 
         O3DE_COPYRIGHT_YEAR=${O3DE_COPYRIGHT_YEAR}
-        O3DE_BUILD_VERSION=${O3DE_BUILD_VERSION}
+        O3DE_BUILD_VERSION=${O3DE_INSTALL_BUILD_VERSION}
         ${LY_PAL_TOOLS_DEFINES}
 )
 ly_add_source_properties(

+ 2 - 2
Code/Tools/CrashHandler/CMakeLists.txt

@@ -36,7 +36,7 @@ ly_add_target(
             AZ::AzFramework
 )
 
-string(REPLACE "." ";" version_list "${O3DE_VERSION_STRING}")
+string(REPLACE "." ";" version_list "${O3DE_INSTALL_VERSION_STRING}")
 list(GET version_list 0 EXE_VERSION_INFO_0)
 list(GET version_list 1 EXE_VERSION_INFO_1)
 
@@ -57,7 +57,7 @@ ly_add_source_properties(
     SOURCES Shared/CrashHandler.cpp
     PROPERTY COMPILE_DEFINITIONS 
     VALUES
-        LY_BUILD=${O3DE_BUILD_VERSION}
+        LY_BUILD=${O3DE_INSTALL_BUILD_VERSION}
         EXE_VERSION_INFO_0=${EXE_VERSION_INFO_0}
         EXE_VERSION_INFO_1=${EXE_VERSION_INFO_1}
         EXE_VERSION_INFO_2=${EXE_VERSION_INFO_2}

+ 21 - 0
cmake/LySet.cmake

@@ -21,3 +21,24 @@ macro(ly_set name)
         set(${name} "${ARGN}" PARENT_SCOPE)
     endif()
 endmacro()
+
+#! o3de_set_from_env_with_default: convenient function to set a variable
+# from an environment variable or a default if the environment var is empty
+# and then run CONFIGURE on the result to replace all @sign variable references
+#
+# Example usage:
+# set(default "example")
+# o3de_set_from_env_with_default(var ENVVAR "@default@" CACHE STRING "Example string")
+# message(INFO "Result is ${var}")
+# Prints "Result is example" if no environment var named "ENVVAR" is set or is empty
+# 
+# \arg:name - name of output variable to set 
+# \arg:env_name - name of environment variable to use 
+# \argn - remaining args are passed to the set() command and should at least contain the value 
+macro(o3de_set_from_env_with_default name env_name)
+    set(${name} ${ARGN})
+    if(NOT "$ENV{${env_name}}" STREQUAL "")
+        set(${name} "$ENV{${env_name}}")
+    endif()
+    string(CONFIGURE ${${name}} ${name} @ONLY)
+endmacro()

+ 3 - 3
cmake/Packaging.cmake

@@ -53,10 +53,10 @@ set(CPACK_PACKAGE_CONTACT "[email protected]")
 # prefer the display engine version if available.
 # during development, the display version will be "00.00" or "" in which case we want
 # to use the actual engine version  
-if(NOT ((${O3DE_DISPLAY_VERSION_STRING} STREQUAL "00.00") OR (${O3DE_DISPLAY_VERSION_STRING} STREQUAL "")))
-    set(CPACK_PACKAGE_VERSION "${O3DE_DISPLAY_VERSION_STRING}")
+if(NOT ((${O3DE_INSTALL_DISPLAY_VERSION_STRING} STREQUAL "00.00") OR (${O3DE_INSTALL_DISPLAY_VERSION_STRING} STREQUAL "")))
+    set(CPACK_PACKAGE_VERSION "${O3DE_INSTALL_DISPLAY_VERSION_STRING}")
 else()
-    set(CPACK_PACKAGE_VERSION "${O3DE_VERSION_STRING}")
+    set(CPACK_PACKAGE_VERSION "${O3DE_INSTALL_VERSION_STRING}")
 endif()
 set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Installation Tool")
 

+ 1 - 1
cmake/Platform/Linux/Packaging_linux.cmake

@@ -8,7 +8,7 @@
 
 set(CPACK_GENERATOR DEB)
 
-set(CPACK_PACKAGING_INSTALL_PREFIX "/opt/${CPACK_PACKAGE_NAME}/${O3DE_VERSION_STRING}")
+set(CPACK_PACKAGING_INSTALL_PREFIX "/opt/${CPACK_PACKAGE_NAME}/${O3DE_INSTALL_VERSION_STRING}")
 
 set(_cmake_package_name "cmake-${CPACK_DESIRED_CMAKE_VERSION}-linux-x86_64")
 set(CPACK_CMAKE_PACKAGE_FILE "${_cmake_package_name}.tar.gz")

+ 1 - 1
cmake/Platform/Windows/Packaging_windows.cmake

@@ -46,7 +46,7 @@ function(generate_wix_guid out_value seed)
     set(${out_value} ${_guid} PARENT_SCOPE)
 endfunction()
 
-set(_guid_seed_base "${PROJECT_NAME}_${O3DE_VERSION_STRING}")
+set(_guid_seed_base "${PROJECT_NAME}_${O3DE_INSTALL_VERSION_STRING}")
 generate_wix_guid(_wix_default_product_guid "${_guid_seed_base}_ProductID" )
 generate_wix_guid(_wix_default_upgrade_guid "${_guid_seed_base}_UpgradeCode")
 

+ 84 - 17
cmake/Version.cmake

@@ -8,20 +8,87 @@
 
 string(TIMESTAMP current_year "%Y")
 set(O3DE_COPYRIGHT_YEAR ${current_year} CACHE STRING "Open 3D Engine's copyright year")
-set(O3DE_VERSION_STRING "0.0.0" CACHE STRING "Open 3D Engine's version")
-set(O3DE_DISPLAY_VERSION_STRING "00.00" CACHE STRING "Open 3D Engine's display version")
-set(O3DE_BUILD_VERSION 0 CACHE STRING "Open 3D Engine's build number")
-set(O3DE_ENGINE_NAME "o3de" CACHE STRING "Open 3D Engine's engine name")
-
-# Optional environment overrides
-if(NOT "$ENV{O3DE_VERSION}" STREQUAL "")
-    set(O3DE_VERSION_STRING "$ENV{O3DE_VERSION}")
-endif()
-
-if(NOT "$ENV{O3DE_DISPLAY_VERSION}" STREQUAL "")
-    set(O3DE_DISPLAY_VERSION_STRING "$ENV{O3DE_DISPLAY_VERSION}")
-endif()
-
-if(NOT "$ENV{O3DE_BUILD_VERSION}" STREQUAL "")
-    set(O3DE_BUILD_VERSION "$ENV{O3DE_BUILD_VERSION}")
-endif()
+
+# avoid reading engine.json multiple times 
+ly_file_read("${LY_ROOT_FOLDER}/engine.json" tmp_json_data)
+set_property(GLOBAL PROPERTY O3DE_ENGINE_JSON_DATA ${tmp_json_data})
+unset(tmp_json_data)
+
+#! o3de_read_engine_default: Read a field from engine.json or use the default if not found
+# \arg:output_value - name of output variable to set 
+# \arg:key - name of field in engine.json 
+# \arg:default_value - value to use if neither environment var or engine.json value found 
+macro(o3de_read_engine_default output_value key default_value)
+    get_property(engine_json_data GLOBAL PROPERTY O3DE_ENGINE_JSON_DATA)
+    string(JSON tmp_value ERROR_VARIABLE manifest_json_error GET ${engine_json_data} ${key})
+
+    # unset engine_json_data because we're in a macro
+    unset(engine_json_data)
+
+    if(manifest_json_error)
+        message(WARNING "Failed to read ${key} from \"${LY_ROOT_FOLDER}/engine.json\" : ${manifest_json_error}")
+        set(tmp_value ${default_value})
+    endif()
+
+    ly_set(${output_value} ${tmp_value})
+    set_property(GLOBAL PROPERTY ${output_value} ${tmp_value})
+
+    # unset tmp_value because we're in a macro
+    unset(tmp_value)
+endmacro()
+
+#! o3de_set_major_minor_patch_with_prefix: Parses a SemVer string and sets
+#  separate major, minor and patch global properties.  
+#  e.g. given "1.2.3" and prefix VER the following properties are set:
+#   VER_MAJOR 1
+#   VER_MINOR 2
+#   VER_PATCH 3
+#
+# \arg:prefix - prefix for cmake variable names 
+# \arg:version_string - input string in SemVer format e.g. "1.2.3"
+function(o3de_set_major_minor_patch_with_prefix prefix version_string)
+    string(REPLACE "." ";" version_list ${version_string})
+    list(GET version_list 0 major)
+    list(GET version_list 1 minor)
+    list(GET version_list 2 patch)
+    set_property(GLOBAL PROPERTY ${prefix}_MAJOR ${major})
+    set_property(GLOBAL PROPERTY ${prefix}_MINOR ${minor})
+    set_property(GLOBAL PROPERTY ${prefix}_PATCH ${patch})
+endfunction()
+
+#! o3de_get_major_minor_patch_with_prefix: Get the major, minor and patch 
+#  for global properties with the specified prefix and store the output
+#  in the provided variables.
+#
+#  Example storing O3DE_VERSION_MAJOR in major, O3DE_VERSION_MINOR in minor
+#  and O3DE_VERSION_PATCH in patch and print the SemVer:
+#
+#    o3de_get_major_minor_patch_with_prefix(O3DE_VERSION major minor patch) 
+#    message(INFO "O3DE version is ${major}.${minor}.${patch}")
+#
+# \arg:prefix - global properties prefix
+# \arg:output_major - output for <prefix>_MAJOR property
+# \arg:output_minor - output for <prefix>_MINOR property 
+# \arg:output_patch - output for <prefix>_PATCH property 
+macro(o3de_get_major_minor_patch_with_prefix prefix output_major output_minor output_patch)
+    get_property(${output_major} GLOBAL PROPERTY ${prefix}_MAJOR )
+    get_property(${output_minor} GLOBAL PROPERTY ${prefix}_MINOR )
+    get_property(${output_patch} GLOBAL PROPERTY ${prefix}_PATCH )
+endmacro()
+
+# set engine.json variables and global properties 
+# these are not cached variables and cannot be configured by the user
+o3de_read_engine_default(O3DE_VERSION_STRING "version" "0.0.0")
+o3de_read_engine_default(O3DE_DISPLAY_VERSION_STRING "display_version" "00.00")
+o3de_read_engine_default(O3DE_BUILD_VERSION "build" 0)
+o3de_read_engine_default(O3DE_ENGINE_NAME "engine_name" "o3de")
+
+# set O3DE_VERSION_MAJOR/MINOR/PATCH global properties
+o3de_set_major_minor_patch_with_prefix(O3DE_VERSION ${O3DE_VERSION_STRING})
+
+# set variables for INSTALL targets
+# these ARE cached variables and can be configured by the user
+o3de_set_from_env_with_default(O3DE_INSTALL_VERSION_STRING O3DE_INSTALL_VERSION "@O3DE_VERSION_STRING@" CACHE STRING "Open 3D Engine's version for the INSTALL target")
+o3de_set_from_env_with_default(O3DE_INSTALL_DISPLAY_VERSION_STRING O3DE_INSTALL_DISPLAY_VERSION "@O3DE_DISPLAY_VERSION_STRING@" CACHE STRING "Open 3D Engine's display version for the INSTALL target")
+o3de_set_from_env_with_default(O3DE_INSTALL_BUILD_VERSION O3DE_INSTALL_BUILD_VERSION "@O3DE_BUILD_VERSION@" CACHE STRING "Open 3D Engine's build number for the INSTALL target")
+o3de_set_from_env_with_default(O3DE_INSTALL_ENGINE_NAME O3DE_INSTALL_ENGINE_NAME "@O3DE_ENGINE_NAME@" CACHE STRING "Open 3D Engine's engine name for the INSTALL target")

+ 5 - 5
cmake/install/engine.json.in

@@ -1,12 +1,12 @@
 {
-    "engine_name": "@O3DE_ENGINE_NAME@",
-    "restricted_name": "@O3DE_ENGINE_NAME@",
-    "display_version": "@O3DE_DISPLAY_VERSION_STRING@",
-    "version": "@O3DE_VERSION_STRING@",
+    "engine_name": "@O3DE_INSTALL_ENGINE_NAME@",
+    "restricted_name": "@O3DE_INSTALL_ENGINE_NAME@",
+    "display_version": "@O3DE_INSTALL_DISPLAY_VERSION_STRING@",
+    "version": "@O3DE_INSTALL_VERSION_STRING@",
     "api_versions": @O3DE_INSTALL_API_VERSIONS@,
     "file_version": 2,
     "copyright_year": @O3DE_COPYRIGHT_YEAR@,
-    "build": @O3DE_BUILD_VERSION@,
+    "build": @O3DE_INSTALL_BUILD_VERSION@,
     "external_subdirectories": [@O3DE_INSTALL_EXTERNAL_SUBDIRS@],
     "projects": [@O3DE_INSTALL_PROJECTS@],
     "templates": [@O3DE_INSTALL_TEMPLATES@]

+ 9 - 2
scripts/build/Platform/Linux/pipeline.json

@@ -80,14 +80,21 @@
         ],
         "nightly-installer": [
             {
-                "parameter_name": "O3DE_VERSION",
+                "parameter_name": "O3DE_INSTALL_VERSION",
                 "parameter_type": "string",
                 "default_value": "",
                 "use_last_run_value": true,
                 "description": "The O3DE version in the installer filename and engine version"
             },
             {
-                "parameter_name": "O3DE_BUILD_VERSION",
+                "parameter_name": "O3DE_INSTALL_DISPLAY_VERSION",
+                "parameter_type": "string",
+                "default_value": "",
+                "use_last_run_value": true,
+                "description": "The O3DE display version in the installer filename and engine display version"
+            },
+            {
+                "parameter_name": "O3DE_INSTALL_BUILD_VERSION",
                 "parameter_type": "string",
                 "default_value": "",
                 "use_last_run_value": true,

+ 9 - 2
scripts/build/Platform/Windows/pipeline.json

@@ -80,14 +80,21 @@
         ],
         "nightly-installer": [
             {
-                "parameter_name": "O3DE_VERSION",
+                "parameter_name": "O3DE_INSTALL_VERSION",
                 "parameter_type": "string",
                 "default_value": "",
                 "use_last_run_value": true,
                 "description": "The O3DE version in the installer filename and engine version"
             },
             {
-                "parameter_name": "O3DE_BUILD_VERSION",
+                "parameter_name": "O3DE_INSTALL_DISPLAY_VERSION",
+                "parameter_type": "string",
+                "default_value": "",
+                "use_last_run_value": true,
+                "description": "The O3DE display version in the installer filename and engine display version"
+            },
+            {
+                "parameter_name": "O3DE_INSTALL_BUILD_VERSION",
                 "parameter_type": "string",
                 "default_value": "",
                 "use_last_run_value": true,