2020-10-12 22:10:28 +02:00
|
|
|
function(get_relative_link OUTPUT PATH)
|
2020-10-13 00:09:26 +02:00
|
|
|
if (PATH MATCHES "^[$]<[$]<CONFIG:DEBUG>:")
|
2020-10-13 11:59:24 +02:00
|
|
|
set(${OUTPUT} "" PARENT_SCOPE)
|
|
|
|
return()
|
|
|
|
endif()
|
|
|
|
string(REGEX REPLACE "^[$]<[$]<NOT:[$]<CONFIG:DEBUG>>:(.*)>$" "\\1" PATH "${PATH}")
|
|
|
|
|
|
|
|
get_filename_component(NAME "${PATH}" NAME_WE)
|
2020-10-13 12:14:28 +02:00
|
|
|
if (IS_ABSOLUTE ${PATH})
|
|
|
|
get_filename_component(DIRECTORY_NAME "${PATH}" DIRECTORY)
|
|
|
|
if (WIN32)
|
|
|
|
set(${OUTPUT} "-l\"${DIRECTORY_NAME}/${NAME}\"" PARENT_SCOPE)
|
|
|
|
else()
|
|
|
|
get_filename_component(FULL_NAME "${PATH}" NAME)
|
|
|
|
set(${OUTPUT} "-L\"${DIRECTORY_NAME}\" -l:${FULL_NAME}" PARENT_SCOPE)
|
|
|
|
endif()
|
|
|
|
return()
|
|
|
|
endif()
|
|
|
|
|
2020-10-13 11:59:24 +02:00
|
|
|
if (NOT WIN32 AND NAME MATCHES "^lib")
|
|
|
|
string(REGEX REPLACE "^lib" "-l" LINK "${NAME}")
|
2020-10-13 00:09:26 +02:00
|
|
|
elseif (NAME MATCHES "^-")
|
2020-10-13 11:59:24 +02:00
|
|
|
set(LINK "${NAME}")
|
2020-10-12 20:39:48 +02:00
|
|
|
else()
|
2020-10-13 11:59:24 +02:00
|
|
|
string(CONCAT LINK "-l" "${NAME}")
|
2020-10-12 20:39:48 +02:00
|
|
|
endif()
|
2020-10-13 11:59:24 +02:00
|
|
|
set(${OUTPUT} "${LINK}" PARENT_SCOPE)
|
2020-10-12 20:31:22 +02:00
|
|
|
endfunction()
|
|
|
|
|
|
|
|
function(generate_pkgconfig TARGET DESCRIPTION)
|
2020-10-12 20:39:48 +02:00
|
|
|
# message("Generating pkg-config for ${TARGET}")
|
2020-10-13 11:59:24 +02:00
|
|
|
get_filename_component(PREFIX "${CMAKE_INSTALL_PREFIX}" REALPATH)
|
2020-10-12 20:31:22 +02:00
|
|
|
|
2020-10-13 11:59:24 +02:00
|
|
|
get_target_property(LIST "${TARGET}" LINK_LIBRARIES)
|
2020-10-12 20:39:48 +02:00
|
|
|
set(REQS "")
|
|
|
|
set(LIBS "")
|
2020-10-12 22:10:28 +02:00
|
|
|
foreach (LIB ${LIST})
|
2020-10-13 11:59:24 +02:00
|
|
|
if (TARGET "${LIB}")
|
2020-10-12 20:39:48 +02:00
|
|
|
set(HAS_REQS 1)
|
2020-10-13 11:59:24 +02:00
|
|
|
list(APPEND REQS "${LIB}")
|
2020-10-12 20:39:48 +02:00
|
|
|
else()
|
|
|
|
set(HAS_LIBS 1)
|
2020-10-13 11:59:24 +02:00
|
|
|
get_relative_link(LINK "${LIB}")
|
2020-10-12 22:10:28 +02:00
|
|
|
if (NOT LINK EQUAL "")
|
2020-10-13 11:59:24 +02:00
|
|
|
list(APPEND LIBS "${LINK}")
|
2020-10-12 22:10:28 +02:00
|
|
|
endif()
|
2020-10-12 20:39:48 +02:00
|
|
|
endif()
|
|
|
|
endforeach()
|
2020-10-12 20:31:22 +02:00
|
|
|
|
2020-10-12 22:10:28 +02:00
|
|
|
if (HAS_REQS)
|
2020-10-12 22:21:30 +02:00
|
|
|
set(REQUIRES "")
|
2020-10-12 20:39:48 +02:00
|
|
|
foreach (REQ ${REQS})
|
2020-10-12 21:31:02 +02:00
|
|
|
set(REQUIRES "${REQUIRES} ${REQ}")
|
2020-10-12 20:39:48 +02:00
|
|
|
endforeach()
|
2020-10-12 22:21:30 +02:00
|
|
|
set(REQUIRES "Requires.private:${REQUIRES}\n")
|
2020-10-12 20:39:48 +02:00
|
|
|
endif()
|
2020-10-12 22:10:28 +02:00
|
|
|
if (HAS_LIBS)
|
2020-10-12 22:21:30 +02:00
|
|
|
set(LIBRARIES "")
|
|
|
|
list(REVERSE LIBS)
|
|
|
|
list(REMOVE_DUPLICATES LIBS)
|
2020-10-12 20:39:48 +02:00
|
|
|
foreach (LIB ${LIBS})
|
2020-10-12 22:21:30 +02:00
|
|
|
set(LIBRARIES " ${LIB}${LIBRARIES}")
|
2020-10-12 20:39:48 +02:00
|
|
|
endforeach()
|
2020-10-12 22:21:30 +02:00
|
|
|
set(LIBRARIES "Libs.private:${LIBRARIES}\n")
|
2020-10-12 20:39:48 +02:00
|
|
|
endif()
|
2020-10-12 20:31:22 +02:00
|
|
|
|
2020-10-12 21:31:02 +02:00
|
|
|
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/pkgconfig")
|
2020-10-13 00:09:26 +02:00
|
|
|
file(GENERATE OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/pkgconfig/${TARGET}.pc" CONTENT
|
2020-10-12 23:50:08 +02:00
|
|
|
"prefix=${PREFIX}
|
|
|
|
|
|
|
|
Name: ${TARGET}
|
2020-10-12 20:31:22 +02:00
|
|
|
Description: ${DESCRIPTION}
|
|
|
|
Version: ${PROJECT_VERSION}
|
|
|
|
|
2020-10-12 23:50:08 +02:00
|
|
|
CFlags: -I\"\${prefix}/${CMAKE_INSTALL_INCLUDEDIR}\"
|
|
|
|
Libs: -L\"\${prefix}/${CMAKE_INSTALL_LIBDIR}\" -l${TARGET}
|
2020-10-12 22:21:30 +02:00
|
|
|
${REQUIRES}${LIBRARIES}")
|
2020-10-12 20:31:22 +02:00
|
|
|
|
2020-11-02 17:34:21 +01:00
|
|
|
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/pkgconfig/${TARGET}.pc" DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
|
2020-10-12 20:31:22 +02:00
|
|
|
endfunction()
|