Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ python_bindings/bin/*
build-64/*
build-ios/*
build-osx/*
cmake_build/*
cmake_build*/*
*/build/*
tmp/*
doc/*
Expand Down
10 changes: 6 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ compiler:
- gcc
env:
global:
# The Travis Ubuntu Xenial environment we run in currently promises 2 cores,
# so running lengthy make steps with -j2 is almost certainly a win.
- MAKEFLAGS=-j2
# The Travis Ubuntu Xenial environment we run in currently promises 2 cores.
# We'll run at -j4 on the assumption that there's enough I/O bound work
# for that to be profitable.
- MAKEFLAGS=-j4
matrix:
# Configurations
#
Expand All @@ -19,7 +20,8 @@ env:
#
# Note that gcc5.4 is the default install on Travis Xenial, so we'll just use that.
- LLVM_VERSION=8.0.0 BUILD_SYSTEM=MAKE
- LLVM_VERSION=8.0.0 BUILD_SYSTEM=CMAKE HALIDE_SHARED_LIBRARY=1
- LLVM_VERSION=8.0.0 BUILD_SYSTEM=CMAKE HALIDE_SHARED_LIBRARY=ON
- LLVM_VERSION=8.0.0 BUILD_SYSTEM=CMAKE HALIDE_SHARED_LIBRARY=OFF
#
# llvm7 prebuilts are cranky on Travis and give flaky failures; we just skipped them
# in Trusty and continue to skip them in Xenial.
Expand Down
13 changes: 7 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

project(Halide)
cmake_minimum_required(VERSION 3.2)
cmake_minimum_required(VERSION 3.3)

set(HALIDE_BASE_DIR "${CMAKE_CURRENT_SOURCE_DIR}")

Expand Down Expand Up @@ -169,8 +169,10 @@ option(HALIDE_USE_CODEMODEL_LARGE "Use the Large LLVM codemodel" OFF)

if (HALIDE_SHARED_LIBRARY)
set(HALIDE_LIBRARY_TYPE SHARED)
message(STATUS "Building Halide as a shared library")
else()
set(HALIDE_LIBRARY_TYPE STATIC)
message(STATUS "Building Halide as a static library")
endif()

if (HALIDE_ENABLE_RTTI AND NOT LLVM_ENABLE_RTTI)
Expand All @@ -195,7 +197,7 @@ function(halide_project name folder)
target_compile_options("${name}" PUBLIC "-fno-rtti")
endif()
endif()
target_link_libraries("${name}" PRIVATE Halide ${CMAKE_DL_LIBS} ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries("${name}" PRIVATE ${HALIDE_COMPILER_LIB} ${CMAKE_DL_LIBS} ${CMAKE_THREAD_LIBS_INIT})
target_include_directories("${name}" PRIVATE "${HALIDE_BASE_DIR}/src")
target_include_directories("${name}" PRIVATE "${HALIDE_BASE_DIR}/tools")
set_target_properties("${name}" PROPERTIES FOLDER "${folder}")
Expand Down Expand Up @@ -330,7 +332,6 @@ function(add_halide_test TARGET)
endforeach()

set(BUILD_NAME "${TARGET}")
# add_custom_target("${BUILD_NAME}" DEPENDS "${TARGET}")
set_target_properties("${BUILD_NAME}" PROPERTIES EXCLUDE_FROM_ALL TRUE)
add_dependencies(build_tests "${BUILD_NAME}")

Expand Down Expand Up @@ -368,6 +369,7 @@ define_test_group(test_auto_schedule)
define_test_group(test_correctness)
define_test_group(test_error)
define_test_group(test_generator)
define_test_group(test_internal)
define_test_group(test_opengl)
define_test_group(test_performance)
define_test_group(test_tutorial)
Expand Down Expand Up @@ -431,8 +433,7 @@ install(FILES
"${CMAKE_BINARY_DIR}/include/Halide.h"
"${CMAKE_BINARY_DIR}/include/HalideBuffer.h"
${FILES}
DESTINATION include
)
DESTINATION include)

install(DIRECTORY tutorial
DESTINATION .
Expand Down Expand Up @@ -465,7 +466,7 @@ file(GLOB FILES "${HALIDE_BASE_DIR}/*.md")
install(FILES ${FILES}
DESTINATION .)

# ---- CMake
# ---- halide.cmake
file(GLOB FILES "${HALIDE_BASE_DIR}/*.cmake")
install(FILES ${FILES}
DESTINATION .)
Expand Down
2 changes: 1 addition & 1 deletion apps/linear_algebra/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ target_link_libraries(test_halide_blas
PRIVATE
halide_blas
cblas # XXX fragile
Halide
${HALIDE_COMPILER_LIB}
)

37 changes: 25 additions & 12 deletions halide.cmake
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
include(CMakeParseArguments)

cmake_minimum_required(VERSION 3.1.3)
cmake_minimum_required(VERSION 3.3)

# ----------------------- Public Functions.
# These are all documented in README_cmake.md.
Expand Down Expand Up @@ -49,8 +49,8 @@ function(halide_generator NAME)
# at least one source file, and this is the cheapest one we're going to have.
add_executable("${NAME}_binary" "${HALIDE_TOOLS_DIR}/GenGen.cpp")
_halide_set_cxx_options("${NAME}_binary")
target_include_directories("${NAME}_binary" PRIVATE "${HALIDE_TOOLS_DIR}")
target_link_libraries("${NAME}_binary" PRIVATE ${HALIDE_COMPILER_LIB} ${HALIDE_SYSTEM_LIBS} ${CMAKE_DL_LIBS} ${CMAKE_THREAD_LIBS_INIT})
target_include_directories("${NAME}_binary" PRIVATE "${HALIDE_INCLUDE_DIR}" "${HALIDE_TOOLS_DIR}")
target_link_libraries("${NAME}_binary" PRIVATE ${HALIDE_SYSTEM_LIBS} ${CMAKE_DL_LIBS} ${CMAKE_THREAD_LIBS_INIT})
if (MSVC)
target_link_libraries("${NAME}_binary" PRIVATE Kernel32)
endif()
Expand All @@ -71,11 +71,19 @@ function(halide_generator NAME)
endforeach()
# Ensure that Halide.h is built prior to any Generator
add_dependencies("${GENLIB}" ${HALIDE_COMPILER_LIB})

_halide_get_static_library_actual_path(${GENLIB} GENLIB_ACTUAL_PATH)
_halide_force_link_library("${NAME}_binary" "${GENLIB}")
endif()

get_target_property(TARGET_TYPE "${HALIDE_COMPILER_LIB}" TYPE)
if("${TARGET_TYPE}" STREQUAL "STATIC_LIBRARY")
# Getting link order correct for static libraries is nearly impossible in CMake;
# to avoid flakiness, always link libHalide via --whole-archive
# when in static-library mode.
_halide_force_link_library("${NAME}_binary" "${HALIDE_COMPILER_LIB}")
else()
target_link_libraries("${NAME}_binary" PRIVATE ${HALIDE_COMPILER_LIB})
endif()

_halide_genfiles_dir(${BASENAME} GENFILES_DIR)
set(STUB_HDR "${GENFILES_DIR}/${BASENAME}.stub.h")
set(GENERATOR_EXEC_ARGS "-g" "${args_GENERATOR_NAME}" "-o" "${GENFILES_DIR}" "-e" "cpp_stub" "-n" "${BASENAME}")
Expand All @@ -89,15 +97,14 @@ function(halide_generator NAME)
set_property(TARGET "${NAME}_stub_gen" PROPERTY _HALIDE_GENERATOR_NAME "${args_GENERATOR_NAME}")

if("${SRCSLEN}" GREATER 0)
_halide_get_static_library_actual_path(${GENLIB} GENLIB_ACTUAL_PATH)
add_library("${NAME}" STATIC IMPORTED)
set_target_properties("${NAME}" PROPERTIES
IMPORTED_LOCATION "${GENLIB_ACTUAL_PATH}")
set_target_properties("${NAME}" PROPERTIES IMPORTED_LOCATION "${GENLIB_ACTUAL_PATH}")
else()
add_library("${NAME}" INTERFACE)
endif()
add_dependencies("${NAME}" "${NAME}_stub_gen")
set_target_properties("${NAME}" PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${GENFILES_DIR}")
set_target_properties("${NAME}" PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${GENFILES_DIR}")
endfunction()

# Use a Generator target to emit a code library.
Expand Down Expand Up @@ -646,14 +653,20 @@ function(_halide_force_link_library NAME LIB)
# (or the equivalent), to ensure that the Generator-registration code
# isn't omitted. Sadly, there's no portable way to do this, so we do some
# special-casing here:
_halide_get_static_library_actual_path(${LIB} LIB_ACTUAL_PATH)
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
_halide_get_static_library_actual_path("${LIB}" LIB_ACTUAL_PATH)
target_link_libraries("${NAME}" PRIVATE "${LIB}")
set_target_properties("${NAME}" PROPERTIES LINK_FLAGS -Wl,-force_load,${GENLIB_ACTUAL_PATH})
# Append to LINK_FLAGS, since we may call this multiple times
get_property(flags TARGET "${NAME}" PROPERTY LINK_FLAGS)
set(flags "${flags} -Wl,-force_load,${LIB_ACTUAL_PATH}")
set_target_properties("${NAME}" PROPERTIES LINK_FLAGS ${flags})
elseif(MSVC)
# Note that this requires VS2015 R2+
target_link_libraries("${NAME}" PRIVATE "${LIB}")
set_target_properties("${NAME}" PROPERTIES LINK_FLAGS "/WHOLEARCHIVE:${LIB}.lib")
# Append to LINK_FLAGS, since we may call this multiple times
get_property(flags TARGET "${NAME}" PROPERTY LINK_FLAGS)
set(flags "${flags} /WHOLEARCHIVE:${LIB}.lib")
set_target_properties("${NAME}" PROPERTIES LINK_FLAGS ${flags})
else()
# Assume Linux or similar
target_link_libraries("${NAME}" PRIVATE -Wl,--whole-archive "${LIB}" -Wl,-no-whole-archive)
Expand Down
9 changes: 5 additions & 4 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ option(WITH_TEST_AUTO_SCHEDULE "Build auto_schedule tests" ON)

if (WITH_TEST_INTERNAL)
message(STATUS "Internal tests enabled")
halide_project(test_internal internal internal.cpp)
add_halide_test(test_internal
GROUPS run_tests)
halide_project(_test_internal internal internal.cpp)
add_halide_test(_test_internal
GROUPS test_internal run_tests)
else()
message(WARNING "Internal tests disabled")
endif()
Expand Down Expand Up @@ -39,8 +39,9 @@ function(tests folder)
target_compile_definitions("${TARGET}" PRIVATE "-DLLVM_VERSION=${LLVM_VERSION}")

set(GROUPS "test_${folder}")
if("${folder}" STREQUAL "performance" OR "${folder}" STREQUAL "auto_schedule")
if("${folder}" STREQUAL "performance" OR "${folder}" STREQUAL "auto_schedule" OR "${folder}" STREQUAL "opengl")
# These shouldn't be part of run_tests, since they must be run with -j for timing purposes
# Exception: opengl is excluded because Makefile excludes it too. Why?
else()
list(APPEND GROUPS run_tests)
endif()
Expand Down
19 changes: 12 additions & 7 deletions test/scripts/build_travis.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,25 @@ if [ ${BUILD_SYSTEM} = 'CMAKE' ]; then
-G "Unix Makefiles" \
../

# Build and run internal tests
make ${MAKEFLAGS} Halide
make ${MAKEFLAGS} distrib
make ${MAKEFLAGS} test_internal

# Build the docs and run the tests
make doc
make ${MAKEFLAGS} test_correctness
make ${MAKEFLAGS} test_generator
if [ ${HALIDE_SHARED_LIBRARY} = 'ON' ]; then
# Building with static library is slower, and can run
# over the time limit; since we just want a reality
# check, do the full test suite only for shared.
make ${MAKEFLAGS} test_correctness
make ${MAKEFLAGS} test_generator
make doc
fi

elif [ ${BUILD_SYSTEM} = 'MAKE' ]; then
export LLVM_CONFIG=/usr/local/llvm/bin/llvm-config
${LLVM_CONFIG} --cxxflags --libdir --bindir

# Build and run internal tests
make ${MAKEFLAGS}
make ${MAKEFLAGS} distrib
make ${MAKEFLAGS} test_internal

# Build the docs and run the tests
make doc
Expand All @@ -56,3 +60,4 @@ else
echo "Unexpected BUILD_SYSTEM: \"${BUILD_SYSTEM}\""
exit 1
fi