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.
This commit is contained in:
Roland Kaufmann 2013-01-25 21:19:00 +01:00
parent 848c30a67e
commit ad4e9064f7
2 changed files with 60 additions and 0 deletions

View File

@ -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)

6
opm-core.pc.in Normal file
View File

@ -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@