Skip to content

CMake installs under unexpected package name #579

Open
@EmilyBourne

Description

@EmilyBourne

According to the README json-fortran can be used in a CMake project by linking the library jsonfortran::jsonfortran or jsonfortran::jsonfortran-static:

target_link_libraries ( ${TEST} jsonfortran::jsonfortran-static )

However the installation means that a different name library name is used for every installation. This comes from here:

json-fortran/CMakeLists.txt

Lines 111 to 114 in cde2620

# Set the package name to be specific to the compiler used, so that
# versions compiled with different compilers can be installed in parallel
string ( TOLOWER ${PROJECT_NAME}-${CMAKE_Fortran_COMPILER_ID} PACKAGE_NAME )
set ( PACKAGE_VERSION "${PACKAGE_NAME}-${PROJECT_VERSION}" )

The library names are therefore actually more like: jsonfortran-nvhpc::jsonfortran. This is particularly cumbersome as the compiler id in CMake is uppercase but the library uses lowercase.

As a workaround it is possible to use the documented name by doing:

# Get compiler dependent name
string(TOLOWER "jsonfortran-${CMAKE_Fortran_COMPILER_ID}" jsonlibname)
# Create alias
add_library(jsonfortran::jsonfortran ALIAS ${jsonlibname}::jsonfortran)

however it would be simpler if jsonfortran simply installed itself with the documented name

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions