28 lines
1.2 KiB
CMake
28 lines
1.2 KiB
CMake
# Create a shared and static library
|
|
function(add_common_library LIBNAME SOURCES)
|
|
add_library(${LIBNAME} OBJECT ${SOURCES})
|
|
target_include_directories(${LIBNAME} PUBLIC
|
|
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
|
|
$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/include>
|
|
$<INSTALL_INTERFACE:include/${LIBNAME}>)
|
|
get_property(VER GLOBAL PROPERTY VERSION_STR)
|
|
get_property(SOVER GLOBAL PROPERTY VERSION_MAJOR)
|
|
set_property(TARGET ${LIBNAME} PROPERTY VERSION "${VER}")
|
|
set_property(TARGET ${LIBNAME} PROPERTY SOVERSION "${SOVER}")
|
|
set_property(TARGET ${LIBNAME} PROPERTY POSITION_INDEPENDENT_CODE ON)
|
|
|
|
add_library(${LIBNAME}_shared SHARED $<TARGET_OBJECTS:${LIBNAME}>)
|
|
set_target_properties(${LIBNAME}_shared PROPERTIES OUTPUT_NAME ${LIBNAME})
|
|
|
|
add_library(${LIBNAME}_static STATIC $<TARGET_OBJECTS:${LIBNAME}>)
|
|
set_target_properties(${LIBNAME}_static PROPERTIES OUTPUT_NAME ${LIBNAME})
|
|
|
|
set(_libdir "${CMAKE_BINARY_DIR}/lib")
|
|
if(DEFINED ENV{DEB_HOST_MULTIARCH})
|
|
string(APPEND _libdir "/$ENV{DEB_HOST_MULTIARCH}")
|
|
endif()
|
|
set_target_properties(${LIBNAME}_shared PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${_libdir})
|
|
set_target_properties(${LIBNAME}_static PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${_libdir})
|
|
endfunction()
|
|
|