2022-05-06 09:49:46 +00:00
|
|
|
include_guard(GLOBAL)
|
|
|
|
|
|
|
|
|
2021-12-08 11:32:04 +00:00
|
|
|
# Создание динамической библиотеки из объектной библиотеки
|
|
|
|
function(myx_cmake_add_shared_library target)
|
2021-12-10 08:13:43 +00:00
|
|
|
myx_cmake_canonical_string(${target} _ctarget)
|
|
|
|
option(BUILD_${_ctarget}_SHARED "build shared library ${_ctarget}" ON)
|
|
|
|
if(NOT BUILD_${_ctarget}_SHARED)
|
|
|
|
return()
|
|
|
|
endif()
|
2022-01-25 17:49:02 +00:00
|
|
|
|
2021-12-09 14:14:28 +00:00
|
|
|
get_target_property(__target_type ${target} TYPE)
|
|
|
|
if(NOT __target_type STREQUAL OBJECT_LIBRARY)
|
2021-12-21 10:45:09 +00:00
|
|
|
myx_cmake_message_error("MyxCMake: myx_cmake_add_shared_library needs target of type OBJECT_LIBRARY")
|
2021-12-08 11:32:04 +00:00
|
|
|
endif()
|
|
|
|
|
2021-12-29 09:50:13 +00:00
|
|
|
get_target_property(__output_name ${target} OUTPUT_NAME)
|
|
|
|
if(NOT __output_name)
|
|
|
|
set(__output_name ${target})
|
|
|
|
endif()
|
|
|
|
|
2021-12-08 11:32:04 +00:00
|
|
|
add_library(${target}-shared SHARED $<TARGET_OBJECTS:${target}>)
|
2021-12-29 09:50:13 +00:00
|
|
|
# cmake-format: off
|
|
|
|
set_target_properties(${target}-shared
|
2022-01-25 17:49:02 +00:00
|
|
|
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})
|
2021-12-29 09:50:13 +00:00
|
|
|
# cmake-format: on
|
2021-12-08 11:32:04 +00:00
|
|
|
endfunction()
|