From 59c2060edca5cdbc277f22434a6902fb842bb216 Mon Sep 17 00:00:00 2001 From: Steven Johnson Date: Mon, 4 Dec 2017 15:11:16 -0800 Subject: [PATCH 01/10] Rebase --- CMakeLists.txt | 12 ++++++-- halide.cmake | 71 +++++++++++++++++++++++++++++----------------- src/CMakeLists.txt | 3 +- 3 files changed, 55 insertions(+), 31 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 459ff53508f0..49b90d722f77 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ project(Halide) -cmake_minimum_required(VERSION 3.2) +cmake_minimum_required(VERSION 3.3) find_package(Threads QUIET) @@ -42,6 +42,9 @@ set(CMAKE_CXX_EXTENSIONS OFF) set(CMAKE_MACOSX_RPATH ON) +# Allow VISIBILITY_INLINES_HIDDEN to work for static libraries as well as shared +# (since these may later be linked into dynamic libraries). Requires CMake 3.3+. +cmake_policy(SET CMP0063 NEW) set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib") set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib") @@ -138,17 +141,20 @@ option(HALIDE_SHARED_LIBRARY "Build as a shared library" ON) 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() function(halide_project name folder) add_executable("${name}" ${ARGN}) if (MSVC) + target_compile_options("${name}" PRIVATE "/GR-") else() - target_compile_options("${name}" PUBLIC "-fno-rtti") + target_compile_options("${name}" PRIVATE "-fno-rtti") 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 "${CMAKE_SOURCE_DIR}/src") target_include_directories("${name}" PRIVATE "${CMAKE_SOURCE_DIR}/tools") set_target_properties("${name}" PROPERTIES FOLDER "${folder}") diff --git a/halide.cmake b/halide.cmake index bf1e625341ab..a32bba8baf4c 100644 --- a/halide.cmake +++ b/halide.cmake @@ -1,6 +1,9 @@ include(CMakeParseArguments) -cmake_minimum_required(VERSION 3.1.3) +cmake_minimum_required(VERSION 3.3) + +# Allow VISIBILITY_INLINES_HIDDEN to work for static libraries as well as shared. Requires CMake 3.3+. +cmake_policy(SET CMP0063 NEW) # ----------------------- Public Functions. # These are all documented in README_cmake.md. @@ -50,10 +53,6 @@ function(halide_generator NAME) 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}) - if (MSVC) - target_link_libraries("${NAME}_binary" PRIVATE Kernel32) - endif() list(LENGTH args_SRCS SRCSLEN) # Don't create an empty object-library: that can cause quiet failures in MSVC builds. @@ -71,24 +70,20 @@ function(halide_generator NAME) endforeach() # Ensure that Halide.h is built prior to any Generator add_dependencies("${GENLIB}" ${HALIDE_COMPILER_LIB}) + _halide_link_whole_archive("${NAME}_binary" "${GENLIB}") + endif() - _halide_get_static_library_actual_path(${GENLIB} GENLIB_ACTUAL_PATH) - - # We need to ensure that the libraries are linked in with --whole-archive - # (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: - if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") - target_link_libraries("${NAME}_binary" PRIVATE "${GENLIB}") - set_target_properties("${NAME}_binary" PROPERTIES LINK_FLAGS -Wl,-force_load,${GENLIB_ACTUAL_PATH}) - elseif(MSVC) - # Note that this requires VS2015 R2+ - target_link_libraries("${NAME}_binary" PRIVATE "${GENLIB}") - set_target_properties("${NAME}_binary" PROPERTIES LINK_FLAGS "/WHOLEARCHIVE:${GENLIB}.lib") - else() - # Assume Linux or similar - target_link_libraries("${NAME}_binary" PRIVATE -Wl,--whole-archive "${GENLIB}" -Wl,-no-whole-archive) - endif() + 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() + if ("${HALIDE_LIBRARY_TYPE}" STREQUAL "STATIC") + # Getting link order for static libraries is nearly impossible in CMake; + # to avoid flakiness, always link libHalide via --whole-archive + # when in static-library mode. + _halide_link_whole_archive("${NAME}_binary" "${HALIDE_COMPILER_LIB}") + else() + target_link_libraries("${NAME}_binary" PRIVATE ${HALIDE_COMPILER_LIB}) endif() _halide_genfiles_dir(${BASENAME} GENFILES_DIR) @@ -104,15 +99,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. @@ -581,6 +575,31 @@ function(_halide_add_exec_generator_target EXEC_TARGET) endforeach() endfunction() +# We need to ensure that some libraries are linked in with --whole-archive +# (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: +function(_halide_link_whole_archive EXECUTABLE LIBRARY) + if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") + _halide_get_static_library_actual_path("${LIBRARY}" LIBRARY_ACTUAL_PATH) + target_link_libraries("${EXECUTABLE}" PRIVATE "${LIBRARY}") + # Append to LINK_FLAGS, since we may call this multiple times + get_property(flags TARGET "${EXECUTABLE}" PROPERTY LINK_FLAGS) + set(flags "${flags} -Wl,-force_load,${LIBRARY_ACTUAL_PATH}") + set_target_properties("${EXECUTABLE}" PROPERTIES LINK_FLAGS ${flags}) + elseif(MSVC) + # Note that this requires VS2015 R2+ + target_link_libraries("${EXECUTABLE}" PRIVATE "${LIBRARY}") + # Append to LINK_FLAGS, since we may call this multiple times + get_property(flags TARGET "${EXECUTABLE}" PROPERTY LINK_FLAGS) + set(flags "${flags} /WHOLEARCHIVE:${LIBRARY}.lib") + set_target_properties("${EXECUTABLE}" PROPERTIES LINK_FLAGS ${flags}) + else() + # Assume Linux or similar + target_link_libraries("${EXECUTABLE}" PRIVATE -Wl,--whole-archive "${LIBRARY}" -Wl,-no-whole-archive) + endif() +endfunction() + # ----------------------- Configuration code # If paths to tools, include, and libHalide aren't specified, infer them diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b1e457c77f7e..791f327616e4 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -537,8 +537,7 @@ add_library(Halide ${HALIDE_LIBRARY_TYPE} # Define Halide_SHARED or Halide_STATIC depending on library type target_compile_definitions(Halide PRIVATE "-DHalide_${HALIDE_LIBRARY_TYPE}") # Default to not exporting symbols from libHalide -set_target_properties(Halide PROPERTIES CXX_VISIBILITY_PRESET hidden) -set_target_properties(Halide PROPERTIES VISIBILITY_INLINES_HIDDEN 1) +set_target_properties(Halide PROPERTIES CXX_VISIBILITY_PRESET hidden VISIBILITY_INLINES_HIDDEN 1) # Ensure that these tools are build first add_dependencies(Halide binary2cpp From c0fdbe5fb552b48321d22ec34954cd629d0dc4fb Mon Sep 17 00:00:00 2001 From: Steven Johnson Date: Fri, 28 Jun 2019 14:43:00 -0700 Subject: [PATCH 02/10] rename to simplify merge --- halide.cmake | 66 ++++++++++++++++++++++++++-------------------------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/halide.cmake b/halide.cmake index a32bba8baf4c..573b7f0d8fd8 100644 --- a/halide.cmake +++ b/halide.cmake @@ -5,16 +5,16 @@ cmake_minimum_required(VERSION 3.3) # Allow VISIBILITY_INLINES_HIDDEN to work for static libraries as well as shared. Requires CMake 3.3+. cmake_policy(SET CMP0063 NEW) -# ----------------------- Public Functions. +# ----------------------- Public Functions. # These are all documented in README_cmake.md. # # Note that certain CMake variables may need to be set correctly to use these rules: # # - If you are using a Halide distribution, simply set HALIDE_DISTRIB_DIR -# to the path to the distrib directory. +# to the path to the distrib directory. # # - More complex usages (mainly, internal-to-Halide users) may, instead, set some combination -# of HALIDE_TOOLS_DIR, HALIDE_INCLUDE_DIR, and HALIDE_COMPILER_LIB. +# of HALIDE_TOOLS_DIR, HALIDE_INCLUDE_DIR, and HALIDE_COMPILER_LIB. # # Add the include paths and link dependencies for halide_image_io. @@ -65,12 +65,12 @@ function(halide_generator NAME) target_link_libraries("${GENLIB}" ${args_DEPS}) target_include_directories("${GENLIB}" PRIVATE ${args_INCLUDES} "${HALIDE_INCLUDE_DIR}" "${HALIDE_TOOLS_DIR}") foreach(DEP ${args_DEPS}) - target_include_directories("${GENLIB}" PRIVATE + target_include_directories("${GENLIB}" PRIVATE $) endforeach() # Ensure that Halide.h is built prior to any Generator add_dependencies("${GENLIB}" ${HALIDE_COMPILER_LIB}) - _halide_link_whole_archive("${NAME}_binary" "${GENLIB}") + _halide_force_link_library("${NAME}_binary" "${GENLIB}") endif() target_link_libraries("${NAME}_binary" PRIVATE ${HALIDE_SYSTEM_LIBS} ${CMAKE_DL_LIBS} ${CMAKE_THREAD_LIBS_INIT}) @@ -81,7 +81,7 @@ function(halide_generator NAME) # Getting link order for static libraries is nearly impossible in CMake; # to avoid flakiness, always link libHalide via --whole-archive # when in static-library mode. - _halide_link_whole_archive("${NAME}_binary" "${HALIDE_COMPILER_LIB}") + _halide_force_link_library("${NAME}_binary" "${HALIDE_COMPILER_LIB}") else() target_link_libraries("${NAME}_binary" PRIVATE ${HALIDE_COMPILER_LIB}) endif() @@ -232,12 +232,12 @@ function(halide_library_from_generator BASENAME) add_library("${BASENAME}" STATIC IMPORTED) add_dependencies("${BASENAME}" "${BASENAME}_lib_gen" "${RUNTIME_NAME}") - set_target_properties("${BASENAME}" PROPERTIES + set_target_properties("${BASENAME}" PROPERTIES IMPORTED_LOCATION "${GENFILES_DIR}/${BASENAME}${CMAKE_STATIC_LIBRARY_SUFFIX}" INTERFACE_INCLUDE_DIRECTORIES "${GENFILES_DIR}" ${args_INCLUDES} INTERFACE_LINK_LIBRARIES "${RUNTIME_NAME};${args_FILTER_DEPS};${CMAKE_DL_LIBS};${CMAKE_THREAD_LIBS_INIT}") - # A separate invocation for the generated .cpp file, + # A separate invocation for the generated .cpp file, # since it's rarely used, and some code will fail at Generation # time at present (e.g. code with predicated loads or stores). set(ARGS_WITH_OUTPUTS "-e" "cpp" ${GENERATOR_EXEC_ARGS}) @@ -267,13 +267,13 @@ function(halide_library_from_generator BASENAME) set_target_properties("${RUNGEN}" PROPERTIES EXCLUDE_FROM_ALL TRUE) # BASENAME.run simply runs the BASENAME.rungen target - add_custom_target("${BASENAME}.run" + add_custom_target("${BASENAME}.run" COMMAND "${RUNGEN}" "${RUNARGS}" DEPENDS "${RUNGEN}") set_target_properties("${BASENAME}.run" PROPERTIES EXCLUDE_FROM_ALL TRUE) endfunction() -# Rule to build and use a Generator; it's convenient sugar around +# Rule to build and use a Generator; it's convenient sugar around # halide_generator() + halide_library_from_generator(). function(halide_library NAME) set(oneValueArgs FUNCTION_NAME HALIDE_TARGET GENERATOR GENERATOR_NAME) @@ -301,7 +301,7 @@ function(halide_library NAME) EXTRA_OUTPUTS ${args_EXTRA_OUTPUTS}) endfunction() -# ----------------------- Private Functions. +# ----------------------- Private Functions. # All functions, properties, variables, etc. that being with an underscore # should be assumed to be private implementation details; don't rely on them externally. @@ -345,7 +345,7 @@ function(_halide_add_target_features HALIDE_TARGET HALIDE_FEATURES OUTVAR) list(APPEND NEW_T ${F}) endforeach() string(REPLACE ";" "-" NEW_T "${NEW_T}") - _halide_canonicalize_target("${NEW_T}" NEW_T) + _halide_canonicalize_target("${NEW_T}" NEW_T) list(APPEND NEW_MULTITARGETS ${NEW_T}) endforeach() string(REPLACE ";" "," NEW_MULTITARGETS "${NEW_MULTITARGETS}") @@ -437,19 +437,19 @@ function(_halide_runtime_target_name HALIDE_TARGET OUTVAR) # Windows systems still have limits of 260-character pathnames in # lots of situations, and CMake can replicate project names multiple times # in the same path, so long target strings can cause us to overflow - # this limit, even if CMAKE_OBJECT_PATH_MAX is set. So here we make + # this limit, even if CMAKE_OBJECT_PATH_MAX is set. So here we make # algorithmically-generated abbreviations for all the feature strings # and use those for external cmaketarget/filenames. # Halide Target Features we know about. (This need not be exact, but should # be close for best compression.) - list(APPEND KNOWN_FEATURES armv7s avx avx2 avx512 avx512_cannonlake avx512_knl - avx512_skylake c_plus_plus_name_mangling cl_doubles cuda cuda_capability_30 - cuda_capability_32 cuda_capability_35 cuda_capability_50 cuda_capability_61 - debug f16c fma fma4 fuzz_float_stores hvx_128 hvx_64 hvx_shared_object - hvx_v62 hvx_v65 hvx_v66 jit large_buffers matlab metal mingw msan no_asserts - no_bounds_query no_neon no_runtime opencl opengl openglcompute - power_arch_2_07 profile soft_float_abi sse41 trace_loads trace_realizations + list(APPEND KNOWN_FEATURES armv7s avx avx2 avx512 avx512_cannonlake avx512_knl + avx512_skylake c_plus_plus_name_mangling cl_doubles cuda cuda_capability_30 + cuda_capability_32 cuda_capability_35 cuda_capability_50 cuda_capability_61 + debug f16c fma fma4 fuzz_float_stores hvx_128 hvx_64 hvx_shared_object + hvx_v62 hvx_v65 hvx_v66 jit large_buffers matlab metal mingw msan no_asserts + no_bounds_query no_neon no_runtime opencl opengl openglcompute + power_arch_2_07 profile soft_float_abi sse41 trace_loads trace_realizations trace_stores user_context vsx) # Synthesize a one-or-two-char abbreviation based on the feature's position # in the KNOWN_FEATURES list. @@ -509,11 +509,11 @@ function(_halide_library_runtime HALIDE_TARGET OUTVAR) ) # By default, IMPORTED libraries are only visible to the declaration - # directories (and subdirectories); since runtime libraries are declared + # directories (and subdirectories); since runtime libraries are declared # lazily, we need to ensure they are globally visible to avoid ordering issues. add_library("${RUNTIME_NAME}" STATIC IMPORTED GLOBAL) add_dependencies("${RUNTIME_NAME}" "${RUNTIME_NAME}_runtime_gen") - set_target_properties("${RUNTIME_NAME}" PROPERTIES + set_target_properties("${RUNTIME_NAME}" PROPERTIES IMPORTED_LOCATION "${GENFILES_DIR}/${RUNTIME_LIB}") # It's hard to force specific system libraries to the end of link order @@ -539,11 +539,11 @@ function(_halide_library_runtime HALIDE_TARGET OUTVAR) endif() endif() - set_target_properties("${RUNTIME_NAME}" PROPERTIES + set_target_properties("${RUNTIME_NAME}" PROPERTIES INTERFACE_LINK_LIBRARIES "${RT_LIBS}") endif() - set(${OUTVAR} "${RUNTIME_NAME}" PARENT_SCOPE) + set(${OUTVAR} "${RUNTIME_NAME}" PARENT_SCOPE) endfunction() function(_halide_add_exec_generator_target EXEC_TARGET) @@ -575,11 +575,11 @@ function(_halide_add_exec_generator_target EXEC_TARGET) endforeach() endfunction() -# We need to ensure that some libraries are linked in with --whole-archive -# (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: -function(_halide_link_whole_archive EXECUTABLE LIBRARY) +function(_halide_force_link_library EXECUTABLE LIBRARY) + # We need to ensure that some libraries are linked in with --whole-archive + # (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: if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") _halide_get_static_library_actual_path("${LIBRARY}" LIBRARY_ACTUAL_PATH) target_link_libraries("${EXECUTABLE}" PRIVATE "${LIBRARY}") @@ -605,8 +605,8 @@ endfunction() # If paths to tools, include, and libHalide aren't specified, infer them # based on the path to the distrib folder. If the path to the distrib # folder isn't specified, fail. -if("${HALIDE_TOOLS_DIR}" STREQUAL "" OR - "${HALIDE_INCLUDE_DIR}" STREQUAL "" OR +if("${HALIDE_TOOLS_DIR}" STREQUAL "" OR + "${HALIDE_INCLUDE_DIR}" STREQUAL "" OR "${HALIDE_COMPILER_LIB}" STREQUAL "") if("${HALIDE_DISTRIB_DIR}" STREQUAL "") message(FATAL_ERROR "HALIDE_DISTRIB_DIR must point to the Halide distribution directory.") @@ -616,14 +616,14 @@ if("${HALIDE_TOOLS_DIR}" STREQUAL "" OR if(${HALIDE_DISTRIB_USE_STATIC_LIBRARY}) message(STATUS "Using ${HALIDE_DISTRIB_DIR}/lib/libHalide${CMAKE_STATIC_LIBRARY_SUFFIX}") add_library(_halide_compiler_lib STATIC IMPORTED) - set_target_properties(_halide_compiler_lib PROPERTIES + set_target_properties(_halide_compiler_lib PROPERTIES IMPORTED_LOCATION "${HALIDE_DISTRIB_DIR}/lib/libHalide${CMAKE_STATIC_LIBRARY_SUFFIX}" INTERFACE_INCLUDE_DIRECTORIES ${HALIDE_INCLUDE_DIR}) set(HALIDE_COMPILER_LIB _halide_compiler_lib) else() message(STATUS "Using ${HALIDE_DISTRIB_DIR}/bin/libHalide${CMAKE_SHARED_LIBRARY_SUFFIX}") add_library(_halide_compiler_lib SHARED IMPORTED) - set_target_properties(_halide_compiler_lib PROPERTIES + set_target_properties(_halide_compiler_lib PROPERTIES IMPORTED_LOCATION "${HALIDE_DISTRIB_DIR}/bin/libHalide${CMAKE_SHARED_LIBRARY_SUFFIX}" INTERFACE_INCLUDE_DIRECTORIES ${HALIDE_INCLUDE_DIR}) set(HALIDE_COMPILER_LIB _halide_compiler_lib) From c7f480fc5dbfa0b87af28c733f2c8bc067e7af36 Mon Sep 17 00:00:00 2001 From: Steven Johnson Date: Fri, 28 Jun 2019 15:01:22 -0700 Subject: [PATCH 03/10] Update .gitignore --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 6afc31c386fe..1a12dcc6bed3 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,8 @@ build-64/* build-ios/* build-osx/* cmake_build/* +cmake_build_shared/* +cmake_build_static/* */build/* tmp/* doc/* From fefaec0e93db1d2870dc59413c632daa6041b09e Mon Sep 17 00:00:00 2001 From: Steven Johnson Date: Fri, 28 Jun 2019 15:08:58 -0700 Subject: [PATCH 04/10] Reduce delta --- halide.cmake | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/halide.cmake b/halide.cmake index 19e1410d4bc6..a2a4facda5cb 100644 --- a/halide.cmake +++ b/halide.cmake @@ -53,6 +53,10 @@ function(halide_generator NAME) 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_SYSTEM_LIBS} ${CMAKE_DL_LIBS} ${CMAKE_THREAD_LIBS_INIT}) + if (MSVC) + target_link_libraries("${NAME}_binary" PRIVATE Kernel32) + endif() list(LENGTH args_SRCS SRCSLEN) # Don't create an empty object-library: that can cause quiet failures in MSVC builds. @@ -73,11 +77,6 @@ function(halide_generator NAME) _halide_force_link_library("${NAME}_binary" "${GENLIB}") endif() - 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() - if ("${HALIDE_LIBRARY_TYPE}" STREQUAL "STATIC") # Getting link order correct for static libraries is nearly impossible in CMake; # to avoid flakiness, always link libHalide via --whole-archive From 3363669728be0082ecb46cff96be4d1fc32c2376 Mon Sep 17 00:00:00 2001 From: Steven Johnson Date: Fri, 28 Jun 2019 15:42:20 -0700 Subject: [PATCH 05/10] Add HALIDE_SHARED_LIBRARY=0 to travis --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index d11d719aa9e3..3b8b929741e8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -20,6 +20,7 @@ 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=0 # # llvm7 prebuilts are cranky on Travis and give flaky failures; we just skipped them # in Trusty and continue to skip them in Xenial. From 3c90cfaf538f3ce95f68622266a59bfd8cf44b1e Mon Sep 17 00:00:00 2001 From: Steven Johnson Date: Fri, 28 Jun 2019 15:45:47 -0700 Subject: [PATCH 06/10] Revert the -fvis=hidden stuff --- src/CMakeLists.txt | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b8d0f0bba282..2c421e5fb0b5 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -622,9 +622,6 @@ target_compile_options(Halide PUBLIC $<$:/MP>) # Define Halide_SHARED or Halide_STATIC depending on library type target_compile_definitions(Halide PRIVATE "-DHalide_${HALIDE_LIBRARY_TYPE}") -# Default to not exporting symbols from libHalide -set_target_properties(Halide PROPERTIES CXX_VISIBILITY_PRESET hidden VISIBILITY_INLINES_HIDDEN 1) - # Ensure that these tools are build first add_dependencies(Halide binary2cpp From a10d820e3d6e6de4a3cd29e0efa565f6808ce723 Mon Sep 17 00:00:00 2001 From: Steven Johnson Date: Fri, 28 Jun 2019 15:53:11 -0700 Subject: [PATCH 07/10] Update CMakeLists.txt --- src/CMakeLists.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 2c421e5fb0b5..f8f9a3bf48d9 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -621,7 +621,6 @@ target_compile_options(Halide PUBLIC $<$:/MP>) # Define Halide_SHARED or Halide_STATIC depending on library type target_compile_definitions(Halide PRIVATE "-DHalide_${HALIDE_LIBRARY_TYPE}") - # Ensure that these tools are build first add_dependencies(Halide binary2cpp From 481ffbb9b7c422b09288513d0066772c5a3820f0 Mon Sep 17 00:00:00 2001 From: Steven Johnson Date: Mon, 8 Jul 2019 13:21:21 -0700 Subject: [PATCH 08/10] Update .travis.yml --- .travis.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 3b8b929741e8..96aab79b347a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 # From 3f7314247328da05c9edafd7c6262cfeb2c12023 Mon Sep 17 00:00:00 2001 From: Steven Johnson Date: Wed, 10 Jul 2019 15:40:19 -0700 Subject: [PATCH 09/10] fixes --- .gitignore | 4 +--- .travis.yml | 4 ++-- CMakeLists.txt | 11 +++-------- apps/linear_algebra/tests/CMakeLists.txt | 2 +- halide.cmake | 8 +++----- test/CMakeLists.txt | 9 +++++---- 6 files changed, 15 insertions(+), 23 deletions(-) diff --git a/.gitignore b/.gitignore index 1a12dcc6bed3..905c6333a93d 100644 --- a/.gitignore +++ b/.gitignore @@ -8,9 +8,7 @@ python_bindings/bin/* build-64/* build-ios/* build-osx/* -cmake_build/* -cmake_build_shared/* -cmake_build_static/* +cmake_build*/* */build/* tmp/* doc/* diff --git a/.travis.yml b/.travis.yml index 96aab79b347a..842cd67983d6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -20,8 +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=0 + - 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. diff --git a/CMakeLists.txt b/CMakeLists.txt index abf83b9ebf69..a1397b1b642e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -57,10 +57,6 @@ set(CMAKE_CXX_EXTENSIONS OFF) set(CMAKE_MACOSX_RPATH ON) -# Allow VISIBILITY_INLINES_HIDDEN to work for static libraries as well as shared -# (since these may later be linked into dynamic libraries). Requires CMake 3.3+. -cmake_policy(SET CMP0063 NEW) - # Export all symbols SET(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON) @@ -336,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}") @@ -374,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) @@ -437,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 . @@ -471,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 .) diff --git a/apps/linear_algebra/tests/CMakeLists.txt b/apps/linear_algebra/tests/CMakeLists.txt index d7def1e7c554..cc02eb0a4f96 100644 --- a/apps/linear_algebra/tests/CMakeLists.txt +++ b/apps/linear_algebra/tests/CMakeLists.txt @@ -20,6 +20,6 @@ target_link_libraries(test_halide_blas PRIVATE halide_blas cblas # XXX fragile - Halide + ${HALIDE_COMPILER_LIB} ) diff --git a/halide.cmake b/halide.cmake index 0561a9f85bd7..eece8ff5e11d 100644 --- a/halide.cmake +++ b/halide.cmake @@ -2,9 +2,6 @@ include(CMakeParseArguments) cmake_minimum_required(VERSION 3.3) -# Allow VISIBILITY_INLINES_HIDDEN to work for static libraries as well as shared. Requires CMake 3.3+. -cmake_policy(SET CMP0063 NEW) - # ----------------------- Public Functions. # These are all documented in README_cmake.md. # @@ -52,7 +49,7 @@ 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_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) @@ -77,7 +74,8 @@ function(halide_generator NAME) _halide_force_link_library("${NAME}_binary" "${GENLIB}") endif() - if ("${HALIDE_LIBRARY_TYPE}" STREQUAL "STATIC") + 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. diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 272c262214cc..599e8ad11698 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -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() @@ -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() From d0c640b57822e38ae5a1b171fbf75975612eccad Mon Sep 17 00:00:00 2001 From: Steven Johnson Date: Wed, 10 Jul 2019 17:06:04 -0700 Subject: [PATCH 10/10] Limit travis tests for static --- test/scripts/build_travis.sh | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/test/scripts/build_travis.sh b/test/scripts/build_travis.sh index d023a32c07b1..819d0bb60f96 100755 --- a/test/scripts/build_travis.sh +++ b/test/scripts/build_travis.sh @@ -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 @@ -56,3 +60,4 @@ else echo "Unexpected BUILD_SYSTEM: \"${BUILD_SYSTEM}\"" exit 1 fi +