From ad4e9064f73dcddeaa7cac4d046ea19ed7f8413a Mon Sep 17 00:00:00 2001 From: Roland Kaufmann Date: Fri, 25 Jan 2013 21:19:00 +0100 Subject: [PATCH] Write pkgconfig files as well as CMake Note that using pkg-config is NOT recommended because of: 1. It doesn't know which language you are using, so language-specific options such as -std=c++11 or -std=c99 cannot be passed along. Yet, the build will corrupt if you don't get these correct. 2. It has no means of communicating which defines that should be set in config.h, effectively disabling them all, possibly leading to inconsistencies between the library and the executable. --- cmake/Modules/OpmProject.cmake | 54 ++++++++++++++++++++++++++++++++++ opm-core.pc.in | 6 ++++ 2 files changed, 60 insertions(+) create mode 100644 opm-core.pc.in diff --git a/cmake/Modules/OpmProject.cmake b/cmake/Modules/OpmProject.cmake index 84b0ec40..4b123696 100644 --- a/cmake/Modules/OpmProject.cmake +++ b/cmake/Modules/OpmProject.cmake @@ -1,5 +1,34 @@ # - Helper routines for opm-core like projects +# convert a list back to a command-line string +function (unseparate_args var_name prefix value) + separate_arguments (value) + foreach (item IN LISTS value) + set (prefixed_item "${prefix}${item}") + if (${var_name}) + set (${var_name} "${${var_name}} ${prefixed_item}") + else (${var_name}) + set (${var_name} "${prefixed_item}") + endif (${var_name}) + endforeach (item) + set (${var_name} "${${var_name}}" PARENT_SCOPE) +endfunction (unseparate_args var_name prefix value) + +# wrapper to set variables in pkg-config file +function (configure_pc_file name source dest libdir includedir) + # escape set of standard strings + unseparate_args (includes "-I" "${${name}_INCLUDE_DIRS}") + unseparate_args (libs "-l" "${${name}_LIBRARIES}") + unseparate_args (defs "" "${${name}_DEFINITIONS}") + + # necessary to make these variables visible to configure_file + set (target "${${name}_LIBRARY}") + set (major "${${name}_VERSION_MAJOR}") + set (minor "${${name}_VERSION_MINOR}") + + configure_file (${source} ${dest} @ONLY) +endfunction (configure_pc_file name source dist libdir includedir) + # installation of CMake modules to help user programs locate the library function (opm_cmake_config name) # write configuration file to locate library @@ -23,6 +52,15 @@ function (opm_cmake_config name) @ONLY ) + # config-mode .pc file; use this to find the build tree + configure_pc_file ( + ${name} + ${PROJECT_SOURCE_DIR}/${name}.pc.in + ${PROJECT_BINARY_DIR}/${name}.pc + ${CMAKE_LIBRARY_OUTPUT_DIRECTORY} + ${PROJECT_SOURCE_DIR} + ) + # replace the build directory with the target directory in the # variables that contains build paths string (REPLACE @@ -62,4 +100,20 @@ function (opm_cmake_config name) FILES ${PROJECT_BINARY_DIR}/${name}-config-version.cmake DESTINATION share/cmake/${name} ) + + # find-mode .pc file; use this to locate system installation + configure_pc_file ( + ${name} + ${PROJECT_SOURCE_DIR}/${name}.pc.in + ${PROJECT_BINARY_DIR}/${name}-install.pc + ${CMAKE_INSTALL_LIBDIR} + ${CMAKE_INSTALL_PREFIX}/include + ) + + # put this in the right system location; assume that we have binaries + install ( + FILES ${PROJECT_BINARY_DIR}/${name}-install.pc + DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/pkgconfig/ + RENAME ${name}.pc + ) endfunction (opm_cmake_config name) diff --git a/opm-core.pc.in b/opm-core.pc.in new file mode 100644 index 00000000..584f8de2 --- /dev/null +++ b/opm-core.pc.in @@ -0,0 +1,6 @@ +Name: OPM Core +Description: Open Porous Media Initiative Core Library @major@.@minor@ +Version: @major@.@minor@ +URL: http://opm-project.org +Libs: -l@target@ @libs@ +Cflags: @includes@ @defs@