Add config profiles to libspark
This is part of a larger effort to unify the libspark build, and eliminate compile time differences between the builds used by our various services
This commit is contained in:
1 parent
99da1d3dc3
commit
afad713f4e
4 files changed
+70
No files matched your search
@@ -246,6 +246,7 @@
|
||||
"CMAKE_CXX_FLAGS_RELEASE": "-fPIC -Wall -pedantic -Wextra -Werror -Wno-missing-braces -Wno-ignored-qualifiers --std=c++20 -fdiagnostics-color -fno-omit-frame-pointer -DNDEBUG -O3",
|
||||
"CMAKE_INSTALL_PREFIX": "${sourceDir}/install/${presetName}",
|
||||
"CONFIG_DEFAULTS_PATH": "config/profiles/default/*.conf;config/profiles/data_stream/*.conf",
|
||||
"CONFIG_PROFILES": "default;data_stream",
|
||||
"DOTNET_BINARY_DIR": "${sourceDir}/build/$<CONFIG>/bin/net7.0;${sourceDir}/build/$<CONFIG>/bin/net8.0",
|
||||
"EXPORT_MD_CONSUMER": {
|
||||
"type": "BOOL",
|
||||
|
||||
@@ -4,6 +4,7 @@ set(CMAKE_SHARED_LIBRARY_PREFIX "")
|
||||
include(${CMAKE_SOURCE_DIR}/cmake/safe_dep_glob.cmake)
|
||||
include(${CMAKE_SOURCE_DIR}/cmake/Protobuf.cmake)
|
||||
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/GenerateDefaultConfig.cmake)
|
||||
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/GenerateConfigProfile.cmake)
|
||||
include(${CMAKE_SOURCE_DIR}/cmake/PrintList.cmake)
|
||||
|
||||
if (DEFINED DOTNET_BINARY_DIR OR DEFINED DOTNET_WINDOWS_BINARY_DIR)
|
||||
@@ -45,6 +46,10 @@ protobuf_generate_cpp(_proto_srcs _proto_hdrs ${_non_cfg_protos} ${_cfg_protos})
|
||||
service_compiler_generate_cpp(SERVICE_COMPILER_SRCS SERVICE_COMPILER_HDRS ${_service_protos})
|
||||
message(STATUS "Generating default config")
|
||||
generate_default_config(_cfg_protos _cfg_defaults)
|
||||
foreach(profile ${CONFIG_PROFILES})
|
||||
message(STATUS "Generating config profile ${profile}")
|
||||
generate_config_profile(${profile} _cfg_protos)
|
||||
endforeach()
|
||||
|
||||
add_library(${PROJECT_NAME} SHARED ${${PROJECT_NAME}_Sources} ${_proto_srcs} ${SERVICE_COMPILER_SRCS})
|
||||
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
function(generate_config_profile profile_dir cfg_protos)
|
||||
# Glob .conf files in profile dir (they define config defaults for this profile)
|
||||
file(
|
||||
GLOB_RECURSE _cfg_profile_defaults
|
||||
RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
config/profiles/${profile_dir}/*.conf)
|
||||
|
||||
# generate list of config protos
|
||||
set(_cfg_proto_file ${CMAKE_CURRENT_BINARY_DIR}/config_proto_files.h)
|
||||
|
||||
# generate a string with the current config files
|
||||
set(_cfg_proto_str "const char * config_proto_files[] = { // generated file\n")
|
||||
|
||||
foreach(_proto_path ${${cfg_protos}})
|
||||
get_filename_component(_proto_name ${_proto_path} NAME)
|
||||
string(APPEND _cfg_proto_str "\"${_proto_name}\",\n")
|
||||
endforeach(_proto_path)
|
||||
|
||||
string(APPEND _cfg_proto_str "} ;\n")
|
||||
|
||||
# compare with file and if there is any difference update the file
|
||||
set(_old_cfg_proto_str "")
|
||||
|
||||
if(EXISTS "${_cfg_proto_file}")
|
||||
file(READ "${_cfg_proto_file}" _old_cfg_proto_str)
|
||||
endif()
|
||||
|
||||
if(NOT _old_cfg_proto_str STREQUAL _cfg_proto_str)
|
||||
file(WRITE "${_cfg_proto_file}" "${_cfg_proto_str}")
|
||||
endif()
|
||||
|
||||
# generate static defaults
|
||||
set(_cfg_defaults_file ${CMAKE_CURRENT_BINARY_DIR}/config/profiles/${profile_dir}/config_defaults.h)
|
||||
|
||||
# Defaults cannot be a single string because the compiler complains about a
|
||||
# string longer than 65k
|
||||
set(_cfg_defaults_str "const char * config_static_defaults[] = { ")
|
||||
|
||||
foreach(_cfg_file_path ${_cfg_profile_defaults})
|
||||
file(READ ${_cfg_file_path} _cfg_file_content)
|
||||
string(REPLACE "\"" "\\\"" _cfg_file_content_escaped ${_cfg_file_content})
|
||||
string(REPLACE "\n" ";" _cfg_lines ${_cfg_file_content_escaped})
|
||||
|
||||
foreach(_line ${_cfg_lines})
|
||||
string(APPEND _cfg_defaults_str "\n \"${_line}\",")
|
||||
endforeach(_line)
|
||||
endforeach(_cfg_file_path)
|
||||
|
||||
string(APPEND _cfg_defaults_str "};")
|
||||
set(_old_cfg_defaults_str "")
|
||||
|
||||
if(EXISTS ${_cfg_defaults_file})
|
||||
file(READ ${_cfg_defaults_file} _old_cfg_defaults_str)
|
||||
endif()
|
||||
|
||||
if(NOT _cfg_defaults_str STREQUAL _old_cfg_defaults_str)
|
||||
file(WRITE "${_cfg_defaults_file}" "${_cfg_defaults_str}")
|
||||
endif()
|
||||
endfunction()
|
||||
@@ -0,0 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#ifndef CONFIG_PROFILE
|
||||
#define CONFIG_PROFILE "${BTS_SPARK_CONFIG_PROFILE}"
|
||||
#endif
|
||||
Reference in new issue
Block a user