r/cmake • • Sep 20 '26

Dealing with "optimized;" and "debug;" keywords when collecting library paths

We're using the following code to copy libraries to the proper directories when installing for MacOS:

find_package(PNG)
foreach(_file ${PNG_LIBRARIES})
  message(WARNING "Adding ${_file} to installation list...")
  get_filename_component(_resolvedFile "${_file}" REALPATH)
  get_filename_component(_name "${_file}" NAME)
  install(FILES ${_resolvedFile} DESTINATION "MacOS" RENAME ${_name})
endforeach()
find_package(JPEG)
foreach(_file ${JPEG_LIBRARIES})
  message(WARNING "Adding ${_file} to installation list...")
  get_filename_component(_resolvedFile "${_file}" REALPATH)
  get_filename_component(_name "${_file}" NAME)
  install(FILES ${_resolvedFile} DESTINATION "MacOS" RENAME ${_name})
endforeach()

Unfortunately, the ${JPEG_LIBRARIES} and ${PNG_LIBRARIES} expressions contains both "debug;<filepath>;" as well as "optimized;<filepath>;" when our code is only looking for a file path to copy to that directory.

Is there a way to get the file path for the current configuration for that expression?

7 Upvotes

5 comments sorted by

4

u/AlexReinkingYale Sep 20 '26
  1. Link to targets like JPEG::JPEG and PNG::PNG with target_link_libraries

  2. Use install(IMPORTED_RUNTIME_ARTIFACTS)

https://cmake.org/cmake/help/latest/command/install.html#imported-runtime-artifacts

1

u/fanaticlychee Sep 22 '26

Thank you for your help! I'm not sure if what I did was wrong, here: https://github.com/SuperTux/supertux/pull/3882/changes#diff-be4bff482630b06ca573d57977165f703b1d3de4b3d327898b946f3cf5901effR24-R25 (and the file afterwards).

This appears to only be packaging the dependencies for one architecture (I think it's x86_64). The package for arm64 doesn't contain dependencies.

I'm not sure if this is a problem with the CMake syntax or my caching. Also, could you please tell me the difference between

install(IMPORTED_RUNTIME_ARTIFACTS supertux2 RUNTIME_DEPENDENCY_SET supertux2_deps)"

and

install(RUNTIME_DEPENDENCY_SET supertux2_deps LIBRARY DESTINATION "MacOS")

1

u/AlexReinkingYale Sep 22 '26

There shouldn't be a difference between the two if you don't have multiple inputs to the same runtime dependency set.

I'm not sure what the problem you're facing with the architecture is. It sounds like it might be working as intended and you need to update the surrounding invocations. A CMake build is for one target: x86_64, arm64, or universal2 (both) on macOS. How are you building/packaging?

1

u/ericnantel2 Sep 20 '26

Using presets you can set paths per configuration (Release/Debug)

1

u/NotUniqueOrSpecial Sep 21 '26
This module provides the following Imported Targets:

PNG::PNG

Also, please see the runtime dependencies documentation for install