2019-02-12 20:02:48 +00:00
|
|
|
# Создание статической и динамической библиотеки из одинаковых объектных файлов
|
2019-03-05 21:05:25 +00:00
|
|
|
function(add_common_library)
|
|
|
|
set(options)
|
2019-10-04 11:02:07 +00:00
|
|
|
set(oneValueArgs TARGET OUTPUT_NAME)
|
2019-03-05 21:05:25 +00:00
|
|
|
set(multiValueArgs SOURCES)
|
|
|
|
|
2019-12-03 16:23:14 +00:00
|
|
|
cmake_parse_arguments(_LOCAL "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
|
2019-03-05 21:05:25 +00:00
|
|
|
set(LIBNAME ${_LOCAL_TARGET})
|
|
|
|
set(SOURCES ${_LOCAL_SOURCES})
|
|
|
|
|
2019-10-07 10:52:50 +00:00
|
|
|
if(_LOCAL_OUTPUT_NAME)
|
2019-10-04 11:02:07 +00:00
|
|
|
set(OUTNAME ${_LOCAL_OUTPUT_NAME})
|
|
|
|
else()
|
|
|
|
set(OUTNAME ${LIBNAME})
|
|
|
|
endif()
|
|
|
|
|
2019-02-12 16:31:17 +00:00
|
|
|
add_library(${LIBNAME} OBJECT ${SOURCES})
|
2019-12-03 16:23:14 +00:00
|
|
|
target_include_directories(
|
|
|
|
${LIBNAME}
|
|
|
|
PUBLIC
|
|
|
|
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
|
|
|
|
$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/include>
|
|
|
|
$<INSTALL_INTERFACE:include/${LIBNAME}>)
|
2019-02-12 20:02:48 +00:00
|
|
|
set_target_properties(${LIBNAME} PROPERTIES POSITION_INDEPENDENT_CODE ON)
|
2019-02-12 16:31:17 +00:00
|
|
|
|
2019-03-06 09:21:55 +00:00
|
|
|
if(BUILD_SHARED_LIBS)
|
|
|
|
add_library(${LIBNAME}_shared SHARED $<TARGET_OBJECTS:${LIBNAME}>)
|
2019-12-03 16:23:14 +00:00
|
|
|
set_target_properties(
|
|
|
|
${LIBNAME}_shared
|
|
|
|
PROPERTIES
|
|
|
|
VERSION
|
|
|
|
${PROJECT_VERSION}
|
|
|
|
SOVERSION
|
|
|
|
${PROJECT_VERSION_MAJOR}
|
|
|
|
OUTPUT_NAME
|
|
|
|
${OUTNAME}
|
|
|
|
LIBRARY_OUTPUT_DIRECTORY
|
|
|
|
${CMAKE_INSTALL_LIBDIR})
|
2019-03-07 18:47:04 +00:00
|
|
|
install(TARGETS ${LIBNAME}_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)
|
2019-03-07 18:57:24 +00:00
|
|
|
add_library(${LIBNAME}_static STATIC $<TARGET_OBJECTS:${LIBNAME}>)
|
2019-12-03 16:23:14 +00:00
|
|
|
set_target_properties(
|
|
|
|
${LIBNAME}_static PROPERTIES OUTPUT_NAME ${OUTNAME} ARCHIVE_OUTPUT_DIRECTORY
|
|
|
|
${CMAKE_INSTALL_LIBDIR})
|
2019-03-07 18:57:24 +00:00
|
|
|
install(TARGETS ${LIBNAME}_static ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
|
|
|
endif()
|
2019-03-07 18:47:04 +00:00
|
|
|
|
2019-03-07 19:15:07 +00:00
|
|
|
configure_file(${CMLIB_MODULE_DIR}/pc/lib.pc.in ${CMAKE_BINARY_DIR}/${LIBNAME}.pc)
|
2019-12-03 16:23:14 +00:00
|
|
|
install(FILES ${CMAKE_BINARY_DIR}/${LIBNAME}.pc
|
|
|
|
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
|
2019-02-12 16:31:17 +00:00
|
|
|
endfunction()
|