summaryrefslogtreecommitdiffstats
path: root/cmake/module
diff options
context:
space:
mode:
authorAlexey Gavrilov <alexey.gavrilov@mail.com>2026-07-23 14:37:44 +0700
committerAlexey Gavrilov <alexey.gavrilov@mail.com>2026-07-23 17:55:20 +0700
commitccb9dbd3f78d9f06826560bd54519bab3477947a (patch)
tree70a5a4ddb9ff59ba334000c0c87d1e0299b408a7 /cmake/module
parentbfab70232fb99d08131c0da3a95b98174e107999 (diff)
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 <alexey.gavrilov@mail.com>
Diffstat (limited to 'cmake/module')
-rw-r--r--cmake/module/cmaketodo10
-rw-r--r--cmake/module/dexport.cmake (renamed from cmake/module/runfile.cmake)10
-rw-r--r--cmake/module/feature.cmake39
3 files changed, 44 insertions, 15 deletions
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/runfile.cmake b/cmake/module/dexport.cmake
index 86c7493..6ab5146 100644
--- a/cmake/module/runfile.cmake
+++ b/cmake/module/dexport.cmake
@@ -17,11 +17,11 @@
include_guard(GLOBAL)
-set(CONFFILE_NAME "CMakeFeaturesDefineEnum.txt" CACHE STRING "Build configuration
+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}}")
+ if("${var}" IN_LIST ${cachelist} AND DEFINED "${var}")
file(APPEND ${${outfile}} " -D${var}=${${var}}")
endif()
endmacro()
@@ -37,10 +37,10 @@ macro(parseFeatures vars outfile)
endforeach()
endmacro()
-function(writerunfile)
- set(OUT_FILE "${CMAKE_BINARY_DIR}/${CONFFILE_NAME}")
+function(definesFileExport)
+ cmake_path(APPEND OUTFILE "${CMAKE_BINARY_DIR}" "${CONFFILE_NAME}")
get_directory_property(cacheVars CACHE_VARIABLES)
- parseFeatures(cacheVars OUT_FILE)
+ 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
@@ -42,8 +42,23 @@ macro(createFeatureModuleFunction name args bodyfunc)
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.
- # <FEATURE_PROPERTY> = "<VARIABLE>"
+# <FEATURE_PROPERTY> = "<VALUE>"
]]
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")