From ccb9dbd3f78d9f06826560bd54519bab3477947a Mon Sep 17 00:00:00 2001 From: Alexey Gavrilov Date: Thu, 23 Jul 2026 14:37:44 +0700 Subject: Include cmake feature module in the build routine Add predicate `ifFeatureEnables` that checks feature is define or not, and return accordingly boolean value. Consider some cmake objective targets as features. Populate information to these targets, and provides in particular file `CMakeFeatures.txt`. Cpuid, MSR, ACPI and driver VGA in text mode they are. Signed-off-by: Alexey Gavrilov --- cmake/module/cmaketodo | 10 ++++++++++ cmake/module/dexport.cmake | 46 ++++++++++++++++++++++++++++++++++++++++++++++ cmake/module/feature.cmake | 39 +++++++++++++++++++++++++++++---------- cmake/module/runfile.cmake | 46 ---------------------------------------------- 4 files changed, 85 insertions(+), 56 deletions(-) create mode 100644 cmake/module/cmaketodo create mode 100644 cmake/module/dexport.cmake delete mode 100644 cmake/module/runfile.cmake (limited to 'cmake') diff --git a/cmake/module/cmaketodo b/cmake/module/cmaketodo new file mode 100644 index 0000000..9ccad77 --- /dev/null +++ b/cmake/module/cmaketodo @@ -0,0 +1,10 @@ +1.(DONE) Don't create a feature with duplicating name + Add checks in create and save feature functions + +2.(DONE) Add processing for FEATURES_SUSPEND variable features functions to suspend +this module variables populating. + +3.(DONE) Are Features accord toolchain? Implement this check. Maybe to process a cache cmake +variable. FEATURES_TIE_BUILD + +4. find_package() support for modules, and write documentation. diff --git a/cmake/module/dexport.cmake b/cmake/module/dexport.cmake new file mode 100644 index 0000000..6ab5146 --- /dev/null +++ b/cmake/module/dexport.cmake @@ -0,0 +1,46 @@ +#[[ + # Copyright (c) 2026 Alexey Gavrilov + # + # This file is part of ObjectiveOS. + # + # ObjectiveOS is free software: you can redistribute it and/or modify it under + # the terms of the GNU General Public License as published by the Free Software + # Foundation, either version 3 of the License, or (at your option) any later + # version. + # + # ObjectiveOS is distributed in the hope that it will be useful, but WITHOUT ANY + # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + # + # You should have received a copy of the GNU General Public License along with + # ObjectiveOS. If not, see . + ]] + +include_guard(GLOBAL) + +set(CONFFILE_NAME "CMakeDexport.txt" CACHE STRING "Build configuration +file contains cmake run command to reproduce last run") + +macro(convertCacheVarIntoArg var cachelist outfile) + if("${var}" IN_LIST ${cachelist} AND DEFINED "${var}") + file(APPEND ${${outfile}} " -D${var}=${${var}}") + endif() +endmacro() + +macro(parseFeatures vars outfile) + # Make copy of cache variables + set(FEATURE_CACHE_VARS ${${vars}}) + # Stay only features enumeration + list(FILTER FEATURE_CACHE_VARS INCLUDE REGEX "FEATURE_[A-Za-z0-9\.]+$") + + foreach(FEATURE_VAR IN LISTS FEATURE_CACHE_VARS) + convertCacheVarIntoArg("${FEATURE_VAR}" ${vars} ${outfile}) + endforeach() +endmacro() + +function(definesFileExport) + cmake_path(APPEND OUTFILE "${CMAKE_BINARY_DIR}" "${CONFFILE_NAME}") + + get_directory_property(cacheVars CACHE_VARIABLES) + + parseFeatures(cacheVars OUTFILE) +endfunction() diff --git a/cmake/module/feature.cmake b/cmake/module/feature.cmake index 8ee7848..bb2459c 100644 --- a/cmake/module/feature.cmake +++ b/cmake/module/feature.cmake @@ -41,9 +41,24 @@ macro(createFeatureModuleFunction name args bodyfunc) endif() endmacro() +#[[ +# Return TRUE if feature define passed from cmake option, FALSE otherwise + # featurename - the name of a feature + # result - out argument keeps variable name to propagate + ]] +createFeatureModuleFunction("ifFeatureEnables" "featurename;result" +[[ if(DEFINED FEATURE_${featurename}) + set(${result} TRUE) + else() + set(${result} FALSE) + endif() + + return(PROPAGATE ${result})]] +) + #[[ # !IMPORTANT! Call before any other function execution and only one time. - # !IMPORTANT! Incorrect use of this function cause undefined behaviour. + # Incorrect use of this function cause undefined behaviour. # Filling cache variables related project information. ]] createFeatureModuleFunction("featureProjectDataAssign" @@ -65,7 +80,7 @@ createFeatureModuleFunction("featureModuleInitialization" "" set_property(GLOBAL PROPERTY CONSERVED_FEATURES "") # Name of out file - set(FEATURE_OUT_FILE "CMakeFeaturesDefineEnum.txt" CACHE STRING "Features data + set(FEATURE_OUT_FILE "CMakeFeatures.txt" CACHE STRING "Features data out filename") set(FEATURE_AVAILABLE_FIELDS "NAME;DESCRIPTION;TAGS;HASHCOMMIT;AUTHORSHIP" CACHE STRING "Available feature fields")]] @@ -122,11 +137,12 @@ createFeatureModuleFunction("saveFeatureRecording" "" # Save feature divides on three category: nothing to save, cannot to finish # and can finish the save process + list(POP_BACK POPULATING_FEATURES_PROPERTY PROMISE_SAVE) + if(POPULATING_FEATURES_LENGTH LESS 1) message(WARNING "Nothing feature to save") elseif(POPULATING_FEATURES_LENGTH EQUAL 1) - list(POP_BACK POPULATING_FEATURES_PROPERTY SAVING_FEATURE) - list(APPEND FEATURES_LIST_PROPERTY \${SAVING_FEATURE}) + list(APPEND FEATURES_LIST_PROPERTY \${PROMISE_SAVE}) # Finish the save process for all features in CONSERVED_FEATURES list while(NOT "\${CONSERVED_FEATURES_PROPERTY}" STREQUAL "") @@ -151,8 +167,7 @@ createFeatureModuleFunction("saveFeatureRecording" "" list(APPEND FEATURES_LIST_PROPERTY \${CONSERVED_FEATURE}) endwhile() elseif(POPULATING_FEATURES_LENGTH GREATER 1) - list(POP_BACK POPULATING_FEATURES_PROPERTY UNFINISHED_FEATURE) - list(APPEND CONSERVED_FEATURES_PROPERTY \${UNFINISHED_FEATURE}) + list(APPEND CONSERVED_FEATURES_PROPERTY \${PROMISE_SAVE}) endif() set_property(GLOBAL PROPERTY @@ -199,7 +214,7 @@ createFeatureModuleFunction("setFeatureField" "field;value" # Element in names must be an architecture, compiler or another feature. # Would is a list. ]] -createFeatureModuleFunction("setFeatureDependency" "names" +createFeatureModuleFunction("setFeatureDependencies" "names" [[ get_property( POPULATING_FEATURES_PROPERTY GLOBAL PROPERTY POPULATING_FEATURES) get_property( CONSERVED_FEATURES_PROPERTY GLOBAL PROPERTY CONSERVED_FEATURES) list(POP_BACK POPULATING_FEATURES_PROPERTY RECORDING_FEATURE) @@ -248,7 +263,7 @@ createFeatureModuleFunction("setFeatureDependency" "names" #[[ # Function that push features data into file. Content is like cmake variables. - # = "" +# = "" ]] createFeatureModuleFunction("outFeaturesToFile" "" [[ get_directory_property(cacheVars CACHE_VARIABLES) @@ -260,8 +275,12 @@ createFeatureModuleFunction("outFeaturesToFile" "" file(APPEND "\${OUT_FILE}" "# Toolset variables\n") if("CMAKE_TOOLCHAIN_FILE" IN_LIST cacheVars AND NOT "\${CMAKE_TOOLCHAIN_FILE}" STREQUAL "") cmake_path(GET CMAKE_TOOLCHAIN_FILE FILENAME TOOLCHAIN_FILE_NAME) - file(APPEND "\${OUT_FILE}" " -DCMAKE_TOOLCHAIN_FILE=" - "\${FEATURE_PROJECT_ROOT_DIR}/\${FEATURE_TOOLCHAIN_DIR}/\${TOOLCHAIN_FILE_NAME}") + cmake_path(APPEND TOOLCHAIN_PATH + "\${FEATURE_PROJECT_ROOT_DIR}" + "\${FEATURE_TOOLCHAIN_DIR}" + "\${TOOLCHAIN_FILE_NAME}" + ) + file(APPEND "\${OUT_FILE}" " -DCMAKE_TOOLCHAIN_FILE=\${TOOLCHAIN_PATH}") else() cmake_path(GET CMAKE_CXX_COMPILER FILENAME CXX_COMPILER_EXECUTABLE) file(APPEND "\${OUT_FILE}" "CMAKE_CXX_COMPILER= \\"\${CXX_COMPILER_EXECUTABLE}\\"\n") diff --git a/cmake/module/runfile.cmake b/cmake/module/runfile.cmake deleted file mode 100644 index 86c7493..0000000 --- a/cmake/module/runfile.cmake +++ /dev/null @@ -1,46 +0,0 @@ -#[[ - # Copyright (c) 2026 Alexey Gavrilov - # - # This file is part of ObjectiveOS. - # - # ObjectiveOS is free software: you can redistribute it and/or modify it under - # the terms of the GNU General Public License as published by the Free Software - # Foundation, either version 3 of the License, or (at your option) any later - # version. - # - # ObjectiveOS is distributed in the hope that it will be useful, but WITHOUT ANY - # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - # - # You should have received a copy of the GNU General Public License along with - # ObjectiveOS. If not, see . - ]] - -include_guard(GLOBAL) - -set(CONFFILE_NAME "CMakeFeaturesDefineEnum.txt" CACHE STRING "Build configuration -file contains cmake run command to reproduce last run") - -macro(convertCacheVarIntoArg var cachelist outfile) - if("${var}" IN_LIST ${cachelist} AND DEFINED "${${var}}") - file(APPEND ${${outfile}} " -D${var}=${${var}}") - endif() -endmacro() - -macro(parseFeatures vars outfile) - # Make copy of cache variables - set(FEATURE_CACHE_VARS ${${vars}}) - # Stay only features enumeration - list(FILTER FEATURE_CACHE_VARS INCLUDE REGEX "FEATURE_[A-Za-z0-9\.]+$") - - foreach(FEATURE_VAR IN LISTS FEATURE_CACHE_VARS) - convertCacheVarIntoArg("${FEATURE_VAR}" ${vars} ${outfile}) - endforeach() -endmacro() - -function(writerunfile) - set(OUT_FILE "${CMAKE_BINARY_DIR}/${CONFFILE_NAME}") - - get_directory_property(cacheVars CACHE_VARIABLES) - - parseFeatures(cacheVars OUT_FILE) -endfunction() -- cgit v1.2.3