-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce HalideFeatures system for optional components (#8384)
Previously, our `option()` declarations were scattered and not well documented. They certainly weren't self-documenting. Some of them depended on other options and used various ways to handle conflicts. Sometimes inconsistencies were handled with fatal errors, other times by silently overriding an option. With this PR, we introduce a new `Halide_feature` function that is designed to handle interdependent options and default initialization in a much more regular way. It behaves very much like option in its first three parameters: Halide_feature(CMAKE_FLAG "documentation string" DEFAULT_VALUE) Only now `DEFAULT_VALUE` can be more intelligent than simply `ON` or `OFF`. It can also be `TOP_LEVEL`, which is `ON` iff `CMAKE_PROJECT_TOP_LEVEL` is true. It can also be `AUTO` which is `ON` iff the `DEPENDS` clause is defined and true. For example, Halide_feature(WITH_TEST_RUNTIME "Build runtime tests" AUTO DEPENDS NOT MSVC) If a feature is set to `ON` but its `DEPENDS` clause is false, a warning will be issued and the feature will be forced `OFF` in the cache. Furthermore, these features register their documentation strings with the built-in `FeatureSummary` system so now instead of a stream of easy-to-miss messages, the configuration ends with a summary of what is enabled and disabled: -- The following features have been enabled: * Halide_ENABLE_EXCEPTIONS, Enable exceptions in Halide * Halide_ENABLE_RTTI, Enable RTTI in Halide * WITH_AUTOSCHEDULERS, Build the Halide autoschedulers * WITH_PACKAGING, Halide's CMake package install rules * WITH_PYTHON_BINDINGS, Halide's native Python module (not the whole pip package) * WITH_SERIALIZATION, Include experimental Serialization/Deserialization code * WITH_TESTS, Halide's unit test suite * WITH_TUTORIALS, Halide's tutorial code * WITH_UTILS, Optional utility programs for Halide, including HalideTraceViz * WITH_TEST_AUTO_SCHEDULE, Build autoscheduler tests * WITH_TEST_CORRECTNESS, Build correctness tests * WITH_TEST_ERROR, Build error tests * WITH_TEST_WARNING, Build warning tests * WITH_TEST_PERFORMANCE, Build performance tests * WITH_TEST_GENERATOR, Build generator tests * WITH_TEST_RUNTIME, Build runtime tests -- The following features have been disabled: * WITH_DOCS, Halide's Doxygen documentation * WITH_TEST_FUZZ, Build fuzz tests A feature may be marked as `ADVANCED`, which excludes it from the feature summary unless the log level is set to verbose. It also marks it as advanced in the cache, which hides it from the default view in the CMake GUI and the curses-TUI. Finally, features are computed early in the build so that subdirectories see a consistent view. Some generator tests that were broken under static Halide (meaning no autoschedulers) are now properly skipped by directly checking `WITH_AUTOSCHEDULERS`.
- Loading branch information
1 parent
ff538b1
commit 7b53a88
Showing
10 changed files
with
161 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
if (PROJECT_IS_TOP_LEVEL) | ||
include(FeatureSummary) | ||
cmake_language( | ||
DEFER DIRECTORY "${Halide_SOURCE_DIR}" | ||
CALL feature_summary WHAT ENABLED_FEATURES DISABLED_FEATURES | ||
) | ||
endif () | ||
|
||
function(_Halide_feature_info opt doc) | ||
if (NOT PROJECT_IS_TOP_LEVEL) | ||
return() | ||
endif () | ||
|
||
set(notice "") | ||
if (ARG_ADVANCED) | ||
cmake_language(GET_MESSAGE_LOG_LEVEL log_level) | ||
if (log_level MATCHES "^(VERBOSE|DEBUG|TRACE)$") | ||
set(notice " (advanced)") | ||
else () | ||
return() | ||
endif () | ||
endif () | ||
|
||
add_feature_info("${opt}${notice}" "${opt}" "${doc}") | ||
endfunction() | ||
|
||
function(Halide_feature OPTION DOC DEFAULT) | ||
cmake_parse_arguments(PARSE_ARGV 3 ARG "ADVANCED" "" "DEPENDS") | ||
|
||
if (DEFAULT STREQUAL "TOP_LEVEL") | ||
set(default_value "${PROJECT_IS_TOP_LEVEL}") | ||
elseif (DEFAULT STREQUAL "AUTO") | ||
set(default_value ${ARG_DEPENDS}) | ||
else () | ||
set(default_value ${DEFAULT}) | ||
endif () | ||
|
||
if (${default_value}) | ||
set(default_value ON) | ||
else () | ||
set(default_value OFF) | ||
endif () | ||
|
||
option("${OPTION}" "${DOC}" "${default_value}") | ||
if (ARG_ADVANCED) | ||
mark_as_advanced("${OPTION}") | ||
endif () | ||
|
||
if (${OPTION} AND DEFINED ARG_DEPENDS AND NOT (${ARG_DEPENDS})) | ||
list(JOIN ARG_DEPENDS " " depends) | ||
message(WARNING "${OPTION} forcibly disabled -- requires ${depends}") | ||
set("${OPTION}" 0) | ||
set("${OPTION}" "${${OPTION}}" CACHE BOOL "${DOC}" FORCE) | ||
endif () | ||
|
||
_Halide_feature_info("${OPTION}" "${DOC}") | ||
|
||
set("${OPTION}" "${${OPTION}}" PARENT_SCOPE) | ||
endfunction() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.