diff --git a/.gitignore b/.gitignore index 241838c..a0c3471 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,6 @@ **/build-*/ **/cmake-build-*/ Testing + +# Auto generated files +/include/scale/definitions.hpp \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 4f5c022..4ef9de1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,9 +6,9 @@ cmake_minimum_required(VERSION 3.12) -if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.27") +if (${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.27") cmake_policy(SET CMP0144 NEW) -endif() +endif () include(${CMAKE_CURRENT_LIST_DIR}/cmake/HunterGate.cmake) @@ -36,11 +36,21 @@ find_package(Boost CONFIG REQUIRED) hunter_add_package(qtils) find_package(qtils CONFIG REQUIRED) -if (JAM_COMPATIBLE) - add_compile_definitions(JAM_COMPATIBILITY_ENABLED) -endif () -if (CUSTOM_CONFIG_SUPPORT) - add_compile_definitions(CUSTOM_CONFIG_ENABLED) +set(DEFINITION_PATH "${CMAKE_CURRENT_SOURCE_DIR}/include/scale/definitions.hpp") +if (NOT EXISTS "${CMAKE_BINARY_DIR}/definition.d" OR NOT EXISTS "${DEFINITION_PATH}") + get_filename_component(LABEL "${CMAKE_BINARY_DIR}" NAME) + file(WRITE "${DEFINITION_PATH}.${LABEL}" + "// This header was generated by cmake (${LABEL})\n" + "// IMPORTANT: Dont modify this file manually!\n") + if (JAM_COMPATIBLE) + file(APPEND "${DEFINITION_PATH}.${LABEL}" "#define JAM_COMPATIBILITY_ENABLED\n") + endif () + if (CUSTOM_CONFIG_SUPPORT) + file(APPEND "${DEFINITION_PATH}.${LABEL}" "#define CUSTOM_CONFIG_ENABLED\n") + endif () + file(RENAME "${DEFINITION_PATH}.${LABEL}" "${DEFINITION_PATH}") + message(STATUS "include/scale/definitions.hpp has generated") + file(WRITE "${CMAKE_BINARY_DIR}/definition.d" "include/scale/definitions.hpp has generated") endif () add_subdirectory(src) @@ -63,7 +73,7 @@ install(TARGETS scale EXPORT scaleConfig INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} FRAMEWORK DESTINATION ${CMAKE_INSTALL_PREFIX} - ) +) install( DIRECTORY ${CMAKE_SOURCE_DIR}/include/scale diff --git a/include/scale/configurable.hpp b/include/scale/configurable.hpp index 002cd52..c320360 100644 --- a/include/scale/configurable.hpp +++ b/include/scale/configurable.hpp @@ -6,6 +6,7 @@ #pragma once +#include #ifdef CUSTOM_CONFIG_ENABLED #include #endif @@ -68,4 +69,4 @@ namespace scale { #endif }; -} // namespace scale \ No newline at end of file +} // namespace scale diff --git a/include/scale/scale_decoder_stream.hpp b/include/scale/scale_decoder_stream.hpp index 61010af..7be6465 100644 --- a/include/scale/scale_decoder_stream.hpp +++ b/include/scale/scale_decoder_stream.hpp @@ -16,6 +16,7 @@ #include #include +#include #include #ifdef JAM_COMPATIBILITY_ENABLED #include diff --git a/include/scale/scale_encoder_stream.hpp b/include/scale/scale_encoder_stream.hpp index e76dccc..25ecf34 100644 --- a/include/scale/scale_encoder_stream.hpp +++ b/include/scale/scale_encoder_stream.hpp @@ -16,6 +16,7 @@ #include #include +#include #include #ifdef JAM_COMPATIBILITY_ENABLED #include diff --git a/test/scale_tune_test.cpp b/test/scale_tune_test.cpp index 9bb16b4..62045a4 100644 --- a/test/scale_tune_test.cpp +++ b/test/scale_tune_test.cpp @@ -4,15 +4,14 @@ * SPDX-License-Identifier: Apache-2.0 */ +#include +#include + #ifndef CUSTOM_CONFIG_ENABLED #error \ - "This file should not be compiled, because custom config support is not enabed" +"This file should not be compiled, because custom config support is not enabed" #endif -#include - -#include - using scale::ByteArray; using scale::CompactInteger; using scale::decode;