add_kfr_library.cmake (2001B)
1 function (add_kfr_library) 2 3 cmake_parse_arguments(LIB "MULTIARCH" "NAME" "SOURCES;LIBRARIES;DEFINITIONS;OPTIONS" 4 ${ARGN}) 5 6 set(${LIB_NAME}_LIBS) 7 set(${LIB_NAME}_TARGETS) 8 if (KFR_ENABLE_MULTIARCH AND LIB_MULTIARCH) 9 add_library(${LIB_NAME} INTERFACE) 10 foreach (ARCH IN LISTS KFR_ARCHS) 11 add_library(${LIB_NAME}_${ARCH} STATIC ${LIB_SOURCES}) 12 target_compile_definitions(${LIB_NAME}_${ARCH} PRIVATE CMT_MULTI=1) 13 foreach (ENABLED_ARCH IN LISTS KFR_ARCHS) 14 string(TOUPPER ${ENABLED_ARCH} ENABLED_ARCH_UPPER) 15 target_compile_definitions(${LIB_NAME}_${ARCH} PRIVATE CMT_MULTI_ENABLED_${ENABLED_ARCH_UPPER}=1) 16 endforeach() 17 list(APPEND ${LIB_NAME}_LIBS ${LIB_NAME}_${ARCH}) 18 list(APPEND ${LIB_NAME}_TARGETS ${LIB_NAME}_${ARCH}) 19 target_link_libraries(${LIB_NAME} INTERFACE ${LIB_NAME}_${ARCH}) 20 target_set_arch(${LIB_NAME}_${ARCH} PRIVATE ${ARCH}) 21 endforeach () 22 list(GET KFR_ARCHS 0 BASE_ARCH) 23 target_compile_definitions(${LIB_NAME}_${BASE_ARCH} PRIVATE CMT_BASE_ARCH=1) 24 25 link_as_whole(${LIB_NAME} INTERFACE ${LIB_NAME}_${BASE_ARCH}) 26 27 list(APPEND ${LIB_NAME}_TARGETS ${LIB_NAME}) 28 else () 29 add_library(${LIB_NAME} STATIC ${LIB_SOURCES}) 30 list(APPEND ${LIB_NAME}_LIBS ${LIB_NAME}) 31 list(APPEND ${LIB_NAME}_TARGETS ${LIB_NAME}) 32 target_set_arch(${LIB_NAME} PRIVATE ${KFR_ARCH}) 33 endif () 34 35 foreach (LIB IN LISTS ${LIB_NAME}_LIBS) 36 target_link_libraries(${LIB} PUBLIC kfr) 37 target_link_libraries(${LIB} PRIVATE ${LIB_LIBRARIES}) 38 target_compile_definitions(${LIB} PRIVATE ${LIB_DEFINITIONS}) 39 target_compile_options(${LIB} PRIVATE ${LIB_OPTIONS}) 40 endforeach () 41 42 set(${LIB_NAME}_LIBS ${${LIB_NAME}_LIBS} PARENT_SCOPE) 43 set(${LIB_NAME}_TARGETS ${${LIB_NAME}_TARGETS} PARENT_SCOPE) 44 45 endfunction ()