From 6d72c94d0cd467ba2f5a0abd35ca486b4669e270 Mon Sep 17 00:00:00 2001 From: Roland Kaufmann Date: Fri, 22 Mar 2013 13:42:03 +0100 Subject: [PATCH 1/2] Factor out routine that converts lib list to cmdline This routine is useful in its own rights and should be made available as a function that others can call too. --- cmake/Modules/LibtoolArchives.cmake | 41 ++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/cmake/Modules/LibtoolArchives.cmake b/cmake/Modules/LibtoolArchives.cmake index f8a6a562..8fbc7935 100644 --- a/cmake/Modules/LibtoolArchives.cmake +++ b/cmake/Modules/LibtoolArchives.cmake @@ -1,14 +1,7 @@ -function (configure_la name target) - if (NOT (UNIX OR MSYS OR MINGW)) - return () - endif (NOT (UNIX OR MSYS OR MINGW)) - - # these generic variables are initialized from the project info - set (current "${${name}_VERSION_MAJOR}") - set (age "${${name}_VERSION_MINOR}") - set (inherited_linker_flags "${${name}_LINKER_FLAGS}") - set (dependency_libs "${${name}_LIBRARIES}") - +# translate a list of libraries into a command-line that can be passed to the +# compiler/linker. first parameter is the name of the variable that will +# receive this list, the rest is considered the list of libraries +function (linker_cmdline what INTO outvar FROM) # if we are going to put these in regexps, we must escape period string (REPLACE "." "\\." esc_dl_pref "${CMAKE_SHARED_LIBRARY_PREFIX}") string (REPLACE "." "\\." esc_dl_suff "${CMAKE_SHARED_LIBRARY_SUFFIX}") @@ -19,7 +12,7 @@ function (configure_la name target) # (you get an error message about argument not parsed). translate each # of the libraries into a linker option set (deplib_list "") - foreach (deplib IN LISTS dependency_libs) + foreach (deplib IN LISTS ARGN) # starts with a hyphen already? then just add it string (SUBSTRING ${deplib} 0 1 dash) if (${dash} STREQUAL "-") @@ -61,8 +54,30 @@ function (configure_la name target) endif (deplib_orig STREQUAL deplib_name) endif (${dash} STREQUAL "-") endforeach (deplib) - set (dependency_libs ${deplib_list}) + # caller determines whether we want it returned as a list or a string + if ("${what}" STREQUAL "LIST") + set (${outvar} ${deplib_list}) + else ("${what}" STREQUAL "LIST") + set (${outvar} "${deplib_list}") + string (REPLACE ";" " " ${outvar} "${${outvar}}") + endif ("${what}" STREQUAL "LIST") + set (${outvar} "${${outvar}}" PARENT_SCOPE) +endfunction (linker_cmdline what INTO outvar FROM) +function (configure_la name target) + if (NOT (UNIX OR MSYS OR MINGW)) + return () + endif (NOT (UNIX OR MSYS OR MINGW)) + + # these generic variables are initialized from the project info + set (current "${${name}_VERSION_MAJOR}") + set (age "${${name}_VERSION_MINOR}") + set (inherited_linker_flags "${${name}_LINKER_FLAGS}") + set (dependency_libs "${${name}_LIBRARIES}") + + # translate list of libraries to command line + linker_cmdline (LIST INTO dependency_libs FROM ${dependency_libs}) + # convert from CMake list (i.e. semi-colon separated) string (REPLACE ";" " " inherited_linker_flags "${inherited_linker_flags}") string (REPLACE ";" " " dependency_libs "${dependency_libs}") From 1dd608358c55c167ae4cae642af4955b2b86a207 Mon Sep 17 00:00:00 2001 From: Roland Kaufmann Date: Fri, 22 Mar 2013 13:44:06 +0100 Subject: [PATCH 2/2] Write cmdline in .pc file without abs paths When passing libraries to gcc/ld, the search path and library name must be specified separately. This is already done when writing a libtool .la and should be done in the pkg-config .pc file too. --- cmake/Modules/OpmProject.cmake | 7 +++++-- cmake/Templates/opm-project.pc.in | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/cmake/Modules/OpmProject.cmake b/cmake/Modules/OpmProject.cmake index 0aca6056..4ee05cac 100644 --- a/cmake/Modules/OpmProject.cmake +++ b/cmake/Modules/OpmProject.cmake @@ -1,5 +1,7 @@ # - Helper routines for opm-core like projects +include (LibtoolArchives) # linker_cmdline + # convert a list back to a command-line string function (unseparate_args var_name prefix value) separate_arguments (value) @@ -18,15 +20,16 @@ endfunction (unseparate_args var_name prefix value) function (configure_pc_file name source dest prefix 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}") + linker_cmdline (STRING INTO libs FROM ${${name}_LIBRARIES}) # necessary to make these variables visible to configure_file set (name "${${name}_NAME}") set (description "${${name}_DESCRIPTION}") - set (target "${${name}_LIBRARY}") set (major "${${name}_VERSION_MAJOR}") set (minor "${${name}_VERSION_MINOR}") + set (target "${${name}_LIBRARY}") + linker_cmdline (STRING INTO target from ${target}) configure_file (${source} ${dest} @ONLY) endfunction (configure_pc_file name source dist prefix libdir includedir) diff --git a/cmake/Templates/opm-project.pc.in b/cmake/Templates/opm-project.pc.in index 1204d4bd..8a6c915b 100644 --- a/cmake/Templates/opm-project.pc.in +++ b/cmake/Templates/opm-project.pc.in @@ -9,5 +9,5 @@ Name: @name@ Description: @description@ @major@.@minor@ Version: @major@.@minor@ URL: http://opm-project.org -Libs: -l@target@ @libs@ +Libs: @target@ @libs@ Cflags: @includes@ @defs@