myx-cmake/MyxCMake/modules/MyxCMakeAddSharedLibrary.cmake

33 lines
1.1 KiB
CMake

# Создание динамической библиотеки из объектной библиотеки
function(myx_cmake_add_shared_library target)
myx_cmake_canonical_string(${target} _ctarget)
option(BUILD_${_ctarget}_SHARED "build shared library ${_ctarget}" ON)
if(NOT BUILD_${_ctarget}_SHARED)
return()
endif()
get_target_property(__target_type ${target} TYPE)
if(NOT __target_type STREQUAL OBJECT_LIBRARY)
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}>)
# cmake-format: off
set_target_properties(${target}-shared
PROPERTIES
OUTPUT_NAME ${__output_name}
VERSION ${PROJECT_VERSION}
SOVERSION ${PROJECT_VERSION_MAJOR}
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR})
install(TARGETS
${target}-shared
COMPONENT main
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
# cmake-format: on
endfunction()