Skip to content

Commit

Permalink
Merge branch 'main' into pr/8350
Browse files Browse the repository at this point in the history
  • Loading branch information
steven-johnson committed Aug 23, 2024
2 parents a4393df + 45518ac commit f8c37c3
Show file tree
Hide file tree
Showing 182 changed files with 2,930 additions and 1,525 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,9 @@ install_manifest.txt
# Ninja files
*.ninja*

# Package managers
vcpkg_installed/

################################################################################
## IDE directories and metadata

Expand Down
141 changes: 74 additions & 67 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,22 +1,51 @@
cmake_minimum_required(VERSION 3.22...3.23)
cmake_minimum_required(VERSION 3.28)

option(Halide_USE_FETCHCONTENT "When Halide is top-level, use FetchContent for build-time dependencies." ON)
if (Halide_USE_FETCHCONTENT)
list(APPEND CMAKE_PROJECT_TOP_LEVEL_INCLUDES "${CMAKE_CURRENT_LIST_DIR}/cmake/dependencies.cmake")
endif ()

# TODO: remove this after updating build bots.
if (NOT DEFINED VCPKG_OVERLAY_PORTS)
set(VCPKG_OVERLAY_PORTS "${CMAKE_CURRENT_LIST_DIR}/cmake/vcpkg")
endif ()

# TODO: remove this after updating build bots.
if (NOT DEFINED VCPKG_MANIFEST_FEATURES)
set(VCPKG_MANIFEST_FEATURES developer)
endif ()

project(Halide
VERSION 18.0.0
VERSION 19.0.0
DESCRIPTION "Halide compiler and libraries"
HOMEPAGE_URL "https://halide-lang.org")

enable_testing()

##
# Disable find_package(Halide) inside the build
##

file(CONFIGURE OUTPUT "${CMAKE_FIND_PACKAGE_REDIRECTS_DIR}/HalideConfig.cmake"
CONTENT [[set(Halide_FOUND 1)
set(Halide_VERSION @Halide_VERSION@)]])

file(CONFIGURE OUTPUT "${CMAKE_FIND_PACKAGE_REDIRECTS_DIR}/HalideHelpersConfig.cmake"
CONTENT "set(HalideHelpers_FOUND 1)\n")

##
# Set up project-wide properties
##

# Import useful standard modules
include(CMakeDependentOption)
include(CheckCXXSymbolExists)

# Make our custom helpers available throughout the project via include().
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/cmake)
include(BundleStatic)
include(HalideFeatures)
include(HalideGeneratorHelpers)
include(HalidePackageConfigHelpers)

