Skip to content

GitLab

  • Menu
Projects Groups Snippets
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in
  • morse_cmake morse_cmake
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 2
    • Issues 2
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 0
    • Merge requests 0
  • Deployments
    • Deployments
    • Releases
  • Monitor
    • Monitor
    • Incidents
  • Packages & Registries
    • Packages & Registries
    • Container Registry
  • Analytics
    • Analytics
    • Value stream
    • Repository
  • Wiki
    • Wiki
  • Activity
  • Graph
  • Create a new issue
  • Commits
  • Issue Boards
Collapse sidebar
  • solverstack
  • morse_cmakemorse_cmake
  • Issues
  • #1

Closed
Open
Created May 17, 2017 by MIJIEUX Thomas@tmijieuxContributor

Pkg-config part of FindCHAMELEON.cmake

When I use find_package(CHAMELEON), I get the following results

-- Looking for CHAMELEON - found using PkgConfig
-- Found CHAMELEON: chameleon;chameleon_starpu;coreblas

The second line is the command find_package_handle_standard_args which print the content of the CHAMELEON_LIBRARIES variables.
These are not absolute path to the libraries which means it is mandatory for the user (me) to use the link_directories() command which set link directories globally for all target created after the command is called)

Currently the pkg-config part of the code roughly do the following:

pkg_check_modules(CHAMELEON chameleon)
#... version check
set(CHAMELEON_INCLUDE_DIRS_DEP "${CHAMELEON_STATIC_INCLUDE_DIRS}")
set(CHAMELEON_LIBRARY_DIRS_DEP "${CHAMELEON_STATIC_LIBRARY_DIRS}")
set(CHAMELEON_LIBRARIES_DEP "${CHAMELEON_STATIC_LIBRARIES}")
#...
find_package_handle_standard_args(CHAMELEON DEFAULT_MSG CHAMELEON_LIBRARIES)

Which means this is a direct use of pkg-config values, which is not advised.
After reading carefully cmake guidelines about find package modules (in particular Piggybacking on pkg-config and Writing find modules)
and second paragraph from the link_directories() command (It is mentioned that find_package should return absolute paths!), I think something like this would be better.

macro(FIND_LIBRARIES_FROM_PKGCONFIG_RESULTS _prefix _pc_xprefix)
    foreach(_library ${${_pc_xprefix}_LIBRARIES})
        get_filename_component(_library "${_library}" NAME_WE)
        find_library(_library_path NAMES ${_library}
            HINTS ${${_pc_xprefix}_LIBDIR} ${${_pc_xprefix}_LIBRARY_DIRS} )
        if (_library_path)
            list(APPEND ${_prefix}_LIBRARIES ${_library_path})
        else()
            message(FATAL_ERROR "Dependency of ${_prefix} '${_library}' NOT FOUND")
        endif()
        unset(_library_path CACHE)
    endforeach()
endmacro()

pkg_check_modules(PC_CHAMELEON chameleon)

find_path(CHAMELEON_STATIC_INCLUDE_DIRS NAMES morse.h 
              HINTS ${PC_CHAMELEON_STATIC_INCLUDEDIR} ${PC_CHAMELEON_STATIC_INCLUDE_DIRS} )
set(CHAMELEON_STATIC_DEFINITIONS ${PC_CHAMELEON_STATIC_CFLAGS_OTHER} )
find_libraries_from_pkgconfig_results(CHAMELEON_STATIC PC_CHAMELEON_STATIC)

find_path(CHAMELEON_INCLUDE_DIRS NAMES morse.h 
              HINTS ${PC_CHAMELEON_INCLUDEDIR} ${PC_CHAMELEON_INCLUDE_DIRS} )
set(CHAMELEON_DEFINITIONS ${PC_CHAMELEON_CFLAGS_OTHER} )
find_libraries_from_pkgconfig_results(CHAMELEON PC_CHAMELEON)

find_package_handle_standard_args(CHAMELEON DEFAULT_MSG CHAMELEON_LIBRARIES CHAMELEON_INCLUDE_DIRS)

The macro loop over the results from pkg-config and call cmake find_library() command, and eventually append the results into the CHAMELEON_LIBRARIES variable

What do you think about this? @fpruvost

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking