Выходное имя библиотеки наследуется от основной цели

This commit is contained in:
Andrei Astafev 2021-12-29 12:50:13 +03:00
parent c82b5f29f1
commit 530055de9d
2 changed files with 18 additions and 7 deletions

View File

@ -10,10 +10,15 @@ function(myx_cmake_add_shared_library target)
myx_cmake_message_error("MyxCMake: myx_cmake_add_shared_library needs target of type OBJECT_LIBRARY")
endif()
get_target_property(__output_name ${target} OUTPUT_NAME)
if(NOT __output_name)
set(__output_name ${target})
endif()
add_library(${target}-shared SHARED $<TARGET_OBJECTS:${target}>)
set_target_properties(
${target}-shared
PROPERTIES OUTPUT_NAME ${target}
# cmake-format: off
set_target_properties(${target}-shared
PROPERTIES OUTPUT_NAME ${__output_name}
VERSION ${PROJECT_VERSION}
SOVERSION ${PROJECT_VERSION_MAJOR}
LIBRARY_OUTPUT_DIRECTORY
@ -21,4 +26,5 @@ function(myx_cmake_add_shared_library target)
install(TARGETS ${target}-shared
COMPONENT main
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
# cmake-format: on
endfunction()

View File

@ -10,13 +10,18 @@ function(myx_cmake_add_static_library target)
myx_cmake_message_error("MyxCMake: myx_cmake_add_static_library needs target of type OBJECT_LIBRARY")
endif()
get_target_property(__output_name ${target} OUTPUT_NAME)
if(NOT __output_name)
set(__output_name ${target})
endif()
add_library(${target}-static STATIC $<TARGET_OBJECTS:${target}>)
# cmake-format: off
set_target_properties(${target}-static
PROPERTIES
OUTPUT_NAME ${target}
PROPERTIES OUTPUT_NAME ${__output_name}
ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR})
install(TARGETS ${target}-static
COMPONENT static
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
# cmake-format: on
endfunction()