simplify CMake file

This commit is contained in:
gmega 2026-02-27 13:47:04 -03:00
parent fdbc5b5dc0
commit 2f82f37246
No known key found for this signature in database
GPG Key ID: 6290D34EAD824B18

View File

@ -8,98 +8,17 @@ set(CMAKE_INCLUDE_CURRENT_DIR ON)
########### DEPENDENCIES ###########
# This section locates the required dependencies in 3 different ways:
# 1- With NIX, the root folders (LOGOS_LIBLOGOS_ROOT, LOGOS_CPP_SDK_ROOT,
# and LOGOS_STORAGE_ROOT) are defined and point to the correct locations in
# the Nix store.
# 2- If the root folders are fetched from source (basically using git) in the
# parent folder, this is detected and used.
# 3- If none of the above apply, the vendor folders inside this project are used,
# meaning the dependencies need to be fetched using git submodules.
if(NOT DEFINED LOGOS_LIBLOGOS_ROOT)
set(_parent_liblogos "${CMAKE_SOURCE_DIR}/../../logos-liblogos")
set(_use_vendor ${LOGOS_STORAGE_CLI_USE_VENDOR})
if(NOT _use_vendor)
if(NOT EXISTS "${_parent_liblogos}/src/common/interface.h")
set(_use_vendor ON)
endif()
endif()
if(_use_vendor)
set(LOGOS_LIBLOGOS_ROOT "${CMAKE_SOURCE_DIR}/../vendor/logos-liblogos")
else()
set(LOGOS_LIBLOGOS_ROOT "${_parent_liblogos}")
endif()
endif()
if(NOT DEFINED LOGOS_CPP_SDK_ROOT)
set(_parent_cpp_sdk "${CMAKE_SOURCE_DIR}/../../logos-cpp-sdk")
set(_use_vendor ${LOGOS_STORAGE_CLI_USE_VENDOR})
if(NOT _use_vendor)
if(NOT EXISTS "${_parent_cpp_sdk}/cpp/logos_api.h")
set(_use_vendor ON)
endif()
endif()
if(_use_vendor)
set(LOGOS_CPP_SDK_ROOT "${CMAKE_SOURCE_DIR}/../vendor/logos-cpp-sdk")
else()
set(LOGOS_CPP_SDK_ROOT "${_parent_cpp_sdk}")
endif()
endif()
if(NOT DEFINED LOGOS_STORAGE_ROOT)
set(_parent_storage_module "${CMAKE_SOURCE_DIR}/../../logos-storage-module")
set(_use_vendor ${LOGOS_STORAGE_CLI_USE_VENDOR})
if(NOT _use_vendor)
if(NOT EXISTS "${_parent_storage_module}/storage_module_plugin.h")
set(_use_vendor ON)
endif()
endif()
if(_use_vendor)
set(LOGOS_STORAGE_ROOT "${CMAKE_SOURCE_DIR}/../vendor/logos-storage-module")
else()
set(LOGOS_STORAGE_ROOT "${_parent_storage_module}")
endif()
endif()
set(_liblogos_found FALSE)
if(EXISTS "${LOGOS_LIBLOGOS_ROOT}/src/common/interface.h")
set(_liblogos_found TRUE)
set(_liblogos_is_source TRUE)
elseif(EXISTS "${LOGOS_LIBLOGOS_ROOT}/include/interface.h")
set(_liblogos_found TRUE)
set(_liblogos_is_source FALSE)
endif()
set(_cpp_sdk_found FALSE)
if(EXISTS "${LOGOS_CPP_SDK_ROOT}/cpp/logos_api.h")
set(_cpp_sdk_found TRUE)
set(_cpp_sdk_is_source TRUE)
elseif(EXISTS "${LOGOS_CPP_SDK_ROOT}/include/cpp/logos_api.h")
set(_cpp_sdk_found TRUE)
set(_cpp_sdk_is_source FALSE)
endif()
set(_storage_module_found FALSE)
if(EXISTS "${LOGOS_STORAGE_ROOT}/storage_module_plugin.h")
set(_storage_module_found TRUE)
set(_storage_module_is_source TRUE)
elseif(EXISTS "${LOGOS_STORAGE_ROOT}/include/storage_module_api.h")
set(_storage_module_found TRUE)
set(_storage_module_is_source FALSE)
endif()
if(NOT _liblogos_found)
if(NOT EXISTS "${LOGOS_LIBLOGOS_ROOT}/include/interface.h")
message(FATAL_ERROR "logos-liblogos not found at ${LOGOS_LIBLOGOS_ROOT}. "
"Set LOGOS_LIBLOGOS_ROOT or run git submodule update --init --recursive.")
endif()
if(NOT _cpp_sdk_found)
if(NOT EXISTS "${LOGOS_CPP_SDK_ROOT}/include/cpp/logos_api.h")
message(FATAL_ERROR "logos-cpp-sdk not found at ${LOGOS_CPP_SDK_ROOT}. "
"Set LOGOS_CPP_SDK_ROOT or run git submodule update --init --recursive.")
endif()
if(NOT _storage_module_found)
if(NOT EXISTS "${LOGOS_STORAGE_ROOT}/include/storage_module_api.h")
message(FATAL_ERROR "logos-storage-module not found at ${LOGOS_STORAGE_ROOT}. "
"Set LOGOS_STORAGE_ROOT or run git submodule update --init --recursive.")
endif()
@ -110,141 +29,14 @@ message(STATUS "Using logos-storage-module at: ${LOGOS_STORAGE_ROOT}")
########### DEPENDENCIES END ###########
########### SOURCES ###########
# Sources
set(COMMON_SOURCES
logos_manager.cpp
logos_manager.h
)
# Add SDK sources (only if source layout, installed layout uses the library)
if(_cpp_sdk_is_source)
list(APPEND COMMON_SOURCES
${LOGOS_CPP_SDK_ROOT}/cpp/logos_api.cpp
${LOGOS_CPP_SDK_ROOT}/cpp/logos_api.h
${LOGOS_CPP_SDK_ROOT}/cpp/logos_api_client.cpp
${LOGOS_CPP_SDK_ROOT}/cpp/logos_api_client.h
${LOGOS_CPP_SDK_ROOT}/cpp/logos_api_consumer.cpp
${LOGOS_CPP_SDK_ROOT}/cpp/logos_api_consumer.h
${LOGOS_CPP_SDK_ROOT}/cpp/logos_api_provider.cpp
${LOGOS_CPP_SDK_ROOT}/cpp/logos_api_provider.h
${LOGOS_CPP_SDK_ROOT}/cpp/token_manager.cpp
${LOGOS_CPP_SDK_ROOT}/cpp/token_manager.h
${LOGOS_CPP_SDK_ROOT}/cpp/module_proxy.cpp
${LOGOS_CPP_SDK_ROOT}/cpp/module_proxy.h
${LOGOS_CPP_SDK_ROOT}/cpp/logos_types.cpp
${LOGOS_CPP_SDK_ROOT}/cpp/logos_types.h
)
endif()
########### SOURCES END ###########
########### CPP GENERATOR ###########
# Define metadata json path
set(METADATA_JSON "${CMAKE_CURRENT_SOURCE_DIR}/metadata.json")
# Run the cpp generator for the storage module (produces storage_module_api.h/cpp).
# Only for source layout - nix builds already have pre-generated files.
if(_storage_module_is_source)
set(PLUGINS_OUTPUT_DIR "${CMAKE_BINARY_DIR}/generated_code")
set(CPP_GENERATOR_BUILD_DIR "${LOGOS_CPP_SDK_ROOT}/../build/cpp-generator")
set(CPP_GENERATOR "${CPP_GENERATOR_BUILD_DIR}/bin/logos-cpp-generator")
if(NOT TARGET cpp_generator_build)
add_custom_target(cpp_generator_build
COMMAND bash "${LOGOS_CPP_SDK_ROOT}/cpp-generator/compile.sh"
WORKING_DIRECTORY "${LOGOS_CPP_SDK_ROOT}/.."
COMMENT "Building logos-cpp-generator via ${LOGOS_CPP_SDK_ROOT}/cpp-generator/compile.sh"
VERBATIM
)
endif()
add_custom_target(run_build_storage_module
COMMAND "${CMAKE_COMMAND}" -S "${LOGOS_STORAGE_ROOT}" -B "${LOGOS_STORAGE_ROOT}/build"
COMMAND "${CMAKE_COMMAND}" --build "${LOGOS_STORAGE_ROOT}/build" --target all
WORKING_DIRECTORY "${LOGOS_STORAGE_ROOT}/.."
COMMENT "Building storage module in ${LOGOS_STORAGE_ROOT}/build"
VERBATIM
)
if(APPLE)
set(PLUGIN_FILE "${LOGOS_STORAGE_ROOT}/build/modules/storage_module_plugin.dylib")
elseif(UNIX)
set(PLUGIN_FILE "${LOGOS_STORAGE_ROOT}/build/modules/storage_module_plugin.so")
else()
message(FATAL_ERROR "storage_module_plugin is not found.")
endif()
add_custom_target(run_cpp_generator_storage_module
COMMAND ${CMAKE_COMMAND} -E make_directory "${PLUGINS_OUTPUT_DIR}"
COMMAND "${CPP_GENERATOR}" "${PLUGIN_FILE}" --interface "${LOGOS_STORAGE_ROOT}/storage_module_interface.h" --module-only --output-dir "${PLUGINS_OUTPUT_DIR}"
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
COMMENT "Running logos-cpp-generator on ${PLUGIN_FILE} with output-dir ${PLUGINS_OUTPUT_DIR}"
VERBATIM
)
add_dependencies(run_cpp_generator_storage_module cpp_generator_build)
add_dependencies(run_cpp_generator_storage_module run_build_storage_module)
endif()
# Generate logos_sdk.cpp via --general-only --metadata.
# This file #includes all module APIs (storage_module_api.cpp etc.) based on
# the dependencies declared in metadata.json.
# storage_module_api.cpp is NOT added directly to SOURCES to avoid AUTOMOC issues
# with files that don't exist at configure time.
if(_cpp_sdk_is_source)
if(NOT DEFINED PLUGINS_OUTPUT_DIR)
set(PLUGINS_OUTPUT_DIR "${CMAKE_BINARY_DIR}/generated_code")
endif()
if(NOT DEFINED CPP_GENERATOR_BUILD_DIR)
set(CPP_GENERATOR_BUILD_DIR "${LOGOS_CPP_SDK_ROOT}/../build/cpp-generator")
endif()
if(NOT DEFINED CPP_GENERATOR)
set(CPP_GENERATOR "${CPP_GENERATOR_BUILD_DIR}/bin/logos-cpp-generator")
endif()
if(NOT TARGET cpp_generator_build)
add_custom_target(cpp_generator_build
COMMAND bash "${LOGOS_CPP_SDK_ROOT}/cpp-generator/compile.sh"
WORKING_DIRECTORY "${LOGOS_CPP_SDK_ROOT}/.."
COMMENT "Building logos-cpp-generator via ${LOGOS_CPP_SDK_ROOT}/cpp-generator/compile.sh"
VERBATIM
)
endif()
add_custom_command(
OUTPUT "${PLUGINS_OUTPUT_DIR}/logos_sdk.cpp"
COMMAND ${CMAKE_COMMAND} -E make_directory "${PLUGINS_OUTPUT_DIR}"
COMMAND "${CPP_GENERATOR}" --metadata "${METADATA_JSON}" --general-only --output-dir "${PLUGINS_OUTPUT_DIR}"
WORKING_DIRECTORY "${LOGOS_CPP_SDK_ROOT}/.."
DEPENDS "${METADATA_JSON}" cpp_generator_build
VERBATIM
)
add_custom_target(run_cpp_generator_logos_cli DEPENDS "${PLUGINS_OUTPUT_DIR}/logos_sdk.cpp")
if(_storage_module_is_source)
add_dependencies(run_cpp_generator_logos_cli run_cpp_generator_storage_module)
endif()
list(APPEND COMMON_SOURCES ${PLUGINS_OUTPUT_DIR}/logos_sdk.cpp)
# Mark as generated so CMake knows to wait for it
set_source_files_properties(
${PLUGINS_OUTPUT_DIR}/logos_sdk.cpp
PROPERTIES GENERATED TRUE
)
else()
# For installed/nix layout, logos_sdk.cpp is already pre-generated
set(PLUGINS_OUTPUT_DIR "${CMAKE_SOURCE_DIR}/generated_code")
list(APPEND COMMON_SOURCES ${PLUGINS_OUTPUT_DIR}/logos_sdk.cpp)
endif()
########### CPP GENERATOR END ###########
# CPP Generator
set(PLUGINS_OUTPUT_DIR "${CMAKE_SOURCE_DIR}/generated_code")
list(APPEND COMMON_SOURCES ${PLUGINS_OUTPUT_DIR}/logos_sdk.cpp)
########### APP DEFINITION ###########
@ -252,29 +44,23 @@ endif()
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core RemoteObjects)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core RemoteObjects)
# Link directories
link_directories(
${LOGOS_LIBLOGOS_ROOT}/lib
${LOGOS_CPP_SDK_ROOT}/lib
)
# Set output directories
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
# Shared library target holding common sources, includes, and link libraries
add_library(logos-common STATIC ${COMMON_SOURCES})
find_library(LOGOS_CORE_LIB logos_core PATHS ${LOGOS_LIBLOGOS_ROOT}/lib NO_DEFAULT_PATH REQUIRED)
target_link_libraries(logos-common PUBLIC
Qt${QT_VERSION_MAJOR}::Core
Qt${QT_VERSION_MAJOR}::RemoteObjects
logos_core
${LOGOS_CORE_LIB}
)
# Link SDK library if using installed layout (source layout compiles the SDK directly)
if(NOT _cpp_sdk_is_source)
find_library(LOGOS_SDK_LIB logos_sdk PATHS ${LOGOS_CPP_SDK_ROOT}/lib NO_DEFAULT_PATH REQUIRED)
target_link_libraries(logos-common PUBLIC ${LOGOS_SDK_LIB})
endif()
find_library(LOGOS_SDK_LIB logos_sdk PATHS ${LOGOS_CPP_SDK_ROOT}/lib NO_DEFAULT_PATH REQUIRED)
target_link_libraries(logos-common PUBLIC ${LOGOS_SDK_LIB})
# Create executables
add_executable(logos-uploader uploader.cpp)
@ -294,39 +80,13 @@ target_include_directories(logos-common PUBLIC
${PLUGINS_OUTPUT_DIR}
)
if(_liblogos_is_source)
target_include_directories(logos-common PUBLIC ${LOGOS_LIBLOGOS_ROOT})
else()
target_include_directories(logos-common PUBLIC ${LOGOS_LIBLOGOS_ROOT}/include)
endif()
if(_cpp_sdk_is_source)
target_include_directories(logos-common PUBLIC
${LOGOS_CPP_SDK_ROOT}/cpp
${LOGOS_CPP_SDK_ROOT}/cpp/generated
)
else()
target_include_directories(logos-common PUBLIC
${LOGOS_CPP_SDK_ROOT}/include
${LOGOS_CPP_SDK_ROOT}/include/cpp
${LOGOS_CPP_SDK_ROOT}/include/core
${PLUGINS_OUTPUT_DIR}/include
)
endif()
########### HEADERS END ###########
########### GENERATOR DEPENDENCY ###########
if(_cpp_sdk_is_source)
add_dependencies(logos-common run_cpp_generator_logos_cli)
endif()
if(_storage_module_is_source)
add_dependencies(logos-common run_cpp_generator_storage_module)
endif()
########### GENERATOR DEPENDENCY END ###########
target_include_directories(logos-common PUBLIC ${LOGOS_LIBLOGOS_ROOT}/include)
target_include_directories(logos-common PUBLIC
${LOGOS_CPP_SDK_ROOT}/include
${LOGOS_CPP_SDK_ROOT}/include/cpp
${LOGOS_CPP_SDK_ROOT}/include/core
${PLUGINS_OUTPUT_DIR}/include
)
########### LOGOS DEPENDENCIES LIBRARIES ###########