# Build Halide as a shared lib by default, but still honor command-line settings.
option(BUILD_SHARED_LIBS "Build shared libraries" ON)
Expand Down Expand Up @@ -45,14 +74,12 @@ set(CMAKE_CXX_STANDARD 17 CACHE STRING "The C++ standard to use. Halide requires
option(CMAKE_CXX_STANDARD_REQUIRED "When enabled, the value of CMAKE_CXX_STANDARD is a requirement." ON)
option(CMAKE_CXX_EXTENSIONS "When enabled, compiler-specific language extensions are enabled (e.g. -std=gnu++17)" OFF)

if(CMAKE_CXX_STANDARD LESS 17)
if (CMAKE_CXX_STANDARD LESS 17)
message(FATAL_ERROR "Halide requires C++17 or newer but CMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD}")
endif()

# Build Halide with ccache if the package is present
option(Halide_CCACHE_BUILD "Set to ON for a ccache enabled build" OFF)
mark_as_advanced(Halide_CCACHE_BUILD)
endif ()

# Build Halide with ccache if the package is present and the user requested it
Halide_feature(Halide_CCACHE_BUILD "Build with CCache as best configured for Halide" OFF ADVANCED)
if (Halide_CCACHE_BUILD)
find_program(CCACHE_PROGRAM ccache REQUIRED)

Expand All @@ -68,14 +95,12 @@ if (Halide_CCACHE_BUILD)

# Per https://ccache.dev/manual/latest.html#_precompiled_headers,
# we must set -fno-pch-timestamp when using Clang + CCache + PCH
if(CMAKE_C_COMPILER_ID MATCHES "Clang")
if (CMAKE_C_COMPILER_ID MATCHES "Clang")
string(APPEND CMAKE_C_FLAGS " -Xclang -fno-pch-timestamp")
endif()
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
endif ()
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
string(APPEND CMAKE_CXX_FLAGS " -Xclang -fno-pch-timestamp")
endif()

message(STATUS "Enabling ccache usage for building.")
endif ()
endif ()

# Detect whether or not ASAN is enabled. Don't cache the result to ensure this
Expand All @@ -89,13 +114,6 @@ else ()
set(Halide_ANY_SANITIZERS_ENABLED 0)
endif ()

# Enable the SPIR-V target if requested (must declare before processing dependencies)
option(TARGET_SPIRV "Include SPIR-V target" OFF)
option(TARGET_VULKAN "Include Vulkan target" ON)
if (TARGET_VULKAN)
set(TARGET_SPIRV ON) # required
endif()

# Helper function to set C++ compiler warnings in a sane way
function(set_halide_compiler_warnings NAME)
target_compile_options(
Expand Down Expand Up @@ -152,9 +170,6 @@ function(set_halide_compiler_warnings NAME)
$<$<CXX_COMPILER_ID:Clang,AppleClang>:-Wno-unused-member-function>
$<$<CXX_COMPILER_ID:Clang,AppleClang>:-Wno-unused-template>

# This warning was removed in Clang 13
$<$<AND:$<CXX_COMPILER_ID:Clang,AppleClang>,$<VERSION_LESS:$<CXX_COMPILER_VERSION>,13.0>>:-Wno-return-std-move-in-c++11>

$<$<CXX_COMPILER_ID:MSVC>:/W3>
$<$<CXX_COMPILER_ID:MSVC>:/wd4018> # 4018: disable "signed/unsigned mismatch"
$<$<CXX_COMPILER_ID:MSVC>:/wd4141> # 4141: 'inline' used more than once
Expand All @@ -179,8 +194,12 @@ endfunction()
option(THREADS_PREFER_PTHREAD_FLAG "When enabled, prefer to use the -pthread flag to explicit linking" ON)
find_package(Threads REQUIRED)

## Complex dependencies
add_subdirectory(dependencies)
## LLVM
find_package(Halide_LLVM 17...20 REQUIRED
COMPONENTS WebAssembly X86
OPTIONAL_COMPONENTS AArch64 ARM Hexagon NVPTX PowerPC RISCV)

_Halide_pkgdep(Halide_LLVM PACKAGE_VARS Halide_LLVM_SHARED_LIBS)

## Image formats

Expand All @@ -197,70 +216,58 @@ find_package(JPEG)
find_package(PNG)

##
# Declare options
##

# Declare these options after we include dependencies (since it declares Halide_ENABLE_RTTI etc)
# but before we add any subdirectories, since any option you test before it is defined is
# implicitly false the *first* time that the build file is processed, and there are some
# out-of-order dependencies here (e.g, code in src/ eventually checks WITH_UTILS).
# This is especially subtle since it means that some options can end up with different
# values if you build a target as part of the initial CMake run, so (e.g.) a `make install`
# from as totally clean build might neglect to install some pieces.

option(WITH_TESTS "Build tests" "${PROJECT_IS_TOP_LEVEL}")
option(WITH_TUTORIALS "Build tutorials" "${PROJECT_IS_TOP_LEVEL}")
option(WITH_DOCS "Build documentation" OFF)
option(WITH_UTILS "Build utils" "${PROJECT_IS_TOP_LEVEL}")
cmake_dependent_option(
WITH_PYTHON_BINDINGS "Build Python bindings" "${PROJECT_IS_TOP_LEVEL}"
"Halide_ENABLE_RTTI AND Halide_ENABLE_EXCEPTIONS" OFF
)
# Optional features. These settings are defined early so that subdirectories see a consistent view

Halide_feature(Halide_BUNDLE_STATIC "Bundle Halide's static dependencies" OFF ADVANCED
DEPENDS NOT BUILD_SHARED_LIBS)

Halide_feature(Halide_ENABLE_EXCEPTIONS "Enable exceptions in Halide" ON)
Halide_feature(Halide_ENABLE_RTTI "Enable RTTI in Halide" ON
DEPENDS LLVM_ENABLE_RTTI)
Halide_feature(Halide_BUNDLE_STATIC "Bundle Halide's static dependencies" OFF ADVANCED
DEPENDS NOT BUILD_SHARED_LIBS)

Halide_feature(WITH_AUTOSCHEDULERS "Build the Halide autoschedulers" ON
DEPENDS BUILD_SHARED_LIBS)
Halide_feature(WITH_DOCS "Halide's Doxygen documentation" OFF)
Halide_feature(WITH_PACKAGING "Halide's CMake package install rules" TOP_LEVEL)
Halide_feature(WITH_PYTHON_BINDINGS "Halide's native Python module (not the whole pip package)" ON
DEPENDS Halide_ENABLE_EXCEPTIONS AND Halide_ENABLE_RTTI)
Halide_feature(WITH_SERIALIZATION "Include experimental Serialization/Deserialization code" ON)
Halide_feature(WITH_SERIALIZATION_JIT_ROUNDTRIP_TESTING
"Intercepting JIT compilation with a serialization roundtrip, for test only"
OFF ADVANCED
DEPENDS WITH_SERIALIZATION)
Halide_feature(WITH_TESTS "Halide's unit test suite" TOP_LEVEL)
Halide_feature(WITH_TUTORIALS "Halide's tutorial code" TOP_LEVEL)
Halide_feature(WITH_UTILS "Optional utility programs for Halide, including HalideTraceViz" TOP_LEVEL)

##
# Add source directories
##

add_subdirectory(src)
add_subdirectory(tools)

##
# Add tests, tutorials, etc. if we're not being imported into another CMake project.
##

if (WITH_TESTS)
message(STATUS "Building tests enabled")
add_subdirectory(test)
else ()
message(STATUS "Building tests disabled")
endif ()

if (WITH_PYTHON_BINDINGS)
message(STATUS "Building Python bindings enabled")
add_subdirectory(python_bindings)
else ()
message(STATUS "Building Python bindings disabled")
endif ()

if (WITH_TUTORIALS)
message(STATUS "Building tutorials enabled")
add_subdirectory(tutorial)
else ()
message(STATUS "Building tutorials disabled")
endif ()

if (WITH_DOCS)
message(STATUS "Building docs enabled")
add_subdirectory(doc)
else ()
message(STATUS "Building docs disabled")
endif ()

if (WITH_UTILS)
message(STATUS "Building utils enabled")
add_subdirectory(util)
else ()
message(STATUS "Building utils disabled")
endif ()

add_subdirectory(packaging)
if (WITH_PACKAGING)
add_subdirectory(packaging)
endif ()
Loading

0 comments on commit f8c37c3

Please sign in to comment.