diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a21f62a3f..bd4556bac 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -356,7 +356,7 @@ jobs: - uses: actions/checkout@v2 - name: all env: - BUILDTARGET: clang-format + BUILDTARGET: osl-clang-format CMAKE_CXX_STANDARD: 17 PYTHON_VERSION: 3.7 SKIP_TESTS: 1 diff --git a/src/cmake/compiler.cmake b/src/cmake/compiler.cmake index 99aecb8a5..fa095bb74 100644 --- a/src/cmake/compiler.cmake +++ b/src/cmake/compiler.cmake @@ -469,7 +469,7 @@ if (CLANG_FORMAT_EXE) # message (STATUS "clang-format file list: ${FILES_TO_FORMAT}") file (COPY ${CMAKE_CURRENT_SOURCE_DIR}/.clang-format DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) - add_custom_target (clang-format + add_custom_target (osl-clang-format COMMAND "${CLANG_FORMAT_EXE}" -i -style=file ${FILES_TO_FORMAT} ) else () message (STATUS "clang-format not found.") diff --git a/src/cmake/externalpackages.cmake b/src/cmake/externalpackages.cmake index db9e4d79e..090e6393a 100644 --- a/src/cmake/externalpackages.cmake +++ b/src/cmake/externalpackages.cmake @@ -100,19 +100,59 @@ checked_find_package (pugixml 1.8 REQUIRED) # LLVM library setup -checked_find_package (LLVM 7.0 REQUIRED - PRINT LLVM_SYSTEM_LIBRARIES CLANG_LIBRARIES) -# ensure include directory is added (in case of non-standard locations -include_directories (BEFORE SYSTEM "${LLVM_INCLUDES}") -link_directories ("${LLVM_LIB_DIR}") + +############ HACK ############## +# On OSX, the Homebrew (and maybe any build) of LLVM 10.0 seems to have a +# link conflict with its dependency on the llvm libc++ and the system +# libc++, both can end up dynamically linked and lead to very subtle and +# frustrating behavior failures (in particular, osl's use of libclang will +# botch include file parsing any time LD_LIBRARY_PATH doesn't have the llvm +# libc++ first). +# +# It seems that this is not a problem when linking against the llvm and +# libclang libraries statically. So on apple and when LLVM 10+ are involved, +# just force that choice. Other than larger executables, it seems harmless, +# and in any case a better choice than this beastly bug. +# +# We can periodically revisit this with new version of LLVM, maybe they will +# fix things and we won't require this preemptive static linking. +if (APPLE AND LLVM_VERSION VERSION_GREATER_EQUAL 10.0) + set (LLVM_STATIC ON) +endif () + +checked_find_package(LLVM REQUIRED CONFIG + HINTS ${LLVM_DIRECTORY}) + +# manual version check because "LLVM is API-compatible only with matching major.minor versions" aka it requires VERSION_EQUAL +if ( ${LLVM_PACKAGE_VERSION} VERSION_LESS 7 ) + message(FATAL_ERROR "LLVM 7.0+ is required but ${LLVM_PACKAGE_VERSION} was found") +endif() + +include_directories(BEFORE SYSTEM ${LLVM_INCLUDE_DIRS}) +add_definitions(${LLVM_DEFINITIONS}) +link_directories(${LLVM_LIBRARY_DIRS}) + +llvm_map_components_to_libnames(LLVM_LIBRARIES + MCJIT Passes + ${LLVM_TARGETS_TO_BUILD}) #this will link with all LLVM targets (x86, nvptx, ...) specific libraries (codegen, dissasembly,...) + # Extract and concatenate major & minor, remove wayward patches, # dots, and "svn" or other suffixes. -string (REGEX REPLACE "([0-9]+)\\.([0-9]+).*" "\\1\\2" OSL_LLVM_VERSION ${LLVM_VERSION}) +string (REGEX REPLACE "([0-9]+)\\.([0-9]+).*" "\\1\\2" OSL_LLVM_VERSION ${LLVM_PACKAGE_VERSION}) add_definitions (-DOSL_LLVM_VERSION=${OSL_LLVM_VERSION}) -add_definitions (-DOSL_LLVM_FULL_VERSION="${LLVM_VERSION}") +add_definitions (-DOSL_LLVM_FULL_VERSION="${LLVM_PACKAGE_VERSION}") if (LLVM_NAMESPACE) - add_definitions ("-DLLVM_NAMESPACE=${LLVM_NAMESPACE}") + add_definitions ("-DLLVM_NAMESPACE=${LLVM_NAMESPACE}") endif () +if (NOT LLVM_DIRECTORY) + set(LLVM_DIRECTORY ${LLVM_INSTALL_PREFIX}) +endif() +set(LLVM_TARGETS ${LLVM_TARGETS_TO_BUILD}) + +checked_find_package(Clang REQUIRED) +include_directories(BEFORE SYSTEM ${CLANG_INCLUDE_DIRS}) +set(CLANG_LIBRARIES clangCrossTU) # TODO figure out what exactly we need (this seems to work though it might be overkill) + if (LLVM_VERSION VERSION_GREATER_EQUAL 10.0.0 AND CMAKE_CXX_STANDARD VERSION_LESS 14) message (FATAL_ERROR @@ -135,6 +175,8 @@ if (APPLE AND LLVM_VERSION VERSION_EQUAL 10.0.1 AND EXISTS "/usr/local/Cellar/ll "${ColorReset}\n") endif () + +# partio checked_find_package (partio) diff --git a/src/cmake/modules/FindLLVM.cmake b/src/cmake/modules/FindLLVM.cmake deleted file mode 100644 index b49a1f934..000000000 --- a/src/cmake/modules/FindLLVM.cmake +++ /dev/null @@ -1,152 +0,0 @@ -# Copyright Contributors to the Open Shading Language project. -# SPDX-License-Identifier: BSD-3-Clause -# https://github.com/imageworks/OpenShadingLanguage - -# Module to find LLVM -# -# This module defines the following variables: -# LLVM_FOUND - True if llvm found. -# LLVM_VERSION - Full LLVM version -# LLVM_INCLUDES - where to find llvm headers -# LLVM_LIBRARIES - List of LLVM libraries to link against -# LLVM_SYSTEM_LIBRARIES - additional libraries needed by LLVM -# LLVM_DIRECTORY - If not already set, the root of the LLVM install -# LLVM_LIB_DIR - where to find llvm libs -# LLVM_TARGETS - List of available LLVM targets -# CLANG_LIBRARIES - list of libraries for clang components (optional, -# those may not be found) -# -# The following input symbols may be used to help guide the search: -# LLVM_DIRECTORY - the root of the LLVM installation (if custom) -# LLVM_FIND_QUIETLY - if true, will suppress most console output -# LLVM_STATIC - if true, will prefer static LLVM libs to dynamic - -# try to find llvm-config, with a specific version if specified -if (LLVM_DIRECTORY) - set (LLVM_CONFIG_PATH_HINTS "${LLVM_DIRECTORY}/bin") -endif () -list (APPEND LLVM_CONFIG_PATH_HINTS - "/usr/local/opt/llvm/${LLVM_VERSION}/bin/" - "/usr/local/opt/llvm/bin/") -find_program (LLVM_CONFIG - NAMES llvm-config-${LLVM_VERSION} llvm-config - llvm-config-64-${LLVM_VERSION} llvm-config-64 - HINTS ${LLVM_CONFIG_PATH_HINTS} NO_DEFAULT_PATH) -find_program (LLVM_CONFIG - NAMES llvm-config-${LLVM_VERSION} llvm-config - llvm-config-64-${LLVM_VERSION} llvm-config-64 - HINTS ${LLVM_CONFIG_PATH_HINTS}) -if (NOT LLVM_FIND_QUIETLY) - message (STATUS "Found llvm-config '${LLVM_CONFIG}'") -endif () - -if (NOT LLVM_DIRECTORY) - execute_process (COMMAND ${LLVM_CONFIG} --prefix - OUTPUT_VARIABLE LLVM_DIRECTORY - OUTPUT_STRIP_TRAILING_WHITESPACE) -endif() - -execute_process (COMMAND ${LLVM_CONFIG} --version - OUTPUT_VARIABLE LLVM_VERSION - OUTPUT_STRIP_TRAILING_WHITESPACE) -execute_process (COMMAND ${LLVM_CONFIG} --libdir - OUTPUT_VARIABLE LLVM_LIB_DIR - OUTPUT_STRIP_TRAILING_WHITESPACE) -execute_process (COMMAND ${LLVM_CONFIG} --includedir - OUTPUT_VARIABLE LLVM_INCLUDES - OUTPUT_STRIP_TRAILING_WHITESPACE) -execute_process (COMMAND ${LLVM_CONFIG} --targets-built - OUTPUT_VARIABLE LLVM_TARGETS - OUTPUT_STRIP_TRAILING_WHITESPACE) -execute_process (COMMAND ${LLVM_CONFIG} --system-libs - OUTPUT_VARIABLE LLVM_SYSTEM_LIBRARIES - OUTPUT_STRIP_TRAILING_WHITESPACE) -string (REPLACE " " ";" LLVM_SYSTEM_LIBRARIES "${LLVM_SYSTEM_LIBRARIES}") - -find_library ( LLVM_LIBRARY - NAMES LLVM-${LLVM_VERSION} LLVM - PATHS ${LLVM_LIB_DIR}) -find_library ( LLVM_MCJIT_LIBRARY - NAMES LLVMMCJIT - PATHS ${LLVM_LIB_DIR}) - -if (NOT LLVM_LIBRARY) - # if no single library was found, use llvm-config to generate the list - # of what libraries we need, and substitute that in the right way for - # LLVM_LIBRARY. - execute_process (COMMAND ${LLVM_CONFIG} --libfiles - OUTPUT_VARIABLE LLVM_LIBRARIES - OUTPUT_STRIP_TRAILING_WHITESPACE) - string (REPLACE " " ";" LLVM_LIBRARIES "${LLVM_LIBRARIES}") - set (LLVM_LIBRARY "${LLVM_LIBRARIES}") -endif () - -execute_process (COMMAND ${LLVM_CONFIG} --shared-mode - OUTPUT_VARIABLE LLVM_SHARED_MODE - OUTPUT_STRIP_TRAILING_WHITESPACE) -if (LLVM_VERSION VERSION_GREATER_EQUAL 9.0 AND (LLVM_SHARED_MODE STREQUAL "shared")) - find_library ( _CLANG_CPP_LIBRARY - NAMES "clang-cpp" - PATHS ${LLVM_LIB_DIR}) - if (_CLANG_CPP_LIBRARY) - list (APPEND CLANG_LIBRARIES ${_CLANG_CPP_LIBRARY}) - endif () -endif () - -foreach (COMPONENT clangFrontend clangDriver clangSerialization - clangParse clangSema clangAnalysis clangAST clangBasic - clangEdit clangLex) - find_library ( _CLANG_${COMPONENT}_LIBRARY - NAMES ${COMPONENT} - PATHS ${LLVM_LIB_DIR}) - if (_CLANG_${COMPONENT}_LIBRARY) - list (APPEND CLANG_LIBRARIES ${_CLANG_${COMPONENT}_LIBRARY}) - endif () -endforeach () - - -############ HACK ############## -# On OSX, the Homebrew (and maybe any build) of LLVM 10.0 seems to have a -# link conflict with its dependency on the llvm libc++ and the system -# libc++, both can end up dynamically linked and lead to very subtle and -# frustrating behavior failures (in particular, osl's use of libclang will -# botch include file parsing any time LD_LIBRARY_PATH doesn't have the llvm -# libc++ first). -# -# It seems that this is not a problem when linking against the llvm and -# libclang libraries statically. So on apple and when LLVM 10+ are involved, -# just force that choice. Other than larger executables, it seems harmless, -# and in any case a better choice than this beastly bug. -# -# We can periodically revisit this with new version of LLVM, maybe they will -# fix things and we won't require this preemptive static linking. -if (APPLE AND LLVM_VERSION VERSION_GREATER_EQUAL 10.0) - set (LLVM_STATIC ON) -endif () - -# shared llvm library may not be available, this is not an error if we use LLVM_STATIC. -if ((LLVM_LIBRARY OR LLVM_LIBRARIES OR LLVM_STATIC) AND LLVM_INCLUDES AND LLVM_DIRECTORY AND LLVM_LIB_DIR) - if (LLVM_STATIC) - # if static LLVM libraries were requested, use llvm-config to generate - # the list of what libraries we need, and substitute that in the right - # way for LLVM_LIBRARY. - execute_process (COMMAND ${LLVM_CONFIG} --libfiles --link-static - OUTPUT_VARIABLE LLVM_LIBRARIES - OUTPUT_STRIP_TRAILING_WHITESPACE) - if (LLVM_LIBRARIES) - string (REPLACE " " ";" LLVM_LIBRARIES "${LLVM_LIBRARIES}") - set (LLVM_LIBRARY "") - endif () - else () - set (LLVM_LIBRARIES "${LLVM_LIBRARY}") - endif () -endif () - - -include(FindPackageHandleStandardArgs) -find_package_handle_standard_args (LLVM - REQUIRED_VARS - LLVM_INCLUDES - LLVM_LIBRARIES - VERSION_VAR LLVM_VERSION - )