Parcourir la source

Updated the install layout to generate an empty CMakeLists.txt for gems (#11213)

* Updated the install layout to generate an empty CMakeLists.txt for gems

The directory with the gem.json file will now contain an empty
CMakeLists.txt file.
This allows the top-level CMakeLists.txt of the SDK root to invoke
`add_engine_json_external_subdirectories` which visits each gem root and
add their path to a `@GEMROOT:<gem-name>@` cmake GLOBAL property.

Signed-off-by: lumberyard-employee-dm <[email protected]>

* Fixed overwriting of an install CMakeLists.txt with install permutation
content.

The generate empty CMakeLists.txt would override the CMakeLists.txt
generated in the `ly_setup_subdirectory` function causing the include
command within it to be removed.

Added a global property of
`O3DE_SUBDIRECTORY_${real_external_subdirectory_path}` for each External
Subdirectory to provide a quick way to lookup if a directory is an
external subdirectory.
This is used to prevent the `ly_setup_install` function from invoking
add_subdirectory on an external subdirectory that would be added via
visiting the "external_subdirectories" paths in the SDK layout
engine.json.

Signed-off-by: lumberyard-employee-dm <[email protected]>

Signed-off-by: lumberyard-employee-dm <[email protected]>
lumberyard-employee-dm il y a 3 ans
Parent
commit
64c36a2d66
3 fichiers modifiés avec 56 ajouts et 9 suppressions
  1. 4 4
      CMakeLists.txt
  2. 36 2
      cmake/Platform/Common/Install_common.cmake
  3. 16 3
      cmake/Subdirectories.cmake

+ 4 - 4
CMakeLists.txt

@@ -53,12 +53,12 @@ add_o3de_manifest_json_external_subdirectories()
 # Add the projects first so the Launcher can find them
 # Add the projects first so the Launcher can find them
 include(cmake/Projects.cmake)
 include(cmake/Projects.cmake)
 
 
+# Add external subdirectories listed in the engine.json.
+# LY_EXTERNAL_SUBDIRS is a cache variable so the user can add extra
+# external subdirectories.
+add_engine_json_external_subdirectories()
 
 
 if(NOT INSTALLED_ENGINE)
 if(NOT INSTALLED_ENGINE)
-    # Add external subdirectories listed in the engine.json.
-    # LY_EXTERNAL_SUBDIRS is a cache variable so the user can add extra
-    # external subdirectories.
-    add_engine_json_external_subdirectories()
 
 
     # Add the rest of the targets
     # Add the rest of the targets
     add_subdirectory(Assets)
     add_subdirectory(Assets)

+ 36 - 2
cmake/Platform/Common/Install_common.cmake

@@ -368,10 +368,16 @@ function(ly_setup_subdirectory absolute_target_source_dir)
     ly_file_read(${LY_ROOT_FOLDER}/cmake/install/Copyright.in cmake_copyright_comment)
     ly_file_read(${LY_ROOT_FOLDER}/cmake/install/Copyright.in cmake_copyright_comment)
 
 
     # 1. Create the base CMakeLists.txt that will just include a cmake file per platform
     # 1. Create the base CMakeLists.txt that will just include a cmake file per platform
-    file(CONFIGURE OUTPUT "${target_install_source_dir}/CMakeLists.txt" CONTENT [[
+    string(CONFIGURE [[
 @cmake_copyright_comment@
 @cmake_copyright_comment@
 include(Platform/${PAL_PLATFORM_NAME}/platform_${PAL_PLATFORM_NAME_LOWERCASE}.cmake)
 include(Platform/${PAL_PLATFORM_NAME}/platform_${PAL_PLATFORM_NAME_LOWERCASE}.cmake)
-]] @ONLY)
+]] subdirectory_cmakelist_content @ONLY)
+
+    # Store off the generated CMakeLists.txt into a DIRECTORY property based on the subdirectory being visited
+    # In the ly_setup_assets() function, it generates an empty CMakeLists.txt into the gem root directory
+    # if one does not exist by checking if this property is set
+    set_property(DIRECTORY "${absolute_target_source_dir}" APPEND_STRING PROPERTY O3DE_SUBDIRECTORY_CMAKELIST_CONTENT "${subdirectory_cmakelist_content}")
+    file(WRITE "${target_install_source_dir}/CMakeLists.txt" "${subdirectory_cmakelist_content}")
 
 
     ly_install(FILES "${target_install_source_dir}/CMakeLists.txt"
     ly_install(FILES "${target_install_source_dir}/CMakeLists.txt"
         DESTINATION ${relative_target_source_dir}
         DESTINATION ${relative_target_source_dir}
@@ -530,6 +536,13 @@ function(ly_setup_cmake_install)
     # Add to find_subdirectories all directories in which ly_add_target were called in
     # Add to find_subdirectories all directories in which ly_add_target were called in
     get_property(all_subdirectories GLOBAL PROPERTY LY_ALL_TARGET_DIRECTORIES)
     get_property(all_subdirectories GLOBAL PROPERTY LY_ALL_TARGET_DIRECTORIES)
     foreach(target_subdirectory IN LISTS all_subdirectories)
     foreach(target_subdirectory IN LISTS all_subdirectories)
+        # If the subdirectory is an external_subdirectory, then it is being added in the engine.json file
+        # Therefore it is not added to the o3de_subdirectories_<Platform>.cmake file to avoid
+        # invoking add_subdirectory twice
+        get_property(is_external_subdir GLOBAL PROPERTY "O3DE_SUBDIRECTORY_${target_subdirectory}" SET)
+        if(is_external_subdir)
+            continue()
+        endif()
         ly_get_root_subdirectory_which_is_parent(${target_subdirectory} root_subdir_of_target)
         ly_get_root_subdirectory_which_is_parent(${target_subdirectory} root_subdir_of_target)
         cmake_path(RELATIVE_PATH target_subdirectory BASE_DIRECTORY ${root_subdir_of_target} OUTPUT_VARIABLE relative_target_subdirectory)
         cmake_path(RELATIVE_PATH target_subdirectory BASE_DIRECTORY ${root_subdir_of_target} OUTPUT_VARIABLE relative_target_subdirectory)
 
 
@@ -761,6 +774,27 @@ function(ly_setup_assets)
                     COMPONENT ${CMAKE_INSTALL_DEFAULT_COMPONENT_NAME}
                     COMPONENT ${CMAKE_INSTALL_DEFAULT_COMPONENT_NAME}
                 )
                 )
             elseif (EXISTS ${gem_absolute_path})
             elseif (EXISTS ${gem_absolute_path})
+                # Special case for the gem.json file, generate an empty CMakeLists.txt with the gem.json file
+                # if there is not already a CMakeLists.txy being installed to gem root directory
+                cmake_path(GET gem_absolute_path FILENAME filename)
+                cmake_path(COMPARE "${filename}" EQUAL "gem.json" is_gem_root)
+                get_property(has_gem_root_cmakelist_content DIRECTORY "${gem_candidate_dir}" PROPERTY O3DE_SUBDIRECTORY_CMAKELIST_CONTENT SET)
+                if (is_gem_root AND NOT has_gem_root_cmakelist_content)
+                    ly_file_read(${LY_ROOT_FOLDER}/cmake/install/Copyright.in cmake_copyright_comment)
+                    # Generate an empty CMakeLists.txt  inside the cmake binary directory
+                    # to allow it to be installed next to the gem.json
+                    set(gem_scratch_binary_dir "${CMAKE_CURRENT_BINARY_DIR}/install/${gem_install_dest_dir}")
+
+                    # copy the empty CMakeList.txt into the gem root directory, to allow add_subdirectory
+                    # calls to succeed on the gem root in the install layout
+                    file(CONFIGURE OUTPUT "${gem_scratch_binary_dir}/CMakeLists.txt" CONTENT [[@cmake_copyright_comment@]] @ONLY)
+
+                    ly_install(FILES "${gem_scratch_binary_dir}/CMakeLists.txt"
+                        DESTINATION ${gem_install_dest_dir}
+                        COMPONENT ${CMAKE_INSTALL_DEFAULT_COMPONENT_NAME}
+                    )
+                endif()
+
                 ly_install(FILES ${gem_absolute_path}
                 ly_install(FILES ${gem_absolute_path}
                     DESTINATION ${gem_install_dest_dir}
                     DESTINATION ${gem_install_dest_dir}
                     COMPONENT ${CMAKE_INSTALL_DEFAULT_COMPONENT_NAME}
                     COMPONENT ${CMAKE_INSTALL_DEFAULT_COMPONENT_NAME}

+ 16 - 3
cmake/Subdirectories.cmake

@@ -12,6 +12,13 @@ include_guard()
 # Subdirectory processing
 # Subdirectory processing
 ################################################################################
 ################################################################################
 
 
+# Add a GLOBAL property which can be used to quickly determine if a directory is an external subdirectory
+get_property(cache_external_subdirs CACHE LY_EXTERNAL_SUBDIRS PROPERTY VALUE)
+foreach(cache_external_subdir IN LISTS cache_external_subdirs)
+    file(REAL_PATH ${cache_external_subdir} real_external_subdir)
+    set_property(GLOBAL PROPERTY "O3DE_SUBDIRECTORY_${real_external_subdir}" TRUE)
+endforeach()
+
 # The following functions is for gathering the list of external subdirectories
 # The following functions is for gathering the list of external subdirectories
 # provided by the engine.json
 # provided by the engine.json
 function(add_engine_gem_json_external_subdirectories gem_path)
 function(add_engine_gem_json_external_subdirectories gem_path)
@@ -31,6 +38,7 @@ function(add_engine_gem_json_external_subdirectories gem_path)
             get_property(current_external_subdirs GLOBAL PROPERTY LY_EXTERNAL_SUBDIRS_ENGINE)
             get_property(current_external_subdirs GLOBAL PROPERTY LY_EXTERNAL_SUBDIRS_ENGINE)
             if(NOT real_external_subdir IN_LIST current_external_subdirs)
             if(NOT real_external_subdir IN_LIST current_external_subdirs)
                 set_property(GLOBAL APPEND PROPERTY LY_EXTERNAL_SUBDIRS_ENGINE ${real_external_subdir})
                 set_property(GLOBAL APPEND PROPERTY LY_EXTERNAL_SUBDIRS_ENGINE ${real_external_subdir})
+                set_property(GLOBAL PROPERTY "O3DE_SUBDIRECTORY_${real_external_subdir}" TRUE)
                 add_engine_gem_json_external_subdirectories(${real_external_subdir})
                 add_engine_gem_json_external_subdirectories(${real_external_subdir})
             endif()
             endif()
         endforeach()
         endforeach()
@@ -41,13 +49,14 @@ function(add_engine_json_external_subdirectories)
     set(engine_json_path ${LY_ROOT_FOLDER}/engine.json)
     set(engine_json_path ${LY_ROOT_FOLDER}/engine.json)
     if(EXISTS ${engine_json_path})
     if(EXISTS ${engine_json_path})
         o3de_read_json_external_subdirs(engine_external_subdirs ${engine_json_path})
         o3de_read_json_external_subdirs(engine_external_subdirs ${engine_json_path})
-        foreach(engine_external_subdir IN LISTS engine_external_subdirs )
+        foreach(engine_external_subdir IN LISTS engine_external_subdirs)
             file(REAL_PATH ${engine_external_subdir} real_external_subdir BASE_DIRECTORY ${LY_ROOT_FOLDER})
             file(REAL_PATH ${engine_external_subdir} real_external_subdir BASE_DIRECTORY ${LY_ROOT_FOLDER})
 
 
             # Append external subdirectory ONLY to LY_EXTERNAL_SUBDIRS_ENGINE PROPERTY
             # Append external subdirectory ONLY to LY_EXTERNAL_SUBDIRS_ENGINE PROPERTY
             get_property(current_external_subdirs GLOBAL PROPERTY LY_EXTERNAL_SUBDIRS_ENGINE)
             get_property(current_external_subdirs GLOBAL PROPERTY LY_EXTERNAL_SUBDIRS_ENGINE)
             if(NOT real_external_subdir IN_LIST current_external_subdirs)
             if(NOT real_external_subdir IN_LIST current_external_subdirs)
                 set_property(GLOBAL APPEND PROPERTY LY_EXTERNAL_SUBDIRS_ENGINE ${real_external_subdir})
                 set_property(GLOBAL APPEND PROPERTY LY_EXTERNAL_SUBDIRS_ENGINE ${real_external_subdir})
+                set_property(GLOBAL PROPERTY "O3DE_SUBDIRECTORY_${real_external_subdir}" TRUE)
                 add_engine_gem_json_external_subdirectories(${real_external_subdir})
                 add_engine_gem_json_external_subdirectories(${real_external_subdir})
             endif()
             endif()
         endforeach()
         endforeach()
@@ -74,6 +83,7 @@ function(add_project_gem_json_external_subdirectories gem_path project_name)
             get_property(current_external_subdirs GLOBAL PROPERTY LY_EXTERNAL_SUBDIRS_${project_name})
             get_property(current_external_subdirs GLOBAL PROPERTY LY_EXTERNAL_SUBDIRS_${project_name})
             if(NOT real_external_subdir IN_LIST current_external_subdirs)
             if(NOT real_external_subdir IN_LIST current_external_subdirs)
                 set_property(GLOBAL APPEND PROPERTY LY_EXTERNAL_SUBDIRS_${project_name} ${real_external_subdir})
                 set_property(GLOBAL APPEND PROPERTY LY_EXTERNAL_SUBDIRS_${project_name} ${real_external_subdir})
+                set_property(GLOBAL PROPERTY "O3DE_SUBDIRECTORY_${real_external_subdir}" TRUE)
                 add_project_gem_json_external_subdirectories(${real_external_subdir} "${project_name}")
                 add_project_gem_json_external_subdirectories(${real_external_subdir} "${project_name}")
             endif()
             endif()
         endforeach()
         endforeach()
@@ -91,6 +101,7 @@ function(add_project_json_external_subdirectories project_path project_name)
             get_property(current_external_subdirs GLOBAL PROPERTY LY_EXTERNAL_SUBDIRS_${project_name})
             get_property(current_external_subdirs GLOBAL PROPERTY LY_EXTERNAL_SUBDIRS_${project_name})
             if(NOT real_external_subdir IN_LIST current_external_subdirs)
             if(NOT real_external_subdir IN_LIST current_external_subdirs)
                 set_property(GLOBAL APPEND PROPERTY LY_EXTERNAL_SUBDIRS_${project_name} ${real_external_subdir})
                 set_property(GLOBAL APPEND PROPERTY LY_EXTERNAL_SUBDIRS_${project_name} ${real_external_subdir})
+                set_property(GLOBAL PROPERTY "O3DE_SUBDIRECTORY_${real_external_subdir}" TRUE)
                 add_project_gem_json_external_subdirectories(${real_external_subdir} "${project_name}")
                 add_project_gem_json_external_subdirectories(${real_external_subdir} "${project_name}")
             endif()
             endif()
         endforeach()
         endforeach()
@@ -117,6 +128,7 @@ function(add_o3de_manifest_gem_json_external_subdirectories gem_path)
             get_property(current_external_subdirs GLOBAL PROPERTY LY_EXTERNAL_SUBDIRS_O3DE_MANIFEST)
             get_property(current_external_subdirs GLOBAL PROPERTY LY_EXTERNAL_SUBDIRS_O3DE_MANIFEST)
             if(NOT real_external_subdir IN_LIST current_external_subdirs)
             if(NOT real_external_subdir IN_LIST current_external_subdirs)
                 set_property(GLOBAL APPEND PROPERTY LY_EXTERNAL_SUBDIRS_O3DE_MANIFEST ${real_external_subdir})
                 set_property(GLOBAL APPEND PROPERTY LY_EXTERNAL_SUBDIRS_O3DE_MANIFEST ${real_external_subdir})
+                set_property(GLOBAL PROPERTY "O3DE_SUBDIRECTORY_${real_external_subdir}" TRUE)
                 add_o3de_manifest_gem_json_external_subdirectories(${real_external_subdir})
                 add_o3de_manifest_gem_json_external_subdirectories(${real_external_subdir})
             endif()
             endif()
         endforeach()
         endforeach()
@@ -136,6 +148,7 @@ function(add_o3de_manifest_json_external_subdirectories)
             get_property(current_external_subdirs GLOBAL PROPERTY LY_EXTERNAL_SUBDIRS_O3DE_MANIFEST)
             get_property(current_external_subdirs GLOBAL PROPERTY LY_EXTERNAL_SUBDIRS_O3DE_MANIFEST)
             if(NOT real_external_subdir IN_LIST current_external_subdirs)
             if(NOT real_external_subdir IN_LIST current_external_subdirs)
                 set_property(GLOBAL APPEND PROPERTY LY_EXTERNAL_SUBDIRS_O3DE_MANIFEST ${real_external_subdir})
                 set_property(GLOBAL APPEND PROPERTY LY_EXTERNAL_SUBDIRS_O3DE_MANIFEST ${real_external_subdir})
+                set_property(GLOBAL PROPERTY "O3DE_SUBDIRECTORY_${real_external_subdir}" TRUE)
                 add_o3de_manifest_gem_json_external_subdirectories(${real_external_subdir})
                 add_o3de_manifest_gem_json_external_subdirectories(${real_external_subdir})
             endif()
             endif()
         endforeach()
         endforeach()
@@ -291,8 +304,8 @@ endfunction()
 #! or references("gem_names")
 #! or references("gem_names")
 function(get_external_subdirectories_in_use output_subdirs)
 function(get_external_subdirectories_in_use output_subdirs)
     # Gather the list of external subdirectories set through the LY_EXTERNAL_SUBDIRS Cache Variable
     # Gather the list of external subdirectories set through the LY_EXTERNAL_SUBDIRS Cache Variable
-    get_property(all_external_subdirs GLOBAL PROPERTY LY_EXTERNAL_SUBDIRS)
-    # Append the list of Extenal Subdirectories from the engine.json
+    get_property(all_external_subdirs CACHE LY_EXTERNAL_SUBDIRS PROPERTY VALUE)
+    # Append the list of external subdirectories from the engine.json
     get_property(engine_external_subdirs GLOBAL PROPERTY LY_EXTERNAL_SUBDIRS_ENGINE)
     get_property(engine_external_subdirs GLOBAL PROPERTY LY_EXTERNAL_SUBDIRS_ENGINE)
     list(APPEND all_external_subdirs ${engine_external_subdirs})
     list(APPEND all_external_subdirs ${engine_external_subdirs})
     # Append the gems referenced by name from "gem_names" field in the engine.json
     # Append the gems referenced by name from "gem_names" field in the engine.json