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

CMake cant locate imported executables (usResourceCompiler3, etc.) when pulled in via vcpkg #851

Open
XJ-0461 opened this issue May 16, 2023 · 1 comment

Comments

@XJ-0461
Copy link
Contributor

XJ-0461 commented May 16, 2023

Expected Behavior

When building with vcpkg, CMake can locate the imported tools (usResourceCompiler3, jsonschemavalidator, usShell3) in the /vcpkg/installed/x64-linux/tools/cppmicroservices/ directory

Actual Behavior

When building with vcpkg, CMake is attempting to locate the tools in the /vcpkg/installed/x64-linux/share/tools/cppmicroservices/ directory. It is not able to find them and throws configuration errors.

Description

OS: Fedora Linux 38 (Workstation Edition) x86_64
Kernel: 6.2.14-200.fc37.x86_64
CPU: 11th Gen Intel i5-11320H (8) @ 4.500GHz
Compiler: gcc version 13.1.1 20230426 (Red Hat 13.1.1-1) (GCC)

Building a project with CMake under Debug configuration, pulling in CppMicroServices with vcpkg:

CMake Error at /home/myUser/Programs/test-project/vcpkg/installed/x64-linux/share/cppmicroservices/cmake/CppMicroServicesTargets.cmake:81 (message):
  The imported target "usResourceCompiler" references the file

     "/home/myUser/Programs/test-project/vcpkg/installed/x64-linux/share/tools/cppmicroservices/usResourceCompiler3"

  but this file does not exist.

The file actually exists in -> /home/myUser/Programs/test-project/vcpkg/installed/x64-linux/tools/cppmicroservices/usResourceCompiler3. (which is the vcpkg convention)

Somehow the _IMPORT_PREFIX is pointing to the wrong directory in the generated CppMicroServicesTargets-*.cmake files.
It must be getting set as /home/myUser/Programs/test-project/vcpkg/installed/x64-linux/share/. Because TOOLS_INSTALL_DIR is fine as TOOLS_INSTALL_DIR:STRING=tools/cppmicroservices

CppMicroServicesTargets-debug.cmake

# Import target "usResourceCompiler" for configuration "Debug"
set_property(TARGET usResourceCompiler APPEND PROPERTY IMPORTED_CONFIGURATIONS DEBUG)
set_target_properties(usResourceCompiler PROPERTIES
  IMPORTED_LOCATION_DEBUG "${_IMPORT_PREFIX}/tools/cppmicroservices/usResourceCompiler3"
  )

CppMicroservicesTargets-release.cmake

# Import target "usResourceCompiler" for configuration "Release"
set_property(TARGET usResourceCompiler APPEND PROPERTY IMPORTED_CONFIGURATIONS RELEASE)
set_target_properties(usResourceCompiler PROPERTIES
  IMPORTED_LOCATION_RELEASE "${_IMPORT_PREFIX}/tools/cppmicroservices/usResourceCompiler3"
  )

I believe the problem is in the generated CppMicroServicesTargets.cmake

# Compute the installation prefix relative to this file.
get_filename_component(_IMPORT_PREFIX "${CMAKE_CURRENT_LIST_FILE}" PATH)
get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH)
get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH)
if(_IMPORT_PREFIX STREQUAL "/")
  set(_IMPORT_PREFIX "")
endif()

As CMAKE_CURRENT_LIST_FILE is /home/myUser/Programs/test-project/vcpkg/installed/x64-linux/share/cppmicroservices/cmake/CppMicroServicesTargets.cmake, the _IMPORT_PREFIX is set from there and then the two get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH) commands shave off the two topmost directories. Leaving us with /home/myUser/Programs/test-project/vcpkg/installed/x64-linux/share/.

If I change it to:

# Compute the installation prefix relative to this file.
get_filename_component(_IMPORT_PREFIX "${CMAKE_CURRENT_LIST_FILE}" PATH)
get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH)
get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH)
get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH) # ADDED THIS LINE!!
if(_IMPORT_PREFIX STREQUAL "/")
  set(_IMPORT_PREFIX "")
endif()

The usResourceCompiler target can actually be found, but expectedly it causes problems locating other resources. I'm assuming the problem is in the tools/*/CMakeLists.txt specifically this part:

if(NOT US_NO_INSTALL)
    install(TARGETS ${US_RCC_EXECUTABLE_TARGET}
            EXPORT ${PROJECT_NAME}Targets
            FRAMEWORK DESTINATION . ${US_SDK_INSTALL_COMPONENT}
            RUNTIME DESTINATION ${TOOLS_INSTALL_DIR} ${US_SDK_INSTALL_COMPONENT})
endif()

if(CMAKE_CROSSCOMPILING)
  # When cross-compiling, import the host machine executable from a file
  # See https://gitlab.kitware.com/cmake/community/wikis/doc/cmake/CrossCompiling
  include(${IMPORT_EXECUTABLES})
else()
  # Export the host usResourceCompiler target to a file so it can be imported when cross-compiling.
  # Use the NAMESPACE option of EXPORT() to get a different target name for ${US_RCC_EXECUTABLE_TARGET}
  # when exporting.
  # Doing this allows the host built usResourceCompiler to be used when cross-compiling and allows
  # the usResourceCompiler to be built and installed for the target machine.
  export( TARGETS ${US_RCC_EXECUTABLE_TARGET} FILE ${IMPORT_EXECUTABLES} NAMESPACE native-)
endif()

I've been experimenting around here but haven't been able to find any fix.

@dg0yt
Copy link

dg0yt commented Oct 18, 2023

The vcpkg port needs work.
Test microsoft/vcpkg#34552.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants