Skip to content

Proposal to divide the stdlib CMake project in multiple libraries #1031

@eduardz1

Description

@eduardz1

Motivation

Currently, the stdlib exports a single CMake target, this means that to use even a single feature one has to compile the entire standard library. This is particularly problematic for cases where compiler support is lacking such as #107.

In the software I am currently working on, https://ffaucher.gitlab.io/hawen-website/ (note that the public source code is not up-to-date), I would consider proposing the usage of the stdlib but compiler limitations currently make it non-feasible.

The solution would be to export a library for each module, so I believe it could be solved with something like

# src/CMakeLists.txt

add_library(stdlib_io ${IO_SOURCES})
add_library(stdlib_array ${ARRAY_SOURCES})
# ...

add_library(${PROJECT_NAME} INTERFACE)
target_link_libraries(${PROJECT_NAME} INTERFACE 
    stdlib_io 
    stdlib_array
    # ...
)

install(TARGETS 
    ${PROJECT_NAME}
    stdlib_io
    stdlib_array
    # ...
    EXPORT ${PROJECT_NAME}-targets
    LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
    ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
    PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)

So that in our application we could, for example, only link fortran_stdlib::stdlib_io (whilst still keeping the fortran_stdlib::fortran_stdlib target available) and therefore limit the compatibility issues across different compilers (and potential points of failure in general).

This is not super straight forward to implement as dependencies will have to be managed individually (for example I see that stdlib_ansi will depend on stdlib_kinds and stdlib_string_type and will also make the CMakeLists.txt file under src quite verbose.

I would be willing to try to implement this if I find agreement in the proposal

Prior Art

No response

Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    ideaProposition of an idea and opening an issue to discuss it

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions