GenPkgConfig.cmake 7.36 KB
Newer Older
1 2 3 4 5
###
#
# @copyright (c) 2009-2014 The University of Tennessee and The University
#                          of Tennessee Research Foundation.
#                          All rights reserved.
PRUVOST Florent's avatar
PRUVOST Florent committed
6
# @copyright (c) 2012-2017 Inria. All rights reserved.
7 8 9 10 11 12 13 14 15 16 17 18
# @copyright (c) 2012-2014 Bordeaux INP, CNRS (LaBRI UMR 5800), Inria, Univ. Bordeaux. All rights reserved.
#
###
#
#  @file GenPkgConfig.cmake
#
#  @project MORSE
#  MORSE is a software package provided by:
#     Inria Bordeaux - Sud-Ouest,
#     Univ. of Tennessee,
#     King Abdullah Univesity of Science and Technology
#     Univ. of California Berkeley,
19
#     Univ. of Colorado Denver.
20
#
PRUVOST Florent's avatar
PRUVOST Florent committed
21
#  @version 0.9.1
22 23 24 25 26 27 28 29 30 31
#  @author Cedric Castagnede
#  @author Emmanuel Agullo
#  @author Mathieu Faverge
#  @author Florent Pruvost
#  @date 10-11-2014
#
###

###
#
PRUVOST Florent's avatar
PRUVOST Florent committed
32 33
# CONVERT_LIBSTYLE_TO_PKGCONFIG: convert a libraries list to follow the pkg-config style
#                                used in CLEAN_LIB_LIST
34 35
#
###
PRUVOST Florent's avatar
PRUVOST Florent committed
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
MACRO(CONVERT_LIBSTYLE_TO_PKGCONFIG _liblist)
    set(${_liblist}_CPY "${${_liblist}}")
    set(${_liblist} "")
    foreach(_dep ${${_liblist}_CPY})
        if (${_dep} MATCHES "^/")
            get_filename_component(dep_libname ${_dep} NAME)
            get_filename_component(dep_libdir  ${_dep} DIRECTORY)
            STRING(REPLACE "lib"    "" dep_libname "${dep_libname}")
            STRING(REPLACE ".so"    "" dep_libname "${dep_libname}")
            STRING(REPLACE ".a"     "" dep_libname "${dep_libname}")
            STRING(REPLACE ".dylib" "" dep_libname "${dep_libname}")
            STRING(REPLACE ".dll"   "" dep_libname "${dep_libname}")
            list(APPEND ${_liblist} -L${dep_libdir} -l${dep_libname})
        elseif(NOT ${_dep} MATCHES "^-")
            list(APPEND ${_liblist} "-l${_dep}")
        else()
            list(APPEND ${_liblist} ${_dep})
        endif()
    endforeach()
ENDMACRO(CONVERT_LIBSTYLE_TO_PKGCONFIG)

###
#
# CLEAN_LIB_LIST: clean libraries lists to follow the pkg-config style
60
#                 used in GENERATE_PKGCONFIG_FILE
PRUVOST Florent's avatar
PRUVOST Florent committed
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
#
###
MACRO(CLEAN_LIB_LIST _package)
    list(REMOVE_DUPLICATES ${_package}_PKGCONFIG_LIBS)
    list(REMOVE_DUPLICATES ${_package}_PKGCONFIG_LIBS_PRIVATE)
    list(REMOVE_DUPLICATES ${_package}_PKGCONFIG_REQUIRED)
    list(REMOVE_DUPLICATES ${_package}_PKGCONFIG_REQUIRED_PRIVATE)
    CONVERT_LIBSTYLE_TO_PKGCONFIG(${_package}_PKGCONFIG_LIBS)
    CONVERT_LIBSTYLE_TO_PKGCONFIG(${_package}_PKGCONFIG_LIBS_PRIVATE)
    STRING(REPLACE ";" " " ${_package}_PKGCONFIG_LIBS "${${_package}_PKGCONFIG_LIBS}")
    STRING(REPLACE ";" " " ${_package}_PKGCONFIG_LIBS_PRIVATE "${${_package}_PKGCONFIG_LIBS_PRIVATE}")
    STRING(REPLACE ";" " " ${_package}_PKGCONFIG_REQUIRED "${${_package}_PKGCONFIG_REQUIRED}")
    STRING(REPLACE ";" " " ${_package}_PKGCONFIG_REQUIRED_PRIVATE "${${_package}_PKGCONFIG_REQUIRED_PRIVATE}")
ENDMACRO(CLEAN_LIB_LIST)

###
#
# GENERATE_PKGCONFIG_FILE: generate files chameleon.pc, coreblas.pc and cudablas.pc
#
###
MACRO(GENERATE_PKGCONFIG_FILE)
82

83
    # The definitions
PRUVOST Florent's avatar
PRUVOST Florent committed
84 85 86
    
    # DEFINITIONS_LIST contains a cmake style list, e.g.: USE_FLAG1;USE_FLAG2;USE_FLAG3
    # transform the cmake list to get a correct definitions list for pkg-config
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
    string(REGEX REPLACE ";" " -D" CHAMELEON_PKGCONFIG_DEFINITIONS "${CHAMELEON_DEFINITIONS_LIST}")
    string(REGEX REPLACE ";" " -D" COREBLAS_PKGCONFIG_DEFINITIONS "${COREBLAS_DEFINITIONS_LIST}")
    string(REGEX REPLACE ";" " -D" CUDABLAS_PKGCONFIG_DEFINITIONS "${CUDABLAS_DEFINITIONS_LIST}")
    if (CHAMELEON_PKGCONFIG_DEFINITIONS)
      set(CHAMELEON_PKGCONFIG_DEFINITIONS "-D${CHAMELEON_PKGCONFIG_DEFINITIONS}")
    else()
      set(CHAMELEON_PKGCONFIG_DEFINITIONS "")
    endif()
    if (COREBLAS_PKGCONFIG_DEFINITIONS)
      set(COREBLAS_PKGCONFIG_DEFINITIONS  "-D${COREBLAS_PKGCONFIG_DEFINITIONS}")
    else()
      set(COREBLAS_PKGCONFIG_DEFINITIONS "")
    endif()
    if (CUDABLAS_PKGCONFIG_DEFINITIONS)
      set(CUDABLAS_PKGCONFIG_DEFINITIONS  "-D${CUDABLAS_PKGCONFIG_DEFINITIONS}")
    else()
      set(CUDABLAS_PKGCONFIG_DEFINITIONS "")
    endif()

106 107
    # The link flags specific to this package and any required libraries
    # that don't support PkgConfig
PRUVOST Florent's avatar
PRUVOST Florent committed
108 109 110 111
    set(CHAMELEON_PKGCONFIG_LIBS "-lchameleon")
    set(COREBLAS_PKGCONFIG_LIBS  "-lcoreblas")
    set(CUDABLAS_PKGCONFIG_LIBS  "-lcudablas")

112 113 114
    # The link flags for private libraries required by this package but not
    # exposed to applications
    set(CHAMELEON_PKGCONFIG_LIBS_PRIVATE "")
PRUVOST Florent's avatar
PRUVOST Florent committed
115 116 117
    set(COREBLAS_PKGCONFIG_LIBS_PRIVATE  "")
    set(CUDABLAS_PKGCONFIG_LIBS_PRIVATE  "")

118 119
    # A list of packages required by this package
    set(CHAMELEON_PKGCONFIG_REQUIRED "")
PRUVOST Florent's avatar
PRUVOST Florent committed
120 121
    set(COREBLAS_PKGCONFIG_REQUIRED  "")
    set(CUDABLAS_PKGCONFIG_REQUIRED  "")
122

123 124 125
    # A list of private packages required by this package but not exposed to
    # applications
    set(CHAMELEON_PKGCONFIG_REQUIRED_PRIVATE "")
PRUVOST Florent's avatar
PRUVOST Florent committed
126 127
    set(COREBLAS_PKGCONFIG_REQUIRED_PRIVATE  "")
    set(CUDABLAS_PKGCONFIG_REQUIRED_PRIVATE  "")
128 129 130 131

    if(CHAMELEON_SCHED_STARPU)
        list(APPEND CHAMELEON_PKGCONFIG_LIBS -lchameleon_starpu)
        if ( CHAMELEON_USE_MPI )
PRUVOST Florent's avatar
PRUVOST Florent committed
132
            list(APPEND CHAMELEON_PKGCONFIG_REQUIRED_PRIVATE libstarpumpi)
133
        else()
PRUVOST Florent's avatar
PRUVOST Florent committed
134
            list(APPEND CHAMELEON_PKGCONFIG_REQUIRED_PRIVATE libstarpu)
135 136 137
        endif()
    elseif(CHAMELEON_SCHED_QUARK)
        list(APPEND CHAMELEON_PKGCONFIG_LIBS -lchameleon_quark)
PRUVOST Florent's avatar
PRUVOST Florent committed
138
        list(APPEND CHAMELEON_PKGCONFIG_LIBS_PRIVATE "${QUARK_LIBRARIES_DEP}")
139 140 141 142
    endif()

    if(NOT CHAMELEON_SIMULATION)

PRUVOST Florent's avatar
PRUVOST Florent committed
143 144 145 146 147
        list(APPEND COREBLAS_PKGCONFIG_LIBS_PRIVATE
        ${LAPACKE_LIBRARIES_DEP}
        ${CBLAS_LIBRARIES_DEP}
        )
        list(APPEND CHAMELEON_PKGCONFIG_LIBS_PRIVATE
148 149
        ${EXTRA_LIBRARIES}
        )
PRUVOST Florent's avatar
PRUVOST Florent committed
150
        list(APPEND CHAMELEON_PKGCONFIG_REQUIRED "coreblas")
151

PRUVOST Florent's avatar
PRUVOST Florent committed
152 153 154 155
        if(CHAMELEON_USE_CUDA)
            list(APPEND CUDABLAS_PKGCONFIG_LIBS_PRIVATE ${CUDA_LIBRARIES})
            list(APPEND CHAMELEON_PKGCONFIG_REQUIRED "cudablas")
        endif()
156 157 158

    else(NOT CHAMELEON_SIMULATION)

PRUVOST Florent's avatar
PRUVOST Florent committed
159 160 161
        if(CHAMELEON_USE_CUDA)
            list(APPEND CHAMELEON_PKGCONFIG_LIBS -lcudablas)
        endif()
162
        list(APPEND CHAMELEON_PKGCONFIG_LIBS
163 164 165 166 167 168
        -lcoreblas
        ${EXTRA_LIBRARIES}
        )

    endif(NOT CHAMELEON_SIMULATION)

PRUVOST Florent's avatar
PRUVOST Florent committed
169 170
    list(APPEND CHAMELEON_PKGCONFIG_REQUIRED_PRIVATE hwloc)

171 172
    # Define required package
    # -----------------------
PRUVOST Florent's avatar
PRUVOST Florent committed
173 174 175 176 177
    CLEAN_LIB_LIST(CHAMELEON)
    CLEAN_LIB_LIST(COREBLAS)
    if(CHAMELEON_USE_CUDA)
        CLEAN_LIB_LIST(CUDABLAS)
    endif()
178

179 180
    # Create .pc file
    # ---------------
PRUVOST Florent's avatar
PRUVOST Florent committed
181 182 183 184 185 186
    SET(_output_chameleon_file "${CMAKE_BINARY_DIR}/chameleon.pc")
    SET(_output_coreblas_file "${CMAKE_BINARY_DIR}/coreblas.pc")
    if(CHAMELEON_USE_CUDA)
        SET(_output_cudablas_file "${CMAKE_BINARY_DIR}/cudablas.pc")
    endif()

187
    # TODO: add url of MORSE releases in .pc file
PRUVOST Florent's avatar
PRUVOST Florent committed
188 189 190 191 192
    CONFIGURE_FILE("${CMAKE_CURRENT_SOURCE_DIR}/lib/pkgconfig/chameleon.pc.in" "${_output_chameleon_file}" @ONLY)
    CONFIGURE_FILE("${CMAKE_CURRENT_SOURCE_DIR}/lib/pkgconfig/coreblas.pc.in"  "${_output_coreblas_file}" @ONLY)
    if(CHAMELEON_USE_CUDA)
        CONFIGURE_FILE("${CMAKE_CURRENT_SOURCE_DIR}/lib/pkgconfig/cudablas.pc.in"  "${_output_cudablas_file}" @ONLY)
    endif()
193 194 195

    # installation
    # ------------
PRUVOST Florent's avatar
PRUVOST Florent committed
196 197 198
    INSTALL(FILES ${_output_chameleon_file} DESTINATION lib/pkgconfig)
    INSTALL(FILES ${_output_coreblas_file}  DESTINATION lib/pkgconfig)
    INSTALL(FILES ${_output_cudablas_file}  DESTINATION lib/pkgconfig)
199 200 201 202 203 204

ENDMACRO(GENERATE_PKGCONFIG_FILE)

##
## @end file GenPkgConfig.cmake
##