Commit b57ae65a authored by Ramon Nou's avatar Ramon Nou
Browse files

Merge branch '8-use-file_options-and-genopts-to-define-the-configuration-file' into 'main'

Resolve "Use `file_options` and `genopts` to define the configuration file"

Closes #8

See merge request !6
parents ce59dff1 f8293058
Loading
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
# Compilation of scord and execution of tests

image: gekkofs/scord:0.1.0
image: bscstorage/scord:0.1.0

stages:
  - build
@@ -39,4 +39,3 @@ test:
    - pkill -9 scord
  cache:
    key: $CI_COMMIT_REF_SLUG
      
+58 −37
Original line number Diff line number Diff line
@@ -137,10 +137,6 @@ find_package(PkgConfig REQUIRED)
message(STATUS "[${PROJECT_NAME}] Checking for boost libraries")
find_package(Boost 1.53 REQUIRED COMPONENTS program_options)

### yaml-cpp: required for reading configuration files
message(STATUS "[${PROJECT_NAME}] Checking for yaml-cpp")
find_package(YAMLCpp 0.6.2 REQUIRED)

### transport library
if (SCORD_TRANSPORT_LIBRARY STREQUAL libfabric)
  pkg_check_modules(libfabric REQUIRED IMPORTED_TARGET GLOBAL libfabric)
@@ -188,6 +184,31 @@ FetchContent_Declare(

FetchContent_MakeAvailable(spdlog)

### file_options: required for reading configuration files
message(STATUS "[${PROJECT_NAME}] Downloading and building file_options")
FetchContent_Declare(
  file_options
  GIT_REPOSITORY https://storage.bsc.es/gitlab/utils/file_options
  GIT_TAG b2de92b3755e3391595bb368573b82abed16978d # v0.1.0-pre
  GIT_SHALLOW ON
  GIT_PROGRESS ON
)

FetchContent_MakeAvailable(file_options)

### genopts: required for generating file_options schemas
message(STATUS "[${PROJECT_NAME}] Downloading and building genopts")
FetchContent_Declare(
  genopts
  GIT_REPOSITORY https://storage.bsc.es/gitlab/utils/genopts
  GIT_TAG 1dcef400f8fbc6e1969c856ca844707b730c3002 # v0.1.0-pre
  GIT_SHALLOW ON
  GIT_PROGRESS ON
)

FetchContent_MakeAvailable(genopts)


### Mark any CMake variables imported from {fmt} and spdlog as advanced, so
### that they don't appear in cmake-gui or ccmake. Similarly for FETCHCONTENT
### variables.
+1 −10
Original line number Diff line number Diff line
/******************************************************************************
 * Copyright 2021, Barcelona Supercomputing Center (BSC), Spain
 * Copyright 2021-2022, Barcelona Supercomputing Center (BSC), Spain
 *
 * This software was partially supported by the EuroHPC-funded project ADMIRE
 *   (Project ID: 956748, https://www.admire-eurohpc.eu).
@@ -21,12 +21,3 @@
 *
 * SPDX-License-Identifier: GPL-3.0-or-later
 *****************************************************************************/

#ifndef SCORD_CONFIG_FILE_OPTIONS_HPP
#define SCORD_CONFIG_FILE_OPTIONS_HPP

#include "schema.hpp"
#include "options_description.hpp"
#include "yaml_parser.hpp"

#endif /* SCORD_CONFIG_FILE_OPTIONS_HPP */
+21 −19
Original line number Diff line number Diff line
@@ -28,7 +28,9 @@ RUN apt-get update && \
        libboost-program-options-dev \
        uuid-dev  \
        python3 \
        libyaml-dev libcurl4-openssl-dev procps && \
        libyaml-dev libcurl4-openssl-dev procps \
        # genopts dependencies
        python3-venv && \
    # install cmake 3.14 since it's needed for some dependencies
    curl -OL https://github.com/Kitware/CMake/releases/download/v3.23.1/cmake-3.23.1-Linux-x86_64.sh && \
    chmod u+x ./cmake-3.23.1-Linux-x86_64.sh && \
+45 −9
Original line number Diff line number Diff line
@@ -22,30 +22,66 @@
# SPDX-License-Identifier: GPL-3.0-or-later                                    #
################################################################################

# Create a config target for all configuration code
add_library(config STATIC)

# Since some of the sources will be auto-generated, we need to search for
# includes in ${CMAKE_CURRENT_BINARY_DIR}
target_include_directories(
  config PRIVATE ${CMAKE_SOURCE_DIR}/src ${CMAKE_CURRENT_SOURCE_DIR}
                 ${CMAKE_CURRENT_BINARY_DIR}
)
set_property(TARGET config PROPERTY POSITION_INDEPENDENT_CODE ON)

configure_file(defaults.cpp.in defaults.cpp)

target_sources(
  config
  PRIVATE config.hpp
        config_schema.hpp
          defaults.hpp
          ${CMAKE_CURRENT_BINARY_DIR}/defaults.cpp
        file_options/file_options.hpp
        file_options/schema.hpp
        file_options/options_description.hpp
        file_options/yaml_parser.hpp
          keywords.hpp
          ${CMAKE_CURRENT_BINARY_DIR}/config_options.hpp
          ${CMAKE_CURRENT_BINARY_DIR}/keywords.hpp
          parsers.cpp
          parsers.hpp
          settings.cpp
          settings.hpp
)

target_link_libraries(config PRIVATE utils YAMLCpp::YAMLCpp)
target_link_libraries(config PRIVATE utils file_options::file_options)

# ##############################################################################
# Produce several auto-generated files for 'config'
# ##############################################################################

# Default values for options
configure_file(defaults.cpp.in defaults.cpp)

# Automatic generation of file_options schemas. To facilitate the management of
# any file-based configuration options, we generate a C++ schema from a YAML
# file that allows the 'file_options' library to parse them fromm a
# configuration file. The process works as follows:
#  1. We define the desired options in 'file_options.yml'
#  2. We rely on the 'genopts' tool to generate valid C++ schemas for the
#     'file_options' library. This tool can be configured using a 'genopts.yml'
#     configuration file.
#  3. In the daemon code, we use the facilities provided by the 'file_options'
#     library to access the options values.

# Since the configuration in genopts.yml can be path-dependant, we rely on
# CMake to substitute any special @variables@ for their actual values
configure_file(genopts.yml.in genopts.yml @ONLY)

# Define the command that will generate config_options.hpp and keywords.hpp.
# It will be executed since there is a direct dependency between 'config'
# (defined below) and these output files.
# We also make the command depend on file_options.yml and genopts.yml so that
# it gets re-executed if they change.
add_custom_command(
  OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/config_options.hpp
         ${CMAKE_CURRENT_BINARY_DIR}/keywords.hpp
  COMMENT "Generating config_options.hpp, keywords.hpp"
  DEPENDS file_options.yml ${CMAKE_CURRENT_BINARY_DIR}/genopts.yml
  COMMAND
    Genopts::Python3_Interpreter -m genopts --config
    ${CMAKE_CURRENT_BINARY_DIR}/genopts.yml
    ${CMAKE_CURRENT_LIST_DIR}/file_options.yml
)
Loading