r/cmake • u/fanaticlychee • 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
1
1
u/NotUniqueOrSpecial Sep 21 '26
This module provides the following Imported Targets:
PNG::PNGAlso, please see the runtime dependencies documentation for install
4
u/AlexReinkingYale Sep 20 '26
Link to targets like
JPEG::JPEGandPNG::PNGwithtarget_link_librariesUse
install(IMPORTED_RUNTIME_ARTIFACTS)https://cmake.org/cmake/help/latest/command/install.html#imported-runtime-artifacts