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

Fix a bug that unexpectedly created library symlink #550

Merged
merged 2 commits into from
Mar 23, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@ macro(library_target_setup tgt)
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)

get_target_property(name ${tgt} NAME)
get_target_property(output_name ${tgt} OUTPUT_NAME)
if(NOT name STREQUAL output_name AND NOT CMAKE_HOST_WIN32)
if(NOT CMAKE_HOST_WIN32)
# Create library symlink
get_target_property(target_type ${tgt} TYPE)
if(target_type STREQUAL "SHARED_LIBRARY")
Expand All @@ -47,13 +48,18 @@ macro(library_target_setup tgt)
set(library_prefix ${CMAKE_STATIC_LIBRARY_PREFIX})
set(library_suffix ${CMAKE_STATIC_LIBRARY_SUFFIX})
endif()

list(APPEND noop_command "${CMAKE_COMMAND}" "-E" "true")
list(APPEND create_symlink_command "${CMAKE_COMMAND}" "-E" "create_symlink" "${library_prefix}${output_name}${library_suffix}" "${library_prefix}${name}${library_suffix}")
# `add_custom_command()` does nothing if the `OUTPUT_NAME` and `NAME`
# properties are equal, otherwise it creates library symlink.
add_custom_command(TARGET ${tgt} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E create_symlink "${library_prefix}${output_name}${library_suffix}" "${library_prefix}${name}${library_suffix}"
COMMAND "$<IF:$<STREQUAL:${name},${output_name}>,${noop_command},${create_symlink_command}>"
VERBATIM
COMMAND_EXPAND_LISTS
)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${library_prefix}${name}${library_suffix}
DESTINATION ${CMAKE_INSTALL_LIBDIR}
install(FILES $<TARGET_FILE_DIR:${tgt}>/${library_prefix}${name}${library_suffix}
DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
endif()
endmacro()
Expand Down