Skip to content
Merged
14 changes: 5 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.16)
project(Halide VERSION 10.0.0)
project(Halide VERSION 12.0.0)

enable_testing()

Expand All @@ -10,6 +10,9 @@ enable_testing()
# Make our custom helpers available throughout the project via include().
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/cmake)
include(HalideTargetHelpers)
include(HalideGeneratorHelpers)
include(MakeShellPath)
include(CMakeDependentOption)

# Build Halide as a shared lib by default, but still honor command-line settings.
if (NOT DEFINED BUILD_SHARED_LIBS)
Expand All @@ -25,7 +28,7 @@ endif ()
# Windows has file name length restrictions and lacks an RPATH mechanism.
# We work around this by setting a path max and putting all exes / dlls in
# the same output directory.
if (${CMAKE_SYSTEM_NAME} MATCHES "Windows")
if (CMAKE_SYSTEM_NAME MATCHES "Windows")
set(CMAKE_OBJECT_PATH_MAX 260)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/bin")

Expand Down Expand Up @@ -53,13 +56,6 @@ add_subdirectory(dependencies)
add_subdirectory(src)
add_subdirectory(tools)

##
# Add helper functions to the build
##

include(HalideGeneratorHelpers)
include(MakeShellPath)

##
# Add tests, apps, tutorials, etc. if we're not being imported into another CMake project.
##
Expand Down
8 changes: 2 additions & 6 deletions apps/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,10 @@ function(add_app_test NAME)
endif ()

set(cmakeDefinitionOpts
# TODO: enable verbose here temporarily, to try to track down flaky Windows failures
"-DCMAKE_VERBOSE_MAKEFILE=ON"
"-DCMAKE_PREFIX_PATH=${HALIDE_DIR}"
"-DCMAKE_BUILD_TYPE=$<CONFIG>"
"-DLLVM_DIR=${LLVM_DIR}")
if (NOT "${Halide_TARGET}" STREQUAL "")
list(APPEND cmakeDefinitionOpts "-DHalide_TARGET=${Halide_TARGET}")
endif ()
"-DLLVM_DIR=${LLVM_DIR}"
"-DHalide_TARGET=${Halide_TARGET}")

