myx-cmake/MyxCMake/modules/MyxCMakeAddStaticLibrary.cmake

20 lines
728 B
CMake

# Создание статической библиотеки из объектной библиотеки
function(myx_cmake_add_static_library target)
get_target_property(_target_type ${target} TYPE)
if(NOT _target_type STREQUAL OBJECT_LIBRARY)
message(
FATAL_ERROR
"MyxCMake: add_static_library needs target of type OBJECT_LIBRARY")
return()
endif()
add_library(${target}-static STATIC $<TARGET_OBJECTS:${target}>)
set_target_properties(
${target}-static
PROPERTIES OUTPUT_NAME ${target}
ARCHIVE_OUTPUT_DIRECTORY
${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR})
install(TARGETS ${target}-static ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
endfunction()