Changing find files to add_subdirectory to be able to have SettingsRegistry.cmake finding the path to the gems

This commit is contained in:
pappeste
2021-05-04 13:52:19 -07:00
parent 03ae0195a3
commit b0732dd494
5 changed files with 35 additions and 37 deletions
+5 -7
View File
@@ -52,7 +52,6 @@ define_property(TARGET PROPERTY GEM_MODULE
# \arg:HEADERONLY (bool) defines this target to be a header only library. A ${NAME}_HEADERS project will be created for the IDE
# \arg:EXECUTABLE (bool) defines this target to be an executable
# \arg:APPLICATION (bool) defines this target to be an application (executable that is not a console)
# \arg:UNKNOWN (bool) defines this target to be unknown. This is used when importing installed targets from Find files
# \arg:IMPORTED (bool) defines this target to be imported.
# \arg:NAMESPACE namespace declaration for this target. It will be used for IDE and dependencies
# \arg:OUTPUT_NAME (optional) overrides the name of the output target. If not specified, the name will be used.
@@ -76,7 +75,7 @@ define_property(TARGET PROPERTY GEM_MODULE
# \arg:AUTOGEN_RULES a set of AutoGeneration rules to be passed to the AzAutoGen expansion system
function(ly_add_target)
set(options STATIC SHARED MODULE GEM_MODULE HEADERONLY EXECUTABLE APPLICATION UNKNOWN IMPORTED AUTOMOC AUTOUIC AUTORCC NO_UNITY)
set(options STATIC SHARED MODULE GEM_MODULE HEADERONLY EXECUTABLE APPLICATION IMPORTED AUTOMOC AUTOUIC AUTORCC NO_UNITY)
set(oneValueArgs NAME NAMESPACE OUTPUT_SUBDIRECTORY OUTPUT_NAME)
set(multiValueArgs FILES_CMAKE GENERATED_FILES INCLUDE_DIRECTORIES COMPILE_DEFINITIONS BUILD_DEPENDENCIES RUNTIME_DEPENDENCIES PLATFORM_INCLUDE_FILES TARGET_PROPERTIES AUTOGEN_RULES)
@@ -128,12 +127,12 @@ function(ly_add_target)
set(linking_options APPLICATION)
set(linking_count "${linking_count}1")
endif()
if(ly_add_target_UNKNOWN)
set(linking_options UNKNOWN)
if(ly_add_target_IMPORTED)
set(linking_options UNKNOWN IMPORTED GLOBAL)
set(linking_count "${linking_count}1")
endif()
if(NOT ("${linking_count}" STREQUAL "1"))
message(FATAL_ERROR "More than one of the following options [STATIC | SHARED | MODULE | HEADERONLY | EXECUTABLE | APPLICATION | UNKNOWN] was specified and they are mutually exclusive")
message(FATAL_ERROR "More than one of the following options [STATIC | SHARED | MODULE | HEADERONLY | EXECUTABLE | APPLICATION | IMPORTED] was specified and they are mutually exclusive")
endif()
if(ly_add_target_NAMESPACE)
@@ -159,10 +158,9 @@ function(ly_add_target)
${linking_options}
${ALLFILES} ${ly_add_target_GENERATED_FILES}
)
elseif(ly_add_target_UNKNOWN)
elseif(ly_add_target_IMPORTED)
add_library(${ly_add_target_NAME}
${linking_options}
IMPORTED
)
else()
add_library(${ly_add_target_NAME}
+23 -22
View File
@@ -11,7 +11,7 @@
set(CMAKE_INSTALL_MESSAGE NEVER) # Simplify messages to reduce output noise
ly_set(LY_DEFAULT_INSTALL_COMPONENT "Core")
ly_set(LY_DEFAULT_INSTALL_COMPONENT Core)
file(RELATIVE_PATH runtime_output_directory ${CMAKE_BINARY_DIR} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
file(RELATIVE_PATH library_output_directory ${CMAKE_BINARY_DIR} ${CMAKE_LIBRARY_OUTPUT_DIRECTORY})
@@ -74,20 +74,9 @@ function(ly_install_target ly_install_target_NAME)
COMPONENT ${ly_install_target_COMPONENT}
)
ly_generate_target_find_file(
NAME ${ly_install_target_NAME}
${ARGN}
)
ly_generate_target_find_file(NAME ${ly_install_target_NAME} ${ARGN})
ly_generate_target_config_file(${ly_install_target_NAME})
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${ly_install_target_NAME}_$<CONFIG>.cmake"
DESTINATION cmake_autogen/${ly_install_target_NAME}
COMPONENT ${ly_install_target_COMPONENT}
)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/Find${ly_install_target_NAME}.cmake"
DESTINATION cmake
COMPONENT ${ly_install_target_COMPONENT}
)
endfunction()
@@ -129,16 +118,21 @@ function(ly_generate_target_find_file)
# Includes need additional processing to add the install root
foreach(include ${include_directories_interface_props})
set(installed_include_prefix "\${LY_ROOT_FOLDER}/include/")
file(RELATIVE_PATH relative_path ${CMAKE_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/${include})
list(APPEND INCLUDE_DIRECTORIES_PLACEHOLDER "include/${relative_path}")
string(APPEND INCLUDE_DIRECTORIES_PLACEHOLDER "\${LY_ROOT_FOLDER}/include/${relative_path}\n")
endforeach()
string(REPLACE ";" "\n" INCLUDE_DIRECTORIES_PLACEHOLDER "${INCLUDE_DIRECTORIES_PLACEHOLDER}")
string(REPLACE ";" "\n" BUILD_DEPENDENCIES_PLACEHOLDER "${BUILD_DEPENDENCIES_PLACEHOLDER}")
string(REPLACE ";" "\n" RUNTIME_DEPENDENCIES_PLACEHOLDER "${RUNTIME_DEPENDENCIES_PLACEHOLDER}")
configure_file(${LY_ROOT_FOLDER}/cmake/FindTarget.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/Find${ly_generate_target_find_file_NAME}.cmake @ONLY)
# Since a CMakeLists could contain multiple targets, we generate it in a folder per target
configure_file(${LY_ROOT_FOLDER}/cmake/install/TargetCMakeLists.txt.in ${CMAKE_CURRENT_BINARY_DIR}/install/${ly_generate_target_find_file_NAME}/CMakeLists.txt @ONLY)
get_target_property(target_source_dir ${ly_generate_target_find_file_NAME} SOURCE_DIR)
file(RELATIVE_PATH target_source_dir_relative ${CMAKE_SOURCE_DIR} ${target_source_dir})
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/install/${ly_generate_target_find_file_NAME}/CMakeLists.txt"
DESTINATION ${target_source_dir_relative}/${ly_generate_target_find_file_NAME}
COMPONENT ${ly_install_target_COMPONENT}
)
endfunction()
@@ -183,7 +177,13 @@ endif()
")
endif()
file(GENERATE OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${NAME}_$<CONFIG>.cmake" CONTENT "${target_file_contents}")
file(GENERATE OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/install/${NAME}/${NAME}_$<CONFIG>.cmake" CONTENT "${target_file_contents}")
get_target_property(target_source_dir ${NAME} SOURCE_DIR)
file(RELATIVE_PATH target_source_dir_relative ${CMAKE_SOURCE_DIR} ${target_source_dir})
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/install/${NAME}_$<CONFIG>.cmake"
DESTINATION ${target_source_dir_relative}/${NAME}
COMPONENT ${ly_install_target_COMPONENT}
)
endfunction()
@@ -254,11 +254,12 @@ function(ly_setup_cmake_install)
get_property(all_targets GLOBAL PROPERTY LY_ALL_TARGETS)
unset(FIND_PACKAGES_PLACEHOLDER)
foreach(target IN LISTS all_targets)
string(APPEND FIND_PACKAGES_PLACEHOLDER " find_package(${target})\n")
get_target_property(target_source_dir ${target} SOURCE_DIR)
file(RELATIVE_PATH target_source_dir_relative ${CMAKE_SOURCE_DIR} ${target_source_dir})
string(APPEND FIND_PACKAGES_PLACEHOLDER " add_subdirectory(${target_source_dir_relative}/${target})\n")
endforeach()
configure_file(${LY_ROOT_FOLDER}/cmake/Findo3de.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/cmake/Findo3de.cmake @ONLY)
configure_file(${LY_ROOT_FOLDER}/cmake/install/Findo3de.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/cmake/Findo3de.cmake @ONLY)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/cmake/Findo3de.cmake"
DESTINATION cmake
COMPONENT ${LY_DEFAULT_INSTALL_COMPONENT}
+5 -4
View File
@@ -126,15 +126,16 @@ function(ly_delayed_generate_settings_registry)
get_property(gem_relative_source_dir TARGET ${gem_target} PROPERTY SOURCE_DIR)
if(gem_relative_source_dir)
# Most gems CMakeLists.txt files reside in the <GemSourceDir>/Code/ so remove "Code/" from the path
if(gem_relative_source_dir MATCHES ".*/Code$")
while(gem_relative_source_dir MATCHES ".*/Code$")
get_filename_component(gem_relative_source_dir ${gem_relative_source_dir} DIRECTORY)
endif()
endwhile()
file(TO_CMAKE_PATH ${LY_ROOT_FOLDER} ly_root_folder_cmake)
file(RELATIVE_PATH gem_relative_source_dir ${ly_root_folder_cmake} ${gem_relative_source_dir})
endif()
# Strip target namespace from gem targets before configuring them into the json template
ly_strip_target_namespace(TARGET ${gem_target} OUTPUT_VARIABLE stripped_gem_target)
message("gem_target: ${gem_target}, gem_relative_source_dir: ${gem_relative_source_dir}")
# Strip target namespace from gem targets before configuring them into the json template
ly_strip_target_namespace(TARGET ${gem_target} OUTPUT_VARIABLE stripped_gem_target)
string(CONFIGURE ${gem_module_template} gem_module_json @ONLY)
list(APPEND target_gem_dependencies_names ${gem_module_json})
endforeach()
@@ -11,10 +11,8 @@
# Generated by O3DE
include(FindPackageHandleStandardArgs)
ly_add_target(
NAME @NAME_PLACEHOLDER@ UNKNOWN IMPORTED
NAME @NAME_PLACEHOLDER@ IMPORTED
@NAMESPACE_PLACEHOLDER@
COMPILE_DEFINITIONS
INTERFACE
@@ -30,5 +28,5 @@ ly_add_target(
)
foreach(config @CMAKE_CONFIGURATION_TYPES@)
include("${LY_ROOT_FOLDER}/cmake_autogen/@NAME_PLACEHOLDER@/@NAME_PLACEHOLDER@_${config}.cmake" OPTIONAL)
include("@NAME_PLACEHOLDER@_${config}.cmake" OPTIONAL)
endforeach()