add_test(NAME ${NAME}
COMMAND ${CMAKE_CTEST_COMMAND}
Expand Down
20 changes: 10 additions & 10 deletions cmake/HalideTargetHelpers.cmake
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
##
# Cache variable to control the global target for add_halide_library.
##

if (NOT "$ENV{HL_TARGET}" STREQUAL "")
set(Halide_TARGET "$ENV{HL_TARGET}" CACHE STRING "The target to use when compiling AOT tests")
else ()
set(Halide_TARGET "" CACHE STRING "The target to use when compiling AOT tests")
endif ()

##
# Utilities for manipulating Halide target triples
##
Expand Down Expand Up @@ -54,3 +44,13 @@ if (NOT Halide_CMAKE_TARGET)
_Halide_cmake_target(Halide_CMAKE_TARGET)
message(STATUS "Halide detected active CMake target `${Halide_CMAKE_TARGET}`")
endif ()

##
# Cache variable to control the global target for add_halide_library.
##

if (NOT "$ENV{HL_TARGET}" STREQUAL "")
set(Halide_TARGET "$ENV{HL_TARGET}" CACHE STRING "The target to use when compiling AOT tests")
else ()
set(Halide_TARGET "${Halide_CMAKE_TARGET}" CACHE STRING "The target to use when compiling AOT tests")
endif ()
2 changes: 1 addition & 1 deletion dependencies/wasm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ if (WITH_WABT)
set(BUILD_LIBWASM OFF)
FetchContent_MakeAvailable(wabt)

set_target_properties(wabt PROPERTIES POSITION_INDEPENDENT_CODE TRUE)
set_target_properties(wabt PROPERTIES POSITION_INDEPENDENT_CODE ON)

# TODO: we want to require unique prefixes to include these files, to avoid ambiguity;
# this means we have to prefix with "wabt-src/...", which is less bad than other alternatives,
Expand Down
8 changes: 0 additions & 8 deletions doc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,3 @@ doxygen_add_docs(doc
"${Halide_SOURCE_DIR}/test"
ALL
COMMENT "Generate HTML documentation")

##
# Installation
##

include(GNUInstallDirs)
set(CMAKE_INSTALL_DOCDIR ${CMAKE_INSTALL_DATAROOTDIR}/doc/${PROJECT_NAME})
install(DIRECTORY ${Halide_BINARY_DIR}/doc/html/ TYPE DOC)
26 changes: 18 additions & 8 deletions packaging/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,42 @@ set(HALIDE_INSTALL_CMAKEDIR
"${CMAKE_INSTALL_LIBDIR}/cmake/Halide"
CACHE STRING "Path to Halide cmake files")

##
# Optional dependencies
##

set(optional_dependencies "")
foreach (target IN ITEMS wabt)
if (TARGET ${target})
list(APPEND optional_dependencies ${target})
endif ()
endforeach ()

##
# Main library exports
##

# TODO(#4053): add autoschedulers when refactored

# Sends Debug -> Debug, Release/MinSizeRel/RelWithDebInfo -> Release
set(CONFIG_DIR $<IF:$<CONFIG:Debug>,Debug,Release>)

install(TARGETS Halide Halide_Generator Halide_RunGenMain
EXPORT Halide_Targets

RUNTIME
DESTINATION ${CMAKE_INSTALL_BINDIR}/${CONFIG_DIR}
DESTINATION ${CMAKE_INSTALL_BINDIR}
COMPONENT Halide_Runtime

LIBRARY
DESTINATION ${CMAKE_INSTALL_LIBDIR}/${CONFIG_DIR}
DESTINATION ${CMAKE_INSTALL_LIBDIR}
COMPONENT Halide_Runtime
NAMELINK_COMPONENT Halide_Development

ARCHIVE
DESTINATION ${CMAKE_INSTALL_LIBDIR}/${CONFIG_DIR}
DESTINATION ${CMAKE_INSTALL_LIBDIR}
COMPONENT Halide_Development

INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})

