Skip to content

Commit 3335ebc

Browse files
Generate pkg-config.pc file in CMake
1 parent 7df0e2f commit 3335ebc

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

CMakeLists.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,3 +552,16 @@ target_include_directories("${PROJECT_NAME}" PUBLIC ${OPENLIBM_INCLUDE_DIRS})
552552
file(GLOB PUBLIC_HEADERS "*.h" "include/*.h" "${OPENLIBM_ARCH_FOLDER}/*.h" "src/*.h")
553553
set_target_properties("${PROJECT_NAME}" PROPERTIES PUBLIC_HEADER "${PUBLIC_HEADERS}")
554554
install (TARGETS "${PROJECT_NAME}")
555+
556+
# Can't use configure_file because openlibm.pc.in uses $var instead of CMake configure @var's
557+
# Would rather string replace variables here instead of editing .pc.in, because editing .pc.in
558+
# might build break autotools build.
559+
file(READ "${PROJECT_SRC}/openlibm.pc.in" PC_FILE)
560+
string(REPLACE "\${version}" ${CMAKE_PROJECT_VERSION} PC_FILE ${PC_FILE})
561+
string(PREPEND PC_FILE "prefix=${CMAKE_INSTALL_PREFIX}
562+
includedir=\${prefix}/${CMAKE_INSTALL_INCLUDEDIR}
563+
libdir=\${prefix}/${CMAKE_INSTALL_LIBDIR}\n
564+
")
565+
file(WRITE "${CMAKE_BINARY_DIR}/${PROJECT_NAME}.pc" ${PC_FILE})
566+
install(FILES "${CMAKE_BINARY_DIR}/${PROJECT_NAME}.pc"
567+
DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")

0 commit comments

Comments
 (0)