Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PhysX Gem can't be used as build dependency in engine SDK #1971

Closed
fabioanderegg opened this issue Jul 8, 2021 · 2 comments
Closed

PhysX Gem can't be used as build dependency in engine SDK #1971

fabioanderegg opened this issue Jul 8, 2021 · 2 comments
Assignees
Labels
kind/bug Categorizes issue or PR as related to a bug. sig/build Categorizes an issue or PR as relevant to SIG Build.

Comments

@fabioanderegg
Copy link

fabioanderegg commented Jul 8, 2021

Describe the bug
If the PhysX Gem is added as a build dependency in CMakeLists.txt, generating the project files with CMake fail with the following error:

CMake Error at D:/dev/open3d/o3de-install/cmake/LYWrappers.cmake:174 (add_library):
  Target "PhysXTest" links to target
  "$<TARGET_PROPERTY:Gem::LmbrCentral,INTERFACE_LINK_LIBRARIES>" but the
  target was not found.  Perhaps a find_package() call is missing for an
  IMPORTED target, or an ALIAS target is missing?
Call Stack (most recent call first):
  Code/CMakeLists.txt:42 (ly_add_target)

CMake Error at D:/dev/open3d/o3de-install/cmake/LYWrappers.cmake:174 (add_library):
  Target "PhysXTest" links to target
  "$<TARGET_PROPERTY:Gem::LmbrCentral,INTERFACE_LINK_LIBRARIES>" but the
  target was not found.  Perhaps a find_package() call is missing for an
  IMPORTED target, or an ALIAS target is missing?
Call Stack (most recent call first):
  Code/CMakeLists.txt:42 (ly_add_target)

CMake Error at D:/dev/open3d/o3de-install/cmake/LYWrappers.cmake:174 (add_library):
  Target "PhysXTest" links to target
  "$<TARGET_PROPERTY:Gem::LmbrCentral,INTERFACE_LINK_LIBRARIES>" but the
  target was not found.  Perhaps a find_package() call is missing for an
  IMPORTED target, or an ALIAS target is missing?
Call Stack (most recent call first):
  Code/CMakeLists.txt:42 (ly_add_target)

-- Generating done
CMake Generate step failed.  Build files cannot be regenerated correctly.

To Reproduce
Steps to reproduce the behavior:

  1. Build the engine as an SDK
  2. Create a new project from the Project Manager
  3. In the projects CMakeLists.txt, add Gem::PhysX to BUILD_DEPENDENCIES:
ly_add_target(
    NAME PhysXTest.Static STATIC
    NAMESPACE Gem
    FILES_CMAKE
        physxtest_files.cmake
        ${pal_dir}/physxtest_${PAL_PLATFORM_NAME_LOWERCASE}_files.cmake
    INCLUDE_DIRECTORIES
        PUBLIC
            Include
    BUILD_DEPENDENCIES
        PRIVATE
            AZ::AzGameFramework
            Gem::Atom_AtomBridge.Static
            Gem::PhysX
)

(Doesn't matter if it's in <project> or <project>.Static Target

Expected behavior
Successful cmake configure and build

Additional context
A workaround is commenting out a line in \o3de-install\Gems\PhysX\Code\CMakeLists.txt (4th last line):

ly_add_target(
    NAME PhysX IMPORTED GEM_MODULE
    NAMESPACE Gem
    COMPILE_DEFINITIONS
        INTERFACE
PHYSX_ENABLE_MULTI_THREADING
    INCLUDE_DIRECTORIES
        INTERFACE
${LY_ROOT_FOLDER}/include/Gems/PhysX/Code/Include

    BUILD_DEPENDENCIES
        INTERFACE
Gem::PhysX.Static
#$<TARGET_PROPERTY:Gem::LmbrCentral,INTERFACE_LINK_LIBRARIES>
    RUNTIME_DEPENDENCIES
Gem::LmbrCentral
)

There are other references to Gem::LmbrCentral,INTERFACE_LINK_LIBRARIES, but it looks like this line is the only one that causes the error.

SDK build of the development branch, commit ec02696.

@fabioanderegg fabioanderegg added kind/bug Categorizes issue or PR as related to a bug. needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Jul 8, 2021
@lemonade-dm lemonade-dm self-assigned this Jul 9, 2021
@lemonade-dm
Copy link
Contributor

lemonade-dm commented Jul 9, 2021

@amznestebanpapp I tried two approaches which haven't completely succeeded at solving this issue.

The first was to replace the call to call to WRITE out the generated CMakeLists.txt with a GENERATE command in the Install_common.cmake, but that ran into the issue, file(GENERATE) cannot resolve $<LINK_ONLY:...> generator expression and CMake will not support doing so.

This also has the issue that O3DE specifies generator expressions as part of ly_add_target calls, and they shouldn't be resolved by the INSTALL build. Those calls would need to be installed by the Project build.
One such example is the Vegetation Gem uses a Generator Expression for the VEG_PROFILE_ENABLED compile definition in debug and profile configurations.

My second approach was to add the GLOBAL tag to the add_library call for the generated IMPORTED targets, but... that is already being done: https://github.com/o3de/o3de/blob/stabilization/2106/cmake/LYWrappers.cmake#L138-L140

Gem::LmbrCentral should be an alias of the global LmbrCentral target so it should be able to be seen by other Gem CMakeLists.txt files, but that doesn't seem to be the case.

I added this blurb to the installed layout Gems/LmbrCentral/Code/CMakeLists.txt and the targets are marked as GLOBAL targets

get_property(is_global_alias TARGET Gem::LmbrCentral PROPERTY ALIAS_GLOBAL)
get_property(is_global_imported TARGET LmbrCentral PROPERTY IMPORTED_GLOBAL)
message(STATUS "The Gem::LmbrCentral target has an ALIAS_GLOBAL value of ${is_global_alias}")
message(STATUS "The LmbrCentral target has an IMPORTED_GLOBAL value of ${is_global_imported}")

-- The Gem::LmbrCentral target has an ALIAS_GLOBAL value of TRUE
-- The LmbrCentral target has an IMPORTED_GLOBAL value of TRUE

@amznestebanpapp
Copy link
Contributor

We talked with @lumberyard-employee-dm offline and found the root cause of the issue, have a fix for it

@amznestebanpapp amznestebanpapp added sig/build Categorizes an issue or PR as relevant to SIG Build. and removed needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Jul 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Categorizes issue or PR as related to a bug. sig/build Categorizes an issue or PR as relevant to SIG Build.
Projects
None yet
Development

No branches or pull requests

3 participants