install(TARGETS Halide_LLVM
install(TARGETS Halide_LLVM ${optional_dependencies}
EXPORT Halide_Targets)

install(TARGETS Halide_Tools Halide_ImageIO Halide_LanguageOptions
Expand Down Expand Up @@ -143,7 +151,9 @@ install(FILES
# Documentation
##

# See /doc/CMakeLists.txt. This way, special install logic isn't needed.
if (WITH_DOCS)
install(DIRECTORY ${Halide_BINARY_DIR}/doc/html/ TYPE DOC)
endif ()

##
# Actual packaging
Expand Down
26 changes: 12 additions & 14 deletions packaging/HalideConfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -62,20 +62,18 @@ macro(_Halide_include TYPE CAUSE)
include("${CMAKE_CURRENT_LIST_DIR}/Halide-Targets-${TYPE}.cmake")

if (NOT ${CMAKE_FIND_PACKAGE_NAME}_both)
# In CMake <= 3.17, ALIAS targets may not refer to non-global targets.
# this means that multiple different versions of Halide may not be used
# in a single project via find_package until 3.18
if (CMAKE_VERSION VERSION_LESS 3.18)
set_target_properties(Halide::${TYPE}::Halide
Halide::${TYPE}::Generator
Halide::${TYPE}::RunGenMain
PROPERTIES
IMPORTED_GLOBAL TRUE)
endif ()

add_library(Halide::Halide ALIAS Halide::${TYPE}::Halide)
add_library(Halide::Generator ALIAS Halide::${TYPE}::Generator)
add_library(Halide::RunGenMain ALIAS Halide::${TYPE}::RunGenMain)
foreach (target IN ITEMS Halide Generator RunGenMain)
if (NOT TARGET Halide::${TYPE}::${target})
continue()
endif ()
if (CMAKE_VERSION VERSION_LESS 3.18)
# In CMake <= 3.17, ALIAS targets may not refer to non-global targets, so we
# are forced to promote here. This means that multiple different versions of
# Halide may not be used in a single project via find_package until 3.18
set_target_properties(Halide::${TYPE}::${target} PROPERTIES IMPORTED_GLOBAL TRUE)
endif ()
add_library(Halide::${target} ALIAS Halide::${TYPE}::${target})
endforeach ()
endif ()
endmacro()

Expand Down
11 changes: 0 additions & 11 deletions packaging/Linux.cmake

This file was deleted.

9 changes: 0 additions & 9 deletions packaging/macOS.cmake

This file was deleted.

2 changes: 1 addition & 1 deletion python_bindings/stub/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ if (NOT TARGET Halide::PyStubs)
set_target_properties(Halide_PyStubs PROPERTIES
EXPORT_NAME PyStubs
VISIBILITY_INLINES_HIDDEN TRUE
POSITION_INDEPENDENT_CODE TRUE)
POSITION_INDEPENDENT_CODE ON)
endif ()

include(${CMAKE_CURRENT_LIST_DIR}/AddHalideGeneratorPython.cmake)
18 changes: 6 additions & 12 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -359,10 +359,8 @@ add_custom_command(OUTPUT "${Halide_BINARY_DIR}/include/Halide.h"
DEPENDS build_halide_h "${LICENSE_PATH}" ${HEADER_FILES}
WORKING_DIRECTORY "${CMAKE_CURRENT_LIST_DIR}"
VERBATIM)
add_custom_target(
HalideIncludes
ALL
DEPENDS "${Halide_BINARY_DIR}/include/Halide.h")
add_custom_target(HalideIncludes ALL
DEPENDS "${Halide_BINARY_DIR}/include/Halide.h")

##
# Define the Halide library target.
Expand All @@ -379,14 +377,16 @@ target_link_libraries(Halide PRIVATE Halide::LLVM)
target_link_libraries(Halide PUBLIC Halide::LanguageOptions)
target_compile_definitions(Halide PRIVATE $<$<NOT:$<BOOL:${BUILD_SHARED_LIBS}>>:Halide_STATIC_DEFINE>)

set_target_properties(Halide PROPERTIES POSITION_INDEPENDENT_CODE ON)
set_target_properties(Halide PROPERTIES
POSITION_INDEPENDENT_CODE ON
VERSION ${Halide_VERSION}
SOVERSION ${Halide_VERSION_MAJOR})

add_dependencies(Halide HalideIncludes)

if (TARGET wabt)
target_link_libraries(Halide PRIVATE wabt)
target_compile_definitions(Halide PRIVATE WITH_WABT)
install(TARGETS wabt EXPORT Halide_Targets)
endif ()

##
Expand Down Expand Up @@ -456,12 +456,6 @@ target_compile_options(Halide
# source files in parallel; the Halide library itself is a "knot" point of the build graph,
# so compiling its files in parallel should not oversubscribe the system
$<$<CXX_COMPILER_ID:MSVC>:/MP>

# To compile LLVM headers, the following was taken from LLVM CMake files:
# Disable sized deallocation if the flag is supported. MSVC fails to compile
# the operator new overload in LLVM/IR/Function.h and Instruction.h otherwise.
# See LLVM PR: 23513 (https://llvm.org/bugs/show_bug.cgi?id=23513)
$<$<CXX_COMPILER_ID:MSVC>:/Zc:sizedDealloc->
)

target_compile_definitions(Halide
Expand Down
11 changes: 7 additions & 4 deletions src/runtime/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
if (NOT CMAKE_GENERATOR MATCHES "Make|Ninja")
message(STATUS "Notice: ${CMAKE_GENERATOR} does not support depfile dependencies. Incremental builds may fail.")
endif ()

# Keep these lists in alphabetical order.
set(RUNTIME_CPP
aarch64_cpu_features
Expand Down Expand Up @@ -151,16 +155,16 @@ foreach (i IN LISTS RUNTIME_CPP)
foreach (j IN ITEMS 32 64)
# -fpic needs special treatment; see below on windows 64bits
set(fpic -fpic)
if (${j} EQUAL 32)
if (${i} MATCHES "windows_.*")
if (j EQUAL 32)
if (i MATCHES "windows_.*")
# win32 uses the stdcall calling convention, which is x86-specific
set(TARGET "i386-unknown-unknown-unknown")
else ()
# (The 'nacl' is a red herring. This is just a generic 32-bit little-endian target.)
set(TARGET "le32-unknown-nacl-unknown")
endif ()
else ()
if (${i} MATCHES "windows_.*")
if (i MATCHES "windows_.*")
# must omit -fpic, otherwise clang will complain with the following:
# clang : error : unsupported option '-fpic' for target 'x86_64-pc-windows-msvc'
set(fpic "")
Expand Down Expand Up @@ -195,7 +199,6 @@ foreach (i IN LISTS RUNTIME_CPP)
list(APPEND clang_flags -MD -MF "$<SHELL_PATH:${CMAKE_CURRENT_BINARY_DIR}/${basename}.d>")
set(dep_args DEPFILE "${CMAKE_CURRENT_BINARY_DIR}/${basename}.d")
elseif (NOT CMAKE_GENERATOR MATCHES "Make")
message(STATUS "Notice: ${CMAKE_GENERATOR} does not support depfile dependencies. Incremental builds may fail.")
set(dep_args "")
endif ()

Expand Down
81 changes: 40 additions & 41 deletions test/correctness/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -345,44 +345,43 @@ tests(GROUPS correctness
target_link_libraries(correctness_image_io PRIVATE Halide::ImageIO)

# Tests which use external funcs need to enable exports.
foreach (TEST IN ITEMS
correctness_async
correctness_atomics
correctness_c_function
correctness_compute_at_split_rvar
correctness_concat
correctness_custom_lowering_pass
correctness_extern_bounds_inference
correctness_extern_consumer
correctness_extern_consumer_tiled
correctness_extern_error
correctness_extern_output_expansion
correctness_extern_partial
correctness_extern_producer
correctness_extern_reorder_storage
correctness_extern_sort
correctness_extern_stage
correctness_extern_stage_on_device
correctness_handle
correctness_image_of_lists
correctness_lazy_convolution
correctness_loop_invariant_extern_calls
correctness_make_struct
correctness_many_small_extern_stages
correctness_memoize
correctness_memoize_cloned
correctness_multiple_outputs_extern
correctness_non_nesting_extern_bounds_query
correctness_parallel_fork
correctness_pipeline_set_jit_externs_func
correctness_process_some_tiles
correctness_side_effects
correctness_skip_stages
correctness_skip_stages_external_array_functions
correctness_sliding_backwards
correctness_sliding_over_guard_with_if
correctness_sliding_reduction
correctness_sliding_window
correctness_storage_folding)
set_target_properties(${TEST} PROPERTIES ENABLE_EXPORTS TRUE)
endforeach ()
set_target_properties(correctness_async
correctness_atomics
correctness_c_function
correctness_compute_at_split_rvar
correctness_concat
correctness_custom_lowering_pass
correctness_extern_bounds_inference
correctness_extern_consumer
correctness_extern_consumer_tiled
correctness_extern_error
correctness_extern_output_expansion
correctness_extern_partial
correctness_extern_producer
correctness_extern_reorder_storage
correctness_extern_sort
correctness_extern_stage
correctness_extern_stage_on_device
correctness_handle
correctness_image_of_lists
correctness_lazy_convolution
correctness_loop_invariant_extern_calls
correctness_make_struct
correctness_many_small_extern_stages
correctness_memoize
correctness_memoize_cloned
correctness_multiple_outputs_extern
correctness_non_nesting_extern_bounds_query
correctness_parallel_fork
correctness_pipeline_set_jit_externs_func
correctness_process_some_tiles
correctness_side_effects
correctness_skip_stages
correctness_skip_stages_external_array_functions
correctness_sliding_backwards
correctness_sliding_over_guard_with_if
correctness_sliding_reduction
correctness_sliding_window
correctness_storage_folding
PROPERTIES ENABLE_EXPORTS TRUE)

Loading