Skip to content

Commit

Permalink
Pass /defaultlib:msvcrt to target_link_options()
Browse files Browse the repository at this point in the history
Do not pass /defaultlib:msvcrt to target_link_libraries(), because it
will be incorrectly treated as a library.
  • Loading branch information
wantehchang committed Jun 21, 2024
1 parent 1842807 commit 8d93ef0
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions cmake/Modules/LocalRav1e.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -99,17 +99,24 @@ else()

set(RAV1E_LIBRARIES ${Rust_CARGO_TARGET_LINK_NATIVE_LIBS})
if(WIN32)
# If an item starts with "/" (e.g., "/defaultlib:msvcrt"), change the
# leading "/" to "-" so that the target_link_libraries() call below
# will treat the item as a linker flag.
list(TRANSFORM RAV1E_LIBRARIES REPLACE "^/" "-")
# If an item in RAV1E_LIBRARIES starts with "/" (e.g.,
# "/defaultlib:msvcrt"), it is a linker option. Pass it to
# target_link_options() instead of target_link_libraries(), otherwise
# target_link_libraries() will treat it as a library.
set(RAV1E_LINK_OPTIONS ${RAV1E_LIBRARIES})
list(FILTER RAV1E_LIBRARIES EXCLUDE REGEX "/.*")
list(FILTER RAV1E_LINK_OPTIONS INCLUDE REGEX "/.*")

# Remove msvcrt from RAV1E_LIBRARIES since it's linked by default
list(REMOVE_ITEM RAV1E_LIBRARIES "msvcrt.lib" "-lmsvcrt")
endif()

add_library(rav1e::rav1e STATIC IMPORTED)
add_dependencies(rav1e::rav1e rav1e)
target_link_libraries(rav1e::rav1e INTERFACE "${RAV1E_LIBRARIES}")
if (RAV1E_LINK_OPTIONS)
target_link_options(rav1e::rav1e INTERFACE "${RAV1E_LINK_OPTIONS}")
endif()
set_target_properties(rav1e::rav1e PROPERTIES IMPORTED_LOCATION "${RAV1E_LIB_FILENAME}" AVIF_LOCAL ON FOLDER "ext/rav1e")
target_include_directories(rav1e::rav1e INTERFACE "${RAV1E_INCLUDE_DIR}")

Expand Down

0 comments on commit 8d93ef0

Please sign in to comment.