mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2024-11-27 07:31:28 +00:00
cbaa3597aa
This reverts commitd763c6e5e2
. Adds the patch by @hans from https://github.com/llvm/llvm-project/issues/62719 This patch fixes the Windows build.d763c6e5e2
reverted the reviews D144509 [CMake] Bumps minimum version to 3.20.0. This partly undoes D137724. This change has been discussed on discourse https://discourse.llvm.org/t/rfc-upgrading-llvms-minimum-required-cmake-version/66193 Note this does not remove work-arounds for older CMake versions, that will be done in followup patches. D150532 [OpenMP] Compile assembly files as ASM, not C Since CMake 3.20, CMake explicitly passes "-x c" (or equivalent) when compiling a file which has been set as having the language C. This behaviour change only takes place if "cmake_minimum_required" is set to 3.20 or newer, or if the policy CMP0119 is set to new. Attempting to compile assembly files with "-x c" fails, however this is workarounded in many cases, as OpenMP overrides this with "-x assembler-with-cpp", however this is only added for non-Windows targets. Thus, after increasing cmake_minimum_required to 3.20, this breaks compiling the GNU assembly for Windows targets; the GNU assembly is used for ARM and AArch64 Windows targets when building with Clang. This patch unbreaks that. D150688 [cmake] Set CMP0091 to fix Windows builds after the cmake_minimum_required bump The build uses other mechanism to select the runtime. Fixes #62719 Reviewed By: #libc, Mordante Differential Revision: https://reviews.llvm.org/D151344
165 lines
4.9 KiB
CMake
165 lines
4.9 KiB
CMake
# Check if this is a in tree build.
|
|
if (NOT DEFINED LLVM_MAIN_SRC_DIR)
|
|
project(Polly)
|
|
cmake_minimum_required(VERSION 3.20.0)
|
|
set(POLLY_STANDALONE_BUILD TRUE)
|
|
endif()
|
|
|
|
# Must go below project(..)
|
|
include(GNUInstallDirs)
|
|
|
|
if(POLLY_STANDALONE_BUILD)
|
|
# Where is LLVM installed?
|
|
find_package(LLVM CONFIG REQUIRED)
|
|
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${LLVM_CMAKE_DIR})
|
|
include(HandleLLVMOptions)
|
|
include(AddLLVM)
|
|
|
|
# Add the llvm header path.
|
|
include_directories(${LLVM_INCLUDE_DIRS})
|
|
|
|
# Sources available, too?
|
|
if (LLVM_BUILD_MAIN_SRC_DIR)
|
|
set(default_llvm_src "${LLVM_BUILD_MAIN_SRC_DIR}")
|
|
else()
|
|
set(default_llvm_src "${CMAKE_CURRENT_SOURCE_DIR}/../llvm")
|
|
endif()
|
|
set(LLVM_SOURCE_ROOT ${default_llvm_src} CACHE PATH "Path to LLVM source tree")
|
|
|
|
# Enable unit tests if available.
|
|
set(POLLY_GTEST_AVAIL 0)
|
|
set(UNITTEST_DIR ${LLVM_THIRD_PARTY_DIR}/unittest)
|
|
if(EXISTS ${UNITTEST_DIR}/googletest/include/gtest/gtest.h)
|
|
if (NOT TARGET gtest)
|
|
add_subdirectory(${UNITTEST_DIR} third-party/unittest)
|
|
endif()
|
|
set(POLLY_GTEST_AVAIL 1)
|
|
endif()
|
|
|
|
if (LLVM_ENABLE_PIC)
|
|
# Make sure the isl c files are built as fPIC if possible
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
|
|
endif ()
|
|
|
|
# Set directory for polly-isl-test.
|
|
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/bin")
|
|
else ()
|
|
set(LLVM_SOURCE_ROOT "${LLVM_MAIN_SRC_DIR}")
|
|
set(POLLY_GTEST_AVAIL 1)
|
|
endif ()
|
|
|
|
set(POLLY_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
|
|
set(POLLY_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
|
|
|
|
if(NOT DEFINED LLVM_COMMON_CMAKE_UTILS)
|
|
set(LLVM_COMMON_CMAKE_UTILS ${POLLY_SOURCE_DIR}/../cmake)
|
|
endif()
|
|
|
|
# Make sure that our source directory is on the current cmake module path so that
|
|
# we can include cmake files from this directory.
|
|
list(INSERT CMAKE_MODULE_PATH 0
|
|
"${POLLY_SOURCE_DIR}/cmake"
|
|
"${LLVM_COMMON_CMAKE_UTILS}/Modules"
|
|
)
|
|
|
|
include("polly_macros")
|
|
|
|
# Add appropriate flags for GCC
|
|
if (CMAKE_COMPILER_IS_GNUCXX)
|
|
# FIXME: Turn off exceptions, RTTI:
|
|
# -fno-exceptions -fno-rtti
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-common -Woverloaded-virtual -Wno-long-long -Wall -W -Wno-unused-parameter -Wwrite-strings -fno-exceptions -fno-rtti")
|
|
elseif (MSVC)
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHs-c-")
|
|
add_definitions("-D_HAS_EXCEPTIONS=0")
|
|
else ()
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions -fno-rtti")
|
|
endif ()
|
|
|
|
SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
|
|
|
|
option(POLLY_BUNDLED_ISL "Use the bundled version of libisl included in Polly" ON)
|
|
if (NOT POLLY_BUNDLED_ISL)
|
|
find_package(ISL MODULE REQUIRED)
|
|
message(STATUS "Using external libisl ${ISL_VERSION} in: ${ISL_PREFIX}")
|
|
set(ISL_TARGET ISL)
|
|
else()
|
|
set(ISL_INCLUDE_DIRS
|
|
${CMAKE_CURRENT_BINARY_DIR}/lib/External/isl/include
|
|
${CMAKE_CURRENT_SOURCE_DIR}/lib/External/isl/include
|
|
)
|
|
set(ISL_TARGET PollyISL)
|
|
endif()
|
|
|
|
include_directories(
|
|
BEFORE
|
|
${CMAKE_CURRENT_SOURCE_DIR}/include
|
|
${ISL_INCLUDE_DIRS}
|
|
${CMAKE_CURRENT_SOURCE_DIR}/lib/External/pet/include
|
|
${CMAKE_CURRENT_SOURCE_DIR}/lib/External
|
|
${CMAKE_CURRENT_BINARY_DIR}/include
|
|
)
|
|
|
|
if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
|
|
install(DIRECTORY include/
|
|
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
|
|
FILES_MATCHING
|
|
PATTERN "*.h"
|
|
)
|
|
|
|
install(DIRECTORY ${POLLY_BINARY_DIR}/include/
|
|
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
|
|
FILES_MATCHING
|
|
PATTERN "*.h"
|
|
PATTERN "CMakeFiles" EXCLUDE
|
|
)
|
|
endif()
|
|
|
|
add_definitions( -D_GNU_SOURCE )
|
|
|
|
add_subdirectory(docs)
|
|
add_subdirectory(lib)
|
|
add_subdirectory(test)
|
|
if (POLLY_GTEST_AVAIL)
|
|
add_subdirectory(unittests)
|
|
endif ()
|
|
add_subdirectory(cmake)
|
|
# TODO: docs.
|
|
|
|
|
|
configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/include/polly/Config/config.h.cmake
|
|
${POLLY_BINARY_DIR}/include/polly/Config/config.h )
|
|
|
|
# Add target to check formatting of polly files
|
|
file( GLOB_RECURSE files *.h lib/*.cpp lib/*.c tools/*.cpp tools/*.c tools/*.h unittests/*.cpp)
|
|
file( GLOB_RECURSE external lib/External/*.h lib/External/*.c lib/External/*.cpp isl_config.h)
|
|
list( REMOVE_ITEM files ${external})
|
|
|
|
set(check_format_depends)
|
|
set(update_format_depends)
|
|
set(i 0)
|
|
foreach (file IN LISTS files)
|
|
add_custom_command(OUTPUT polly-check-format${i}
|
|
COMMAND clang-format -sort-includes -style=llvm ${file} | diff -u ${file} -
|
|
VERBATIM
|
|
COMMENT "Checking format of ${file}..."
|
|
)
|
|
list(APPEND check_format_depends "polly-check-format${i}")
|
|
|
|
add_custom_command(OUTPUT polly-update-format${i}
|
|
COMMAND clang-format -sort-includes -i -style=llvm ${file}
|
|
VERBATIM
|
|
COMMENT "Updating format of ${file}..."
|
|
)
|
|
list(APPEND update_format_depends "polly-update-format${i}")
|
|
|
|
math(EXPR i ${i}+1)
|
|
endforeach ()
|
|
|
|
add_custom_target(polly-check-format DEPENDS ${check_format_depends})
|
|
set_target_properties(polly-check-format PROPERTIES FOLDER "Polly")
|
|
|
|
add_custom_target(polly-update-format DEPENDS ${update_format_depends})
|
|
set_target_properties(polly-update-format PROPERTIES FOLDER "Polly")
|
|
|