diff --git a/cmake/FindLZO.cmake b/cmake/FindLZO.cmake index 20ea4c1b57..920b58b71f 100644 --- a/cmake/FindLZO.cmake +++ b/cmake/FindLZO.cmake @@ -43,29 +43,8 @@ find_library(LZO_LIBRARY PATHS ${PC_LZO_LIBRARY_DIRS} ) -# With vcpkg, the library path should contain both 'debug' and 'optimized' -# entries (see target_link_libraries() documentation for more information) -# -# NOTE: we only patch up when using vcpkg; the same issue might happen -# when not using vcpkg, but this is non-trivial to fix, as we have no idea -# what the paths are. With vcpkg we do. And we only official support vcpkg -# with Windows. -# -# NOTE: this is based on the assumption that the debug file has the same -# name as the optimized file. This is not always the case, but so far -# experiences has shown that in those case vcpkg CMake files do the right -# thing. -if(VCPKG_TOOLCHAIN AND LZO_LIBRARY AND LZO_LIBRARY MATCHES "${VCPKG_INSTALLED_DIR}") - if(LZO_LIBRARY MATCHES "/debug/") - set(LZO_LIBRARY_DEBUG ${LZO_LIBRARY}) - string(REPLACE "/debug/lib/" "/lib/" LZO_LIBRARY_RELEASE ${LZO_LIBRARY}) - else() - set(LZO_LIBRARY_RELEASE ${LZO_LIBRARY}) - string(REPLACE "/lib/" "/debug/lib/" LZO_LIBRARY_DEBUG ${LZO_LIBRARY}) - endif() - include(SelectLibraryConfigurations) - select_library_configurations(LZO) -endif() +include(FixVcpkgLibrary) +FixVcpkgLibrary(LZO) set(LZO_VERSION ${PC_LZO_VERSION}) diff --git a/cmake/FindOgg.cmake b/cmake/FindOgg.cmake index a6487fe083..e0106d25b8 100644 --- a/cmake/FindOgg.cmake +++ b/cmake/FindOgg.cmake @@ -4,6 +4,9 @@ find_library(Ogg_LIBRARY NAMES ogg ) +include(FixVcpkgLibrary) +FixVcpkgLibrary(Ogg) + set(Ogg_COMPILE_OPTIONS "" CACHE STRING "Extra compile options of ogg") set(Ogg_LINK_LIBRARIES "" CACHE STRING "Extra link libraries of ogg") @@ -33,5 +36,6 @@ if (Ogg_FOUND) INTERFACE_LINK_LIBRARIES "${Ogg_LINK_LIBRARIES}" INTERFACE_LINK_FLAGS "${Ogg_LINK_FLAGS}" ) + FixVcpkgTarget(Ogg Ogg::ogg) endif() endif() diff --git a/cmake/FindOpus.cmake b/cmake/FindOpus.cmake index c8ad1b48a5..742a17b818 100644 --- a/cmake/FindOpus.cmake +++ b/cmake/FindOpus.cmake @@ -4,6 +4,9 @@ find_library(Opus_LIBRARY NAMES opus ) +include(FixVcpkgLibrary) +FixVcpkgLibrary(Opus) + set(Opus_COMPILE_OPTIONS "" CACHE STRING "Extra compile options of opus") set(Opus_LINK_LIBRARIES "" CACHE STRING "Extra link libraries of opus") @@ -33,5 +36,6 @@ if (Opus_FOUND) INTERFACE_LINK_LIBRARIES "${Opus_LINK_LIBRARIES}" INTERFACE_LINK_FLAGS "${Opus_LINK_FLAGS}" ) + FixVcpkgTarget(Opus Opus::opus) endif() endif() diff --git a/cmake/FindOpusFile.cmake b/cmake/FindOpusFile.cmake index 8cc4a3b263..809a948618 100644 --- a/cmake/FindOpusFile.cmake +++ b/cmake/FindOpusFile.cmake @@ -4,6 +4,9 @@ find_library(OpusFile_LIBRARY NAMES opusfile ) +include(FixVcpkgLibrary) +FixVcpkgLibrary(OpusFile) + set(OpusFile_COMPILE_OPTIONS "" CACHE STRING "Extra compile options of opusfile") set(OpusFile_LINK_LIBRARIES "" CACHE STRING "Extra link libraries of opusfile") @@ -36,5 +39,6 @@ if (OpusFile_FOUND) INTERFACE_LINK_LIBRARIES "Ogg::ogg;Opus::opus;${OpusFile_LINK_LIBRARIES}" INTERFACE_LINK_FLAGS "${OpusFile_LINK_FLAGS}" ) + FixVcpkgTarget(OpusFile OpusFile::opusfile) endif() endif() diff --git a/cmake/FixVcpkgLibrary.cmake b/cmake/FixVcpkgLibrary.cmake new file mode 100644 index 0000000000..db75d96ff6 --- /dev/null +++ b/cmake/FixVcpkgLibrary.cmake @@ -0,0 +1,40 @@ +macro(FixVcpkgLibrary NAME) + # With vcpkg, the library path should contain both 'debug' and 'optimized' + # entries (see target_link_libraries() documentation for more information) + # + # NOTE: we only patch up when using vcpkg; the same issue might happen + # when not using vcpkg, but this is non-trivial to fix, as we have no idea + # what the paths are. With vcpkg we do. And we only official support vcpkg + # with Windows. + # + # NOTE: this is based on the assumption that the debug file has the same + # name as the optimized file. This is not always the case, but so far + # experiences has shown that in those case vcpkg CMake files do the right + # thing. + if(VCPKG_TOOLCHAIN AND ${NAME}_LIBRARY AND ${NAME}_LIBRARY MATCHES "${VCPKG_INSTALLED_DIR}") + if(${NAME}_LIBRARY MATCHES "/debug/") + set(${NAME}_LIBRARY_DEBUG ${${NAME}_LIBRARY}) + string(REPLACE "/debug/lib/" "/lib/" ${NAME}_LIBRARY_RELEASE ${${NAME}_LIBRARY}) + else() + set(${NAME}_LIBRARY_RELEASE ${${NAME}_LIBRARY}) + string(REPLACE "/lib/" "/debug/lib/" ${NAME}_LIBRARY_DEBUG ${${NAME}_LIBRARY}) + endif() + include(SelectLibraryConfigurations) + select_library_configurations(${NAME}) + endif() +endmacro() + +function(FixVcpkgTarget NAME TARGET) + if(EXISTS "${${NAME}_LIBRARY_RELEASE}") + set_property(TARGET ${TARGET} APPEND PROPERTY + IMPORTED_CONFIGURATIONS RELEASE) + set_target_properties(${TARGET} PROPERTIES + IMPORTED_LOCATION_RELEASE "${${NAME}_LIBRARY_RELEASE}") + endif() + if(EXISTS "${${NAME}_LIBRARY_DEBUG}") + set_property(TARGET ${TARGET} APPEND PROPERTY + IMPORTED_CONFIGURATIONS DEBUG) + set_target_properties(${TARGET} PROPERTIES + IMPORTED_LOCATION_DEBUG "${${NAME}_LIBRARY_DEBUG}") + endif() +endfunction()