Selaa lähdekoodia

Atom SampleViewer project can now build in a project-centric manner (#89)

* Adding the EngineFinder.cmake file which is required to allow the
AtomSampleViewer project to be used in an engine-centric manner

Removed the AtomSampleViewer entry from the
shader_global_build_options.json as that doesn't inject the correct
project path when AtomSampleViewer is used as an external project.
The Shader Compiler Preprocessor injects the project path into the
include hierarchy so there it so it doesn't need to be added in the
shader_global_build_options.json

Updated the test_AtomSampleViewer_main_suite.py script to look for the
expected screenshot folder in the project directory instead of assuming
that there is an "AtomSampleViewer" directory in the Engine Root

* Adding commit to the Atom shader_global_build_options.json file to indicate that the project path is always injected into the front of the include paths

* Updating the AtomSampleViewer project to support the
project-centric workflow

Updating the AtomSampleViewer to support using new gem enabling system
via the naming convensions of Tools, Clients, Builders and Servers

* Adding a Builders alias for the AtomSampleViewer Gem as it is required to load the in the AssetProcessor/AssetBuilder to process project specific assets

* Adding AtomSampleViewer client target as a runtime dependency of the AtomSampleViewer.Tools alias as it requires both gems to be loaded in the Editor and AssetBuilder

* Remove add_vs_debugger_arguments call from AtomSampleViewer CMakeLists.txt
lumberyard-employee-dm 4 vuotta sitten
vanhempi
commit
5a6ff5d7b4

+ 0 - 13
CMakeLists.txt

@@ -9,18 +9,6 @@
 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 #
 
-#! Adds the --project-path argument to the VS IDE debugger command arguments
-function(add_vs_debugger_arguments)
-    # Inject the project root into the --project-path argument into the Visual Studio Debugger arguments by defaults
-    list(APPEND app_targets AtomSampleViewer.GameLauncher AtomSampleViewer.ServerLauncher)
-    list(APPEND app_targets AssetBuilder AssetProcessor AssetProcessorBatch Editor)
-    foreach(app_target IN LISTS app_targets)
-        if (TARGET ${app_target})
-            set_property(TARGET ${app_target} APPEND PROPERTY VS_DEBUGGER_COMMAND_ARGUMENTS "--project-path=\"${CMAKE_CURRENT_LIST_DIR}\"")
-        endif()
-    endforeach()
-endfunction()
-
 if(NOT PROJECT_NAME)
     cmake_minimum_required(VERSION 3.19)
     project(AtomSampleViewer
@@ -30,7 +18,6 @@ if(NOT PROJECT_NAME)
     include(EngineFinder.cmake OPTIONAL)
     find_package(o3de REQUIRED)
     o3de_initialize()
-    add_vs_debugger_arguments()
 else()
     # Add the project_name to global LY_PROJECTS_TARGET_NAME property
     file(READ "${CMAKE_CURRENT_LIST_DIR}/project.json" project_json)

+ 36 - 18
EngineFinder.cmake

@@ -20,31 +20,49 @@ if(json_error)
     message(FATAL_ERROR "Unable to read key 'engine' from 'project.json', error: ${json_error}")
 endif()
 
-# Read the list of paths from ~.o3de/o3de_manifest.json
-file(TO_CMAKE_PATH "$ENV{USERPROFILE}" home_directory) # Windows
-if((NOT home_directory) OR (NOT EXISTS ${home_directory}))
-    file(TO_CMAKE_PATH "$ENV{HOME}" home_directory)# Unix
+if(DEFINED ENV{USERPROFILE} AND EXISTS $ENV{USERPROFILE})
+    set(manifest_path $ENV{USERPROFILE}/.o3de/o3de_manifest.json) # Windows
+else()
+    set(manifest_path $ENV{HOME}/.o3de/o3de_manifest.json) # Unix
 endif()
 
-if (NOT home_directory)
-    message(FATAL_ERROR "Cannot find user home directory, the o3de manifest cannot be found")
-endif()
-# Set manifest path to path in the user home directory
-set(manifest_path ${home_directory}/.o3de/o3de_manifest.json)
-
+# Read the ~/.o3de/o3de_manifest.json file and look through the 'engines_path' object.
+# Find a key that matches LY_ENGINE_NAME_TO_USE and use that as the engine path.
 if(EXISTS ${manifest_path})
     file(READ ${manifest_path} manifest_json)
-    string(JSON engines_count ERROR_VARIABLE json_error LENGTH ${manifest_json} engines)
+
+    string(JSON engines_path_count ERROR_VARIABLE json_error LENGTH ${manifest_json} engines_path)
     if(json_error)
-        message(FATAL_ERROR "Unable to read key 'engines' from '${manifest_path}', error: ${json_error}")
+        message(FATAL_ERROR "Unable to read key 'engines_path' from '${manifest_path}', error: ${json_error}")
+    endif()
+
+    string(JSON engines_path_type ERROR_VARIABLE json_error TYPE ${manifest_json} engines_path)
+    if(json_error OR NOT ${engines_path_type} STREQUAL "OBJECT")
+        message(FATAL_ERROR "Type of 'engines_path' in '${manifest_path}' is not a JSON Object, error: ${json_error}")
     endif()
 
-    math(EXPR engines_count "${engines_count}-1")
-    foreach(engine_path_index RANGE ${engines_count})
-        string(JSON engine_path ERROR_VARIABLE json_error GET ${manifest_json} engines ${engine_path_index})
-        if(${json_error})
-            message(FATAL_ERROR "Unable to read engines[${engine_path_index}] '${manifest_path}', error: ${json_error}")
+    math(EXPR engines_path_count "${engines_path_count}-1")
+    foreach(engine_path_index RANGE ${engines_path_count})
+        string(JSON engine_name ERROR_VARIABLE json_error MEMBER ${manifest_json} engines_path ${engine_path_index})
+        if(json_error)
+            message(FATAL_ERROR "Unable to read 'engines_path/${engine_path_index}' from '${manifest_path}', error: ${json_error}")
+        endif()
+
+        if(LY_ENGINE_NAME_TO_USE STREQUAL engine_name)
+            string(JSON engine_path ERROR_VARIABLE json_error GET ${manifest_json} engines_path ${engine_name})
+            if(json_error)
+                message(FATAL_ERROR "Unable to read value from 'engines_path/${engine_name}', error: ${json_error}")
+            endif()
+
+            if(engine_path)
+                list(APPEND CMAKE_MODULE_PATH "${engine_path}/cmake")
+                break()
+            endif()
         endif()
-        list(APPEND CMAKE_MODULE_PATH "${engine_path}/cmake")
     endforeach()
+else()
+    # If the user is passing CMAKE_MODULE_PATH we assume thats where we will find the engine
+    if(NOT CMAKE_MODULE_PATH)
+        message(FATAL_ERROR "Engine registration is required before configuring a project.  Please register an engine by running 'scripts/o3de register --this-engine'")
+    endif()
 endif()

+ 42 - 34
Gem/Code/CMakeLists.txt

@@ -65,6 +65,10 @@ ly_add_target(
             Gem::ImGui.imguilib
 )
 
+# if enabled, AtomSampleViewer is used by the Client and ServerLauncher
+ly_create_alias(NAME AtomSampleViewer.Clients  NAMESPACE Gem TARGETS Gem::AtomSampleViewer)
+ly_create_alias(NAME AtomSampleViewer.Servers  NAMESPACE Gem TARGETS Gem::AtomSampleViewer)
+
 if(PAL_TRAIT_BUILD_HOST_TOOLS)
 
     ly_add_target(
@@ -102,42 +106,13 @@ if(PAL_TRAIT_BUILD_HOST_TOOLS)
             PUBLIC
                 AZ::AzCore
                 Gem::AtomSampleViewer.Tools.Static
+        RUNTIME_DEPENDENCIES
+            Gem::AtomSampleViewer
     )
 
-endif()
-
-################################################################################
-# Gem dependencies
-################################################################################
-ly_add_project_dependencies(
-    PROJECT_NAME
-        AtomSampleViewer
-    TARGETS 
-        AtomSampleViewer.GameLauncher
-    DEPENDENCIES_FILES runtime_dependencies.cmake
-)
-
-if(PAL_TRAIT_BUILD_HOST_TOOLS)
-    ly_add_project_dependencies(
-        PROJECT_NAME
-            AtomSampleViewer
-        TARGETS
-            AssetBuilder
-            AssetProcessor
-            AssetProcessorBatch
-            Editor
-        DEPENDENCIES_FILES tool_dependencies.cmake
-    )
-endif()
-
-if(PAL_TRAIT_BUILD_SUPPORTS_SERVER)
-    ly_add_project_dependencies(
-        PROJECT_NAME
-            AtomSampleViewer
-        TARGETS
-            AtomSampleViewerServer
-        DEPENDENCIES_FILES runtime_dependencies.cmake
-    )
+    # The AtomSampleViewer.Tools target is the real GEM_MODULE target made above, but the AssetBuilder/AssetProcessor
+    # also needs that target, so alias the "Builders" variant to it
+    ly_create_alias(NAME AtomSampleViewer.Builders NAMESPACE Gem TARGETS Gem::AtomSampleViewer.Tools)
 endif()
 
 ################################################################################
@@ -163,3 +138,36 @@ if(PAL_TRAIT_BUILD_SUPPORTS_TESTS)
         TARGET Gem::AtomSampleViewer.Tests
     )
 endif()
+
+
+################################################################################
+# Gem dependencies
+################################################################################
+# The GameLauncher uses "Clients" gem variants:
+ly_enable_gems(PROJECT_NAME AtomSampleViewer GEM_FILE enabled_gems.cmake
+    TARGETS AtomSampleViewer.GameLauncher
+    VARIANTS Clients)
+
+# If we build a server, then apply the gems to the server
+if(PAL_TRAIT_BUILD_SERVER_SUPPORTED)
+    # if we're making a server, then add the "Server" gem variants to it:
+    ly_enable_gems(PROJECT_NAME AtomSampleViewer GEM_FILE enabled_gems.cmake
+        TARGETS AtomSampleViewer.ServerLauncher
+        VARIANTS Servers)
+
+    set_property(GLOBAL APPEND PROPERTY LY_LAUNCHER_SERVER_PROJECTS AtomSampleViewer)
+endif()
+
+if (PAL_TRAIT_BUILD_HOST_TOOLS)
+    # The Editor uses "Tools" gem variants:
+    ly_enable_gems(
+        PROJECT_NAME AtomSampleViewer GEM_FILE enabled_gems.cmake
+        TARGETS Editor
+        VARIANTS Tools)
+
+    # The pipeline tools use "Builders" gem variants:
+    ly_enable_gems(
+        PROJECT_NAME AtomSampleViewer GEM_FILE enabled_gems.cmake
+        TARGETS AssetBuilder AssetProcessor AssetProcessorBatch
+        VARIANTS Builders)
+endif()

+ 13 - 11
Gem/Code/runtime_dependencies.cmake → Gem/Code/enabled_gems.cmake

@@ -9,14 +9,16 @@
 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 #
 
-# Extracted from Game.xml
-set(GEM_DEPENDENCIES
-    Gem::Maestro
-    Gem::TextureAtlas
-    Gem::LmbrCentral
-    Gem::LyShine
-    Gem::Camera
-    Gem::EMotionFX
-    Gem::Atom_AtomBridge
-    Gem::AtomSampleViewer
-)
+set(ENABLED_GEMS
+    Maestro
+    TextureAtlas
+    LmbrCentral
+    LyShine
+    Camera
+    EMotionFX
+    Atom_AtomBridge
+    AtomSampleViewer
+    SceneProcessing
+    EditorPythonBindings
+    ImGui
+)

+ 0 - 26
Gem/Code/tool_dependencies.cmake

@@ -1,26 +0,0 @@
-#
-# All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
-# its licensors.
-#
-# For complete copyright and license terms please see the LICENSE at the root of this
-# distribution (the "License"). All use of this software is governed by the License,
-# or, if provided, by the license below or the license accompanying this file. Do not
-# remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-#
-
-# Extracted from Editor.xml
-set(GEM_DEPENDENCIES
-    Gem::Maestro.Editor
-    Gem::TextureAtlas.Editor
-    Gem::LmbrCentral.Editor
-    Gem::LyShine.Editor
-    Gem::SceneProcessing.Editor
-    Gem::EditorPythonBindings.Editor
-    Gem::Camera.Editor
-    Gem::EMotionFX.Editor
-    Gem::ImGui.Editor
-    Gem::Atom_AtomBridge.Editor
-    Gem::AtomSampleViewer
-    Gem::AtomSampleViewer.Tools
-)

+ 4 - 6
Standalone/CMakeLists.txt

@@ -41,12 +41,10 @@ if (NOT LY_MONOLITHIC_GAME)
 
         add_subdirectory(PythonTests)
 
-        ly_add_target_dependencies(
-            TARGETS 
-                AtomSampleViewerStandalone
-            DEPENDENCIES_FILES 
-                ../Gem/Code/runtime_dependencies.cmake
-        )
+        ly_enable_gems(GEM_FILE ../Gem/Code/enabled_gems.cmake
+            TARGETS AtomSampleViewerStandalone
+            VARIANTS Clients)
+
 
         # Adds the AtomSampleViewerStandalone target as a C preprocessor define so that it can be used as a Settings Registry
         # specialization in order to look up the generated .setreg which contains the dependencies