2019-02-12 20:02:48 +00:00
|
|
|
# Создание статической и динамической библиотеки из одинаковых объектных файлов
|
2020-04-13 16:44:42 +00:00
|
|
|
function(add_common_library target)
|
2019-03-05 21:05:25 +00:00
|
|
|
set(options)
|
2020-04-13 16:44:42 +00:00
|
|
|
set(oneValueArgs OUTPUT_NAME)
|
2019-03-05 21:05:25 +00:00
|
|
|
set(multiValueArgs SOURCES)
|
|
|
|
|
2021-07-06 01:54:20 +00:00
|
|
|
cmake_parse_arguments(_PREFIX "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
|
2019-03-05 21:05:25 +00:00
|
|
|
|
2021-07-06 01:54:20 +00:00
|
|
|
if(_PREFIX_OUTPUT_NAME)
|
|
|
|
set(output_name ${_PREFIX_OUTPUT_NAME})
|
2019-10-04 11:02:07 +00:00
|
|
|
else()
|
2021-06-12 09:59:31 +00:00
|
|
|
set(output_name ${target})
|
2019-10-04 11:02:07 +00:00
|
|
|
endif()
|
|
|
|
|
2021-07-06 01:54:20 +00:00
|
|
|
add_library(${target} OBJECT ${_PREFIX_SOURCES})
|
2019-12-03 16:23:14 +00:00
|
|
|
target_include_directories(
|
2020-04-13 16:44:42 +00:00
|
|
|
${target} PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
|
|
|
|
$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/include> $<INSTALL_INTERFACE:include/${target}>)
|
|
|
|
set_target_properties(${target} PROPERTIES POSITION_INDEPENDENT_CODE ON)
|
2019-02-12 16:31:17 +00:00
|
|
|
|
2020-04-22 16:06:22 +00:00
|
|
|
# cmake-format: off
|
2019-03-06 09:21:55 +00:00
|
|
|
if(BUILD_SHARED_LIBS)
|
2020-04-13 16:44:42 +00:00
|
|
|
add_library(${target}_shared SHARED $<TARGET_OBJECTS:${target}>)
|
2021-06-12 09:59:31 +00:00
|
|
|
set_target_properties(${target}_shared PROPERTIES OUTPUT_NAME ${output_name}
|
2020-04-22 16:06:22 +00:00
|
|
|
VERSION ${PROJECT_VERSION} SOVERSION ${PROJECT_VERSION_MAJOR}
|
|
|
|
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR})
|
2020-04-13 16:44:42 +00:00
|
|
|
install(TARGETS ${target}_shared LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
2019-03-06 09:21:55 +00:00
|
|
|
endif()
|
2019-02-12 16:31:17 +00:00
|
|
|
|
2019-03-11 18:58:25 +00:00
|
|
|
if(NOT SKIP_STATIC_LIBS)
|
2020-04-13 16:44:42 +00:00
|
|
|
add_library(${target}_static STATIC $<TARGET_OBJECTS:${target}>)
|
2021-06-12 09:59:31 +00:00
|
|
|
set_target_properties(${target}_static PROPERTIES OUTPUT_NAME ${output_name}
|
2020-04-22 16:06:22 +00:00
|
|
|
ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR})
|
2020-04-13 16:44:42 +00:00
|
|
|
install(TARGETS ${target}_static ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
2019-03-07 18:57:24 +00:00
|
|
|
endif()
|
2020-04-22 16:06:22 +00:00
|
|
|
# cmake-format: on
|
2019-02-12 16:31:17 +00:00
|
|
|
endfunction()
|