Reapplication of #137828 and #169638 Move building the .mod files from openmp/flang to openmp/flang-rt using a shared mechanism. Motivations to do so are: 1. Most modules are target-dependent and need to be re-compiled for each target separately, which is something the LLVM_ENABLE_RUNTIMES system already does. Prime example is `iso_c_binding.mod` which encodes the target's ABI. Constants such as `c_long_double` also have different values). Most other modules have `#ifdef`-enclosed code as well. For instance this caused offload targets nvptx64-nvidia-cuda/amdgpu-amd-amdhsa to use the modules files compiled for the host which may contrain uses of the types REAL(10) or REAL(16) not available for nvptx/amdgpu. 2. CMake has support for Fortran that we should use. Among other things, it automatically determines module dependencies so there is no need to hardcode them in the CMakeLists.txt. Currently the dependencies between builtin modules and `omp_lib.mod` seem to be incorrect: https://github.com/llvm/llvm-project/pull/174474#issuecomment-3880189581 3. It allows using Fortran itself to implement Flang-RT. Currently, only `iso_fortran_env_impl.f90` emits object files that are needed by Fortran applications (#89403). The workaround of #95388 could be reverted (PR #169525). If using Flang for cross-compilation or target-offloading, flang-rt must now be compiled for each target not only for the library, but also to get the target-specific module files. For instance in a bootstrapping runtime build, this can be done by adding: `-DLLVM_RUNTIME_TARGETS=default;nvptx64-nvidia-cuda;amdgpu-amd-amdhsa`. Some new dependencies come into play: * openmp depends on flang-rt for building `lib_omp.mod` and `lib_omp_kinds.mod`. Currently, if flang-rt is not found then the modules are not built. * check-flang depends on flang-rt: If not found, the majority of tests are disabled. If not building in a bootstrpping build, the location of the module files can be pointed to using `-DFLANG_INTRINSIC_MODULES_DIR=<path>`, e.g. in a flang-standalone build. Alternatively, the test needing any of the intrinsic modules could be marked with `REQUIRES: flangrt-modules`. * check-flang depends on openmp: Not a change; tests requiring `lib_omp.mod` and `lib_omp_kinds.mod` those are already marked with `openmp_runtime`. As intrinsic are now specific to the target, their location is moved from `include/flang` to `<resource-dir>/finclude/flang/<triple>`. The mechnism to compute the location have been moved from flang-rt (previously used to compute the location of `libflang_rt.*.a`) to common locations in `cmake/GetToolchainDirs.cmake` and `runtimes/CMakeLists.txt` so they can be used by both, openmp and flang-rt. Potentially the mechnism could also be shared by other libraries such as compiler-rt. `finclude` was chosen because `gfortran` uses it as well and avoids misuse such as `#include <flang/iso_c_binding.mod>`. The search location is now determined by `ToolChain` in the driver, instead of by the frontend. Another subdirectory `flang` avoids accidental inclusion of gfortran-modules which due to compression would result in user-unfriendly errors. Now the driver adds `-fintrinsic-module-path` for that location to the frontend call (Just like gfortran does). Since the driver determines the location, tests invoking `flang -fc1` and `bbc` must also be passed the location by llvm-lit. This works like llvm-lit does for finding the include dirs for Clang using `-print-file-name=...`.
591 lines
21 KiB
CMake
591 lines
21 KiB
CMake
cmake_minimum_required(VERSION 3.20.0)
|
|
set(LLVM_SUBPROJECT_TITLE "Flang")
|
|
|
|
if(NOT DEFINED LLVM_COMMON_CMAKE_UTILS)
|
|
set(LLVM_COMMON_CMAKE_UTILS ${CMAKE_CURRENT_SOURCE_DIR}/../cmake)
|
|
endif()
|
|
include(${LLVM_COMMON_CMAKE_UTILS}/Modules/CMakePolicy.cmake
|
|
NO_POLICY_SCOPE)
|
|
|
|
set(CMAKE_BUILD_WITH_INSTALL_NAME_DIR ON)
|
|
|
|
# Flang requires C++17.
|
|
set(CMAKE_CXX_STANDARD 17)
|
|
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
|
|
set(CMAKE_CXX_EXTENSIONS OFF)
|
|
|
|
if (LLVM_ENABLE_EH)
|
|
# To match with the flang guidelines we currently disable
|
|
# building with exception support in core LLVM.
|
|
message(FATAL_ERROR "Flang does not currently support building with \
|
|
LLVM exceptions enabled. Please disable LLVM_ENABLE_EH when building \
|
|
flang.")
|
|
endif()
|
|
|
|
set(FLANG_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
|
|
|
|
# Python is needed for symbol extracting tool
|
|
set(LLVM_MINIMUM_PYTHON_VERSION 3.8)
|
|
find_package(Python3 ${LLVM_MINIMUM_PYTHON_VERSION} REQUIRED
|
|
COMPONENTS Interpreter)
|
|
|
|
if (CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR AND NOT MSVC_IDE)
|
|
message(FATAL_ERROR "In-source builds are not allowed. \
|
|
Please create a directory and run cmake from there,\
|
|
passing the path to this source directory as the last argument.\
|
|
This process created the file `CMakeCache.txt' and the directory\
|
|
`CMakeFiles'. Please delete them.")
|
|
endif()
|
|
|
|
option(FLANG_ENABLE_WERROR "Fail and stop building flang if a warning is triggered." OFF)
|
|
|
|
# Check for a standalone build and configure as appropriate from
|
|
# there.
|
|
if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
|
|
message("Building Flang as a standalone project.")
|
|
project(Flang)
|
|
set(FLANG_STANDALONE_BUILD ON)
|
|
else()
|
|
set(FLANG_STANDALONE_BUILD OFF)
|
|
endif()
|
|
|
|
# Must go below project(..)
|
|
include(GNUInstallDirs)
|
|
|
|
# MSVC + clang-cl build requires clang_rt.builtin.${target} library
|
|
if (MSVC AND CMAKE_CXX_COMPILER_ID MATCHES Clang)
|
|
include(HandleCompilerRT)
|
|
find_compiler_rt_library(builtins CLANG_RT_BUILTINS_LIBRARY)
|
|
get_filename_component(LIBDIR "${CLANG_RT_BUILTINS_LIBRARY}" DIRECTORY)
|
|
if (IS_DIRECTORY "${LIBDIR}")
|
|
link_libraries(${CLANG_RT_BUILTINS_LIBRARY})
|
|
endif()
|
|
|
|
if (MSVC_VERSION EQUAL 1942)
|
|
message(FATAL_ERROR "Flang cannot be built with clang and the MSVC 17.12 "
|
|
"toolchain version. Please upgrade to 17.13 or later, or switch "
|
|
"to the 17.10 LTSC release. "
|
|
"See https://github.com/microsoft/STL/issues/4959 for more details.")
|
|
endif()
|
|
endif()
|
|
|
|
if(CMAKE_SIZEOF_VOID_P EQUAL 4)
|
|
message(FATAL_ERROR "flang isn't supported on 32 bit CPUs")
|
|
endif()
|
|
|
|
set(MLIR_MAIN_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../mlir" CACHE PATH "Path to MLIR source tree")
|
|
|
|
if (FLANG_STANDALONE_BUILD)
|
|
set(FLANG_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
|
|
set(CMAKE_INCLUDE_CURRENT_DIR ON)
|
|
if (NOT MSVC_IDE)
|
|
set(LLVM_ENABLE_ASSERTIONS ${ENABLE_ASSERTIONS}
|
|
CACHE BOOL "Enable assertions")
|
|
# Assertions follow llvm's configuration.
|
|
mark_as_advanced(LLVM_ENABLE_ASSERTIONS)
|
|
endif()
|
|
|
|
# Build with _XOPEN_SOURCE on AIX to avoid errors caused by _ALL_SOURCE.
|
|
# We need to enable the large-file API as well.
|
|
if (UNIX AND CMAKE_SYSTEM_NAME MATCHES "AIX")
|
|
add_compile_definitions(_XOPEN_SOURCE=700)
|
|
add_compile_definitions(_LARGE_FILE_API)
|
|
endif()
|
|
|
|
# If the user specifies a relative path to LLVM_DIR, the calls to include
|
|
# LLVM modules fail. Append the absolute path to LLVM_DIR instead.
|
|
if (LLVM_DIR)
|
|
get_filename_component(LLVM_DIR_ABSOLUTE ${LLVM_DIR}
|
|
REALPATH BASE_DIR ${CMAKE_CURRENT_BINARY_DIR})
|
|
list(APPEND CMAKE_MODULE_PATH ${LLVM_DIR_ABSOLUTE})
|
|
endif()
|
|
# We need a pre-built/installed version of LLVM.
|
|
find_package(LLVM REQUIRED HINTS "${LLVM_DIR_ABSOLUTE}")
|
|
if (NOT LLVM_DIR_ABSOLUTE)
|
|
# If the user did not specify a LLVM_DIR (and therefore LLVM_DIR_ABSOLUTE
|
|
# was not set), append the discovered path to CMAKE_MODULE_PATH.
|
|
list(APPEND CMAKE_MODULE_PATH ${LLVM_DIR})
|
|
endif()
|
|
|
|
# Users might specify a path to CLANG_DIR that's:
|
|
# * a full path, or
|
|
# * a path relative to the path of this script.
|
|
# Append the absolute path to CLANG_DIR so that find_package works in both
|
|
# cases.
|
|
if (CLANG_DIR)
|
|
get_filename_component(
|
|
CLANG_DIR_ABSOLUTE
|
|
${CLANG_DIR}
|
|
REALPATH
|
|
BASE_DIR ${CMAKE_CURRENT_BINARY_DIR})
|
|
list(APPEND CMAKE_MODULE_PATH ${CLANG_DIR_ABSOLUTE})
|
|
|
|
# TODO: Remove when libclangDriver is lifted out of Clang
|
|
find_package(Clang REQUIRED PATHS "${CLANG_DIR_ABSOLUTE}" NO_DEFAULT_PATH)
|
|
else()
|
|
find_package(Clang REQUIRED)
|
|
list(APPEND CMAKE_MODULE_PATH ${Clang_DIR})
|
|
endif()
|
|
|
|
# If LLVM links to zlib we need the imported targets so we can too.
|
|
if(LLVM_ENABLE_ZLIB)
|
|
find_package(ZLIB REQUIRED)
|
|
endif()
|
|
option(LLVM_ENABLE_PEDANTIC "Compile with pedantic enabled." ON)
|
|
if(CMAKE_COMPILER_IS_GNUCXX)
|
|
set(USE_NO_MAYBE_UNINITIALIZED 1)
|
|
endif()
|
|
|
|
# The path is needed to locate extract_symbols.py
|
|
if (NOT DEFINED LLVM_MAIN_SRC_DIR)
|
|
set(LLVM_MAIN_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../llvm")
|
|
endif()
|
|
|
|
separate_arguments(LLVM_DEFINITIONS_LIST NATIVE_COMMAND ${LLVM_DEFINITIONS})
|
|
add_definitions(${LLVM_DEFINITIONS_LIST})
|
|
list(APPEND CMAKE_REQUIRED_DEFINITIONS ${LLVM_DEFINITIONS_LIST})
|
|
|
|
include(AddLLVM)
|
|
include(HandleLLVMOptions)
|
|
include(VersionFromVCS)
|
|
include(GetErrcMessages)
|
|
|
|
include(AddClang)
|
|
|
|
include(TableGen)
|
|
# If the user specifies a relative path to MLIR_DIR, the calls to include
|
|
# MLIR modules fail. Append the absolute path to MLIR_DIR instead.
|
|
if (MLIR_DIR)
|
|
get_filename_component(MLIR_DIR_ABSOLUTE ${MLIR_DIR}
|
|
REALPATH BASE_DIR ${CMAKE_CURRENT_BINARY_DIR})
|
|
list(APPEND CMAKE_MODULE_PATH ${MLIR_DIR_ABSOLUTE})
|
|
endif()
|
|
find_package(MLIR REQUIRED CONFIG HINTS ${MLIR_DIR_ABSOLUTE})
|
|
if (NOT MLIR_DIR_ABSOLUTE)
|
|
list(APPEND CMAKE_MODULE_PATH ${MLIR_DIR})
|
|
endif()
|
|
# Use SYSTEM for the same reasons as for LLVM includes
|
|
include_directories(SYSTEM ${MLIR_INCLUDE_DIRS})
|
|
include(AddMLIR)
|
|
find_program(MLIR_TABLEGEN_EXE "mlir-tblgen" ${LLVM_TOOLS_BINARY_DIR}
|
|
NO_DEFAULT_PATH)
|
|
|
|
option(LLVM_INSTALL_TOOLCHAIN_ONLY
|
|
"Only include toolchain files in the 'install' target." OFF)
|
|
option(LLVM_FORCE_USE_OLD_TOOLCHAIN
|
|
"Set to ON to force using an old, unsupported host toolchain." OFF)
|
|
|
|
|
|
# Add LLVM include files as if they were SYSTEM because there are complex unused
|
|
# parameter issues that may or may not appear depending on the environments and
|
|
# compilers (ifdefs are involved). This allows warnings from LLVM headers to be
|
|
# ignored while keeping -Wunused-parameter a fatal error inside f18 code base.
|
|
# This may have to be fine-tuned if flang headers are consider part of this
|
|
# LLVM_INCLUDE_DIRS when merging in the monorepo (Warning from flang headers
|
|
# should not be suppressed).
|
|
include_directories(SYSTEM ${LLVM_INCLUDE_DIRS})
|
|
add_definitions(${LLVM_DEFINITIONS})
|
|
|
|
# LLVM's cmake configuration files currently sneak in a c++11 flag.
|
|
# We look for it here and remove it from Flang's compile flags to
|
|
# avoid some mixed compilation flangs (e.g. -std=c++11 ... -std=c++17).
|
|
if (DEFINED LLVM_CXX_STD)
|
|
message("LLVM configuration set a C++ standard: ${LLVM_CXX_STD}")
|
|
if (NOT LLVM_CXX_STD EQUAL "c++17")
|
|
message("Flang: Overriding LLVM's 'cxx_std' setting...")
|
|
message(" removing '-std=${LLVM_CXX_STD}'")
|
|
message(" CMAKE_CXX_FLAGS='${CMAKE_CXX_FLAGS}'")
|
|
string(REPLACE " -std=${LLVM_CXX_STD}" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
|
|
message(" [NEW] CMAKE_CXX_FLAGS='${CMAKE_CXX_FLAGS}'")
|
|
endif()
|
|
endif()
|
|
|
|
link_directories("${LLVM_LIBRARY_DIR}")
|
|
|
|
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
|
|
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY
|
|
${CMAKE_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX})
|
|
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY
|
|
${CMAKE_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX})
|
|
|
|
set(LLVM_EXTERNAL_LIT "${LLVM_TOOLS_BINARY_DIR}/llvm-lit" CACHE STRING "Command used to spawn lit")
|
|
set(LIT_ARGS_DEFAULT "-sv")
|
|
if (MSVC OR XCODE)
|
|
set(LIT_ARGS_DEFAULT "${LIT_ARGS_DEFAULT} --no-progress-bar")
|
|
endif()
|
|
set(LLVM_LIT_ARGS "${LIT_ARGS_DEFAULT}" CACHE STRING "Default options for lit")
|
|
|
|
option(FLANG_INCLUDE_TESTS
|
|
"Generate build targets for the Flang unit tests."
|
|
ON)
|
|
|
|
get_errc_messages(LLVM_LIT_ERRC_MESSAGES)
|
|
|
|
#Handle unittests when out-of-tree
|
|
set(FLANG_GTEST_AVAIL 0)
|
|
if (FLANG_INCLUDE_TESTS)
|
|
set(UNITTEST_DIR ${LLVM_THIRD_PARTY_DIR}/unittest)
|
|
if(EXISTS ${UNITTEST_DIR}/googletest/include/gtest/gtest.h)
|
|
if (NOT TARGET llvm_gtest)
|
|
add_subdirectory(${UNITTEST_DIR} third-party/unittest)
|
|
endif()
|
|
set(FLANG_GTEST_AVAIL 1)
|
|
else()
|
|
message(WARNING
|
|
"Unit-tests will be skipped as LLVM install does not include google-test related headers and libraries.")
|
|
set(FLANG_GTEST_AVAIL 0)
|
|
endif()
|
|
endif()
|
|
if (FLANG_GTEST_AVAIL)
|
|
add_custom_target(check-all DEPENDS check-flang FlangUnitTests)
|
|
else()
|
|
add_custom_target(check-all DEPENDS check-flang )
|
|
endif()
|
|
if (LLVM_BUILD_DOCS)
|
|
add_custom_target(doxygen ALL)
|
|
endif()
|
|
|
|
else()
|
|
option(FLANG_INCLUDE_TESTS
|
|
"Generate build targets for the Flang unit tests."
|
|
${LLVM_INCLUDE_TESTS})
|
|
set(FLANG_GTEST_AVAIL 1)
|
|
|
|
if(FLANG_STANDALONE_BUILD)
|
|
set(FLANG_BINARY_DIR ${CMAKE_BINARY_DIR}/tools/flang)
|
|
else()
|
|
set(FLANG_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
|
|
endif()
|
|
|
|
set(MLIR_INCLUDE_DIRS ${MLIR_MAIN_SRC_DIR}/include ) # --includedir
|
|
set(MLIR_TABLEGEN_OUTPUT_DIR ${CMAKE_BINARY_DIR}/tools/mlir/include)
|
|
include_directories(SYSTEM ${MLIR_INCLUDE_DIRS})
|
|
include_directories(SYSTEM ${MLIR_TABLEGEN_OUTPUT_DIR})
|
|
endif()
|
|
|
|
if (FLANG_STANDALONE_BUILD)
|
|
message(STATUS "Not building Flang-RT. For a usable Fortran toolchain, compile a standalone Flang-RT.")
|
|
elseif (NOT "flang-rt" IN_LIST LLVM_ENABLE_RUNTIMES)
|
|
message(STATUS "Not building Flang-RT. For a usable Fortran toolchain, either set FLANG_ENABLE_FLANG_RT=ON, add LLVM_ENABLE_RUNTIMES=flang-rt, or compile a standalone Flang-RT.")
|
|
endif ()
|
|
|
|
set(FLANG_TOOLS_INSTALL_DIR "${CMAKE_INSTALL_BINDIR}" CACHE PATH
|
|
"Path for binary subdirectory (defaults to '${CMAKE_INSTALL_BINDIR}')")
|
|
mark_as_advanced(FLANG_TOOLS_INSTALL_DIR)
|
|
|
|
set(FLANG_INCLUDE_DIR ${FLANG_BINARY_DIR}/include)
|
|
|
|
# TODO: Remove when libclangDriver is lifted out of Clang
|
|
if(FLANG_STANDALONE_BUILD)
|
|
set(CLANG_INCLUDE_DIR ${CLANG_INCLUDE_DIRS} )
|
|
# No need to specify TableGen output dir as that's embedded in CLANG_DIR
|
|
else()
|
|
set(CLANG_INCLUDE_DIR ${LLVM_MAIN_SRC_DIR}/../clang/include )
|
|
# Specify TableGen output dir for things like DiagnosticCommonKinds.inc,
|
|
# DiagnosticDriverKinds.inc (required for reporting diagnostics)
|
|
set(CLANG_TABLEGEN_OUTPUT_DIR ${CMAKE_BINARY_DIR}/tools/clang/include)
|
|
include_directories(SYSTEM ${CLANG_TABLEGEN_OUTPUT_DIR})
|
|
endif()
|
|
include_directories(SYSTEM ${CLANG_INCLUDE_DIR})
|
|
|
|
# tco tool and FIR lib output directories
|
|
if(FLANG_STANDALONE_BUILD)
|
|
set(LLVM_RUNTIME_OUTPUT_INTDIR ${CMAKE_BINARY_DIR}/bin)
|
|
set(LLVM_LIBRARY_OUTPUT_INTDIR ${CMAKE_BINARY_DIR}/lib)
|
|
endif()
|
|
# Always build tco tool
|
|
set(LLVM_BUILD_TOOLS ON)
|
|
|
|
include_directories(BEFORE
|
|
${FLANG_BINARY_DIR}/include
|
|
${FLANG_SOURCE_DIR}/include)
|
|
|
|
# Add Flang-centric modules to cmake path.
|
|
list(INSERT CMAKE_MODULE_PATH 0
|
|
"${FLANG_SOURCE_DIR}/cmake/modules"
|
|
"${LLVM_COMMON_CMAKE_UTILS}/Modules"
|
|
)
|
|
include(AddFlang)
|
|
|
|
if (NOT DEFAULT_SYSROOT)
|
|
set(DEFAULT_SYSROOT "" CACHE PATH
|
|
"The <path> to use for the system root for all compiler invocations (--sysroot=<path>).")
|
|
endif()
|
|
|
|
if (NOT ENABLE_LINKER_BUILD_ID)
|
|
set(ENABLE_LINKER_BUILD_ID OFF CACHE BOOL "pass --build-id to ld")
|
|
endif()
|
|
|
|
set(FLANG_DEFAULT_LINKER "${CLANG_DEFAULT_LINKER}" CACHE STRING
|
|
"Default linker to use (linker name or absolute path, empty for platform default)")
|
|
|
|
set(FLANG_DEFAULT_RTLIB "" CACHE STRING
|
|
"Default Fortran runtime library to use (\"libflang_rt.runtime\"), leave empty for platform default.")
|
|
|
|
if (NOT(FLANG_DEFAULT_RTLIB STREQUAL ""))
|
|
message(WARNING "Resetting Flang's default runtime library to use platform default.")
|
|
set(FLANG_DEFAULT_RTLIB "" CACHE STRING
|
|
"Default runtime library to use (empty for platform default)" FORCE)
|
|
endif()
|
|
|
|
|
|
|
|
set(PACKAGE_VERSION "${LLVM_PACKAGE_VERSION}")
|
|
if (NOT PACKAGE_VERSION)
|
|
set(PACKAGE_VERSION ${LLVM_VERSION_MAJOR})
|
|
endif()
|
|
|
|
|
|
if (NOT DEFINED FLANG_VERSION_MAJOR)
|
|
set(FLANG_VERSION_MAJOR ${LLVM_VERSION_MAJOR})
|
|
endif()
|
|
|
|
if (NOT DEFINED FLANG_VERSION_MINOR)
|
|
set(FLANG_VERSION_MINOR ${LLVM_VERSION_MINOR})
|
|
endif()
|
|
|
|
if (NOT DEFINED FLANG_VERSION_PATCHLEVEL)
|
|
set(FLANG_VERSION_PATCHLEVEL ${LLVM_VERSION_PATCH})
|
|
endif()
|
|
|
|
# Unlike PACKAGE_VERSION, FLANG_VERSION does not include LLVM_VERSION_SUFFIX.
|
|
set(FLANG_VERSION "${FLANG_VERSION_MAJOR}.${FLANG_VERSION_MINOR}.${FLANG_VERSION_PATCHLEVEL}")
|
|
message(STATUS "Flang version: ${FLANG_VERSION}")
|
|
# Flang executable version information
|
|
set(FLANG_EXECUTABLE_VERSION
|
|
"${FLANG_VERSION_MAJOR}" CACHE STRING
|
|
"Major version number to appended to the flang executable name.")
|
|
set(LIBFLANG_LIBRARY_VERSION
|
|
"${FLANG_VERSION_MAJOR}" CACHE STRING
|
|
"Major version number to appended to the libflang library.")
|
|
|
|
mark_as_advanced(FLANG_EXECUTABLE_VERSION LIBFLANG_LIBRARY_VERSION)
|
|
|
|
set(FLANG_VENDOR ${PACKAGE_VENDOR} CACHE STRING
|
|
"Vendor-specific Flang version information.")
|
|
set(FLANG_VENDOR_UTI "org.llvm.flang" CACHE STRING
|
|
"Vendor-specific uti.")
|
|
|
|
if (FLANG_VENDOR)
|
|
add_definitions(-DFLANG_VENDOR="${FLANG_VENDOR} ")
|
|
endif()
|
|
|
|
set(FLANG_REPOSITORY_STRING "" CACHE STRING
|
|
"Vendor-specific text for showing the repository the source is taken from.")
|
|
if (FLANG_REPOSITORY_STRING)
|
|
add_definitions(-DFLANG_REPOSITORY_STRING="${FLANG_REPOSITORY_STRING}")
|
|
endif()
|
|
|
|
# Configure Flang's Version.inc file.
|
|
configure_file(
|
|
${CMAKE_CURRENT_SOURCE_DIR}/include/flang/Version.inc.in
|
|
${CMAKE_CURRENT_BINARY_DIR}/include/flang/Version.inc)
|
|
# Configure Flang's version info header file.
|
|
configure_file(
|
|
${FLANG_SOURCE_DIR}/include/flang/Config/config.h.cmake
|
|
${FLANG_BINARY_DIR}/include/flang/Config/config.h)
|
|
|
|
if (FLANG_ENABLE_WERROR)
|
|
# The following is taken from llvm/cmake/modules/HandleLLVMOptions.cmake
|
|
# Keep this up-to-date with that file
|
|
if( MSVC )
|
|
append("/WX" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
|
|
endif()
|
|
if ( LLVM_COMPILER_IS_GCC_COMPATIBLE )
|
|
append("-Werror" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
|
|
append("-Wno-error" CMAKE_REQUIRED_FLAGS)
|
|
endif( LLVM_COMPILER_IS_GCC_COMPATIBLE )
|
|
endif()
|
|
|
|
# Builtin check_cxx_compiler_flag doesn't seem to work correctly
|
|
macro(check_compiler_flag flag resultVar)
|
|
unset(${resultVar} CACHE)
|
|
check_cxx_compiler_flag("${flag}" ${resultVar})
|
|
endmacro()
|
|
|
|
check_compiler_flag("-Werror -Wno-deprecated-copy" CXX_SUPPORTS_NO_DEPRECATED_COPY_FLAG)
|
|
if (CXX_SUPPORTS_NO_DEPRECATED_COPY_FLAG)
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated-copy")
|
|
endif()
|
|
check_compiler_flag("-Wstring-conversion" CXX_SUPPORTS_NO_STRING_CONVERSION_FLAG)
|
|
if (CXX_SUPPORTS_NO_STRING_CONVERSION_FLAG)
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-string-conversion")
|
|
endif()
|
|
check_compiler_flag("-Wno-ctad-maybe-unsupported" CXX_SUPPORTS_NO_CTAD_MAYBE_UNSUPPORTED_FLAG)
|
|
if (CXX_SUPPORTS_NO_CTAD_MAYBE_UNSUPPORTED_FLAG)
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-ctad-maybe-unsupported")
|
|
endif()
|
|
|
|
# Add appropriate flags for GCC
|
|
if (LLVM_COMPILER_IS_GCC_COMPATIBLE)
|
|
|
|
if (NOT "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-semantic-interposition")
|
|
else()
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-command-line-argument -Wstring-conversion \
|
|
-Wcovered-switch-default")
|
|
endif() # Clang.
|
|
|
|
check_cxx_compiler_flag("-Werror -Wnested-anon-types" CXX_SUPPORTS_NO_NESTED_ANON_TYPES_FLAG)
|
|
if (CXX_SUPPORTS_NO_NESTED_ANON_TYPES_FLAG)
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-nested-anon-types")
|
|
endif()
|
|
|
|
# Add to build type flags.
|
|
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEBUGF18")
|
|
set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL} -DCHECK=\"(void)\"")
|
|
|
|
# Building shared libraries is bad for performance with GCC by default
|
|
# due to the need to preserve the right to override external entry points
|
|
if (BUILD_SHARED_LIBS AND NOT (CMAKE_CXX_COMPILER_ID MATCHES "Clang"))
|
|
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -fno-semantic-interposition")
|
|
endif()
|
|
endif()
|
|
|
|
# Clang on Darwin enables non-POSIX extensions by default, which allows the
|
|
# macro HUGE to leak out of <math.h> even when it is never directly included,
|
|
# conflicting with Flang's HUGE symbols.
|
|
# Set _POSIX_C_SOURCE to avoid including these extensions.
|
|
if (APPLE)
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_POSIX_C_SOURCE=200809")
|
|
endif()
|
|
|
|
list(REMOVE_DUPLICATES CMAKE_CXX_FLAGS)
|
|
|
|
# Determine HOST_LINK_VERSION on Darwin.
|
|
set(HOST_LINK_VERSION)
|
|
if (APPLE)
|
|
set(LD_V_OUTPUT)
|
|
execute_process(
|
|
COMMAND sh -c "${CMAKE_LINKER} -v 2>&1 | head -1"
|
|
RESULT_VARIABLE HAD_ERROR
|
|
OUTPUT_VARIABLE LD_V_OUTPUT)
|
|
if (NOT HAD_ERROR)
|
|
if ("${LD_V_OUTPUT}" MATCHES ".*ld64-([0-9.]+).*")
|
|
string(REGEX REPLACE ".*ld64-([0-9.]+).*" "\\1" HOST_LINK_VERSION ${LD_V_OUTPUT})
|
|
elseif ("${LD_V_OUTPUT}" MATCHES "[^0-9]*([0-9.]+).*")
|
|
string(REGEX REPLACE "[^0-9]*([0-9.]+).*" "\\1" HOST_LINK_VERSION ${LD_V_OUTPUT})
|
|
endif()
|
|
else()
|
|
message(FATAL_ERROR "${CMAKE_LINKER} failed with status ${HAD_ERROR}")
|
|
endif()
|
|
endif()
|
|
|
|
# Set up job pools for flang. Some of the flang sources take a lot of memory to
|
|
# compile, so allow users to limit the number of parallel flang jobs. This is
|
|
# useful for building flang alongside several other projects since you can use
|
|
# the maximum number of build jobs for the other projects while limiting the
|
|
# number of flang compile jobs.
|
|
set(FLANG_PARALLEL_COMPILE_JOBS CACHE STRING
|
|
"The maximum number of concurrent compilation jobs for Flang (Ninja only)")
|
|
if (FLANG_PARALLEL_COMPILE_JOBS)
|
|
set_property(GLOBAL APPEND PROPERTY JOB_POOLS flang_compile_job_pool=${FLANG_PARALLEL_COMPILE_JOBS})
|
|
endif()
|
|
|
|
include(AddFlang)
|
|
include(FlangCommon)
|
|
include(GetClangResourceDir)
|
|
|
|
get_clang_resource_dir(HEADER_BINARY_DIR PREFIX ${LLVM_LIBRARY_OUTPUT_INTDIR}/.. SUBDIR include)
|
|
|
|
if (FLANG_INCLUDE_TESTS)
|
|
add_compile_definitions(FLANG_INCLUDE_TESTS=1)
|
|
endif()
|
|
|
|
add_subdirectory(include)
|
|
add_subdirectory(lib)
|
|
add_subdirectory(cmake/modules)
|
|
|
|
option(FLANG_INCLUDE_TOOLS "Generate build targets for the Flang tools." ON)
|
|
option(FLANG_BUILD_TOOLS
|
|
"Build the Flang tools. If OFF, just generate build targets." ON)
|
|
if (FLANG_INCLUDE_TOOLS)
|
|
add_subdirectory(tools)
|
|
endif()
|
|
|
|
if (LLVM_INCLUDE_EXAMPLES)
|
|
add_subdirectory(examples)
|
|
endif()
|
|
|
|
if (FLANG_INCLUDE_TESTS)
|
|
add_subdirectory(test)
|
|
if (FLANG_GTEST_AVAIL)
|
|
add_subdirectory(unittests)
|
|
endif ()
|
|
endif()
|
|
|
|
option(FLANG_INCLUDE_DOCS "Generate build targets for the Flang docs."
|
|
${LLVM_INCLUDE_DOCS})
|
|
if (FLANG_INCLUDE_DOCS)
|
|
add_subdirectory(docs)
|
|
endif()
|
|
|
|
# Custom target to install Flang libraries.
|
|
add_custom_target(flang-libraries)
|
|
set_target_properties(flang-libraries PROPERTIES FOLDER "Flang/Meta")
|
|
|
|
if (NOT LLVM_ENABLE_IDE)
|
|
add_llvm_install_targets(install-flang-libraries
|
|
DEPENDS flang-libraries
|
|
COMPONENT flang-libraries)
|
|
endif()
|
|
|
|
get_property(FLANG_LIBS GLOBAL PROPERTY FLANG_LIBS)
|
|
if (FLANG_LIBS)
|
|
list(REMOVE_DUPLICATES FLANG_LIBS)
|
|
foreach(lib ${FLANG_LIBS})
|
|
add_dependencies(flang-libraries ${lib})
|
|
if (NOT LLVM_ENABLE_IDE)
|
|
add_dependencies(install-flang-libraries install-${lib})
|
|
endif()
|
|
endforeach()
|
|
endif()
|
|
|
|
if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
|
|
add_llvm_install_targets(install-flang-headers
|
|
COMPONENT flang-headers)
|
|
|
|
install(DIRECTORY include/flang
|
|
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
|
|
COMPONENT flang-headers
|
|
FILES_MATCHING
|
|
PATTERN "*.def"
|
|
PATTERN "*.h"
|
|
PATTERN "*.inc"
|
|
PATTERN "*.td"
|
|
PATTERN "config.h" EXCLUDE
|
|
PATTERN ".git" EXCLUDE
|
|
PATTERN "CMakeFiles" EXCLUDE)
|
|
|
|
install(DIRECTORY ${FLANG_INCLUDE_DIR}/flang
|
|
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
|
|
COMPONENT flang-headers
|
|
FILES_MATCHING
|
|
PATTERN "*.inc"
|
|
)
|
|
endif()
|
|
|
|
# Put ISO_Fortran_binding.h into the include files of the build area now
|
|
# so that we can run tests before installing
|
|
configure_file(
|
|
${FLANG_SOURCE_DIR}/include/flang/ISO_Fortran_binding.h
|
|
${HEADER_BINARY_DIR}/ISO_Fortran_binding.h COPYONLY)
|
|
|
|
# llvm-test-suite explicitly searches for this header file
|
|
# (`ISO_FORTRAN_C_HEADER`), cannot hide it in Clang's resource dir.
|
|
configure_file(
|
|
${FLANG_SOURCE_DIR}/include/flang/ISO_Fortran_binding.h
|
|
${LLVM_RUNTIME_OUTPUT_INTDIR}/../include/flang/ISO_Fortran_binding.h COPYONLY)
|
|
|
|
# And also install it into the install area
|
|
get_clang_resource_dir(HEADER_INSTALL_DIR SUBDIR include)
|
|
install(
|
|
FILES include/flang/ISO_Fortran_binding.h
|
|
DESTINATION ${HEADER_INSTALL_DIR}
|
|
COMPONENT flang-fortran-binding)
|
|
install(
|
|
FILES include/flang/ISO_Fortran_binding.h
|
|
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/flang
|
|
COMPONENT flang-fortran-binding)
|
|
add_llvm_install_targets(install-flang-fortran-binding
|
|
COMPONENT flang-fortran-binding)
|