Reland "[CMake] Bumps minimum version to 3.20.0.
This reverts commit d763c6e5e2d0a6b34097aa7dabca31e9aff9b0b6.
Adds the patch by @hans from
https://github.com/llvm/llvm-project/issues/62719
This patch fixes the Windows build.
d763c6e5e2d0a6b34097aa7dabca31e9aff9b0b6 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
2023-05-24 18:12:32 +02:00
cmake_minimum_required ( VERSION 3.20.0 )
2024-05-25 17:24:58 +02:00
set ( LLVM_SUBPROJECT_TITLE "Flang" )
2018-02-14 09:06:47 -08:00
2022-10-24 06:31:37 +02:00
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
N O _ P O L I C Y _ S C O P E )
2021-01-10 14:11:35 +02:00
set ( CMAKE_BUILD_WITH_INSTALL_NAME_DIR ON )
2019-01-19 14:38:31 -08:00
2020-02-25 16:22:14 -07:00
# Flang requires C++17.
set ( CMAKE_CXX_STANDARD 17 )
set ( CMAKE_CXX_STANDARD_REQUIRED TRUE )
set ( CMAKE_CXX_EXTENSIONS OFF )
2018-02-19 14:28:12 +01:00
2023-04-26 13:49:58 -06:00
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 \
L L V M e x c e p t i o n s e n a b l e d . P l e a s e d i s a b l e L L V M _ E N A B L E _ E H w h e n b u i l d i n g \
f l a n g . " )
endif ( )
2020-02-25 16:22:14 -07:00
set ( FLANG_SOURCE_DIR ${ CMAKE_CURRENT_SOURCE_DIR } )
2025-02-16 13:25:31 +01:00
set ( FLANG_RT_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../flang-rt" )
2018-02-19 14:28:12 +01:00
2025-03-21 16:18:16 -04:00
# Python is needed for symbol extracting tool
set ( LLVM_MINIMUM_PYTHON_VERSION 3.8 )
find_package ( Python3 ${ LLVM_MINIMUM_PYTHON_VERSION } REQUIRED
C O M P O N E N T S I n t e r p r e t e r )
2020-02-25 16:22:14 -07:00
if ( CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR AND NOT MSVC_IDE )
message ( FATAL_ERROR " In-source builds are not allowed. \
P l e a s e c r e a t e a d i r e c t o r y a n d r u n c m a k e f r o m t h e r e , \
p a s s i n g t h e p a t h t o t h i s s o u r c e d i r e c t o r y a s t h e l a s t a r g u m e n t . \
T h i s p r o c e s s c r e a t e d t h e f i l e ` C M a k e C a c h e . t x t ' a n d t h e d i r e c t o r y \
` C M a k e F i l e s ' . P l e a s e d e l e t e t h e m . " )
2018-02-19 14:28:12 +01:00
endif ( )
2018-05-03 14:54:53 +02:00
2020-07-14 10:59:26 -05:00
option ( FLANG_ENABLE_WERROR "Fail and stop building flang if a warning is triggered." OFF )
[flang] Use LLVM's flags
Summary:
The only difference is that LLVM_ENABLE_WERROR is set to OFF
by default, but we enable this in a standalone flang build
This commit fixes some windows issues with the flags
Reviewers: DavidTruby, jdoerfert, sscalpone
Reviewed By: DavidTruby, sscalpone
Subscribers: ormris, richard.barton.arm, mehdi_amini, Meinersbur, ChinouneMehdi, tskeith, mgorny, llvm-commits
Tags: #llvm, #flang
Differential Revision: https://reviews.llvm.org/D78306
2020-06-08 15:08:35 +01:00
2020-02-25 16:22:14 -07:00
# Check for a standalone build and configure as appropriate from
# there.
if ( CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR )
[flang] Use LLVM's flags
Summary:
The only difference is that LLVM_ENABLE_WERROR is set to OFF
by default, but we enable this in a standalone flang build
This commit fixes some windows issues with the flags
Reviewers: DavidTruby, jdoerfert, sscalpone
Reviewed By: DavidTruby, sscalpone
Subscribers: ormris, richard.barton.arm, mehdi_amini, Meinersbur, ChinouneMehdi, tskeith, mgorny, llvm-commits
Tags: #llvm, #flang
Differential Revision: https://reviews.llvm.org/D78306
2020-06-08 15:08:35 +01:00
message ( "Building Flang as a standalone project." )
project ( Flang )
2020-06-22 10:24:28 +05:30
set ( FLANG_STANDALONE_BUILD ON )
2022-01-19 06:45:07 +00:00
else ( )
set ( FLANG_STANDALONE_BUILD OFF )
endif ( )
# Must go below project(..)
include ( GNUInstallDirs )
2020-02-25 16:22:14 -07:00
2022-11-30 16:28:13 +05:00
# 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 ( )
2024-12-18 06:15:29 +00:00
if ( MSVC_VERSION EQUAL 1942 )
message ( FATAL_ERROR "Flang cannot be built with clang and the MSVC 17.12 "
" t o o l c h a i n v e r s i o n . P l e a s e u p g r a d e t o 1 7 . 1 3 o r l a t e r , o r s w i t c h "
" t o t h e 1 7 . 1 0 L T S C r e l e a s e . "
" S e e h t t p s : / / g i t h u b . c o m / m i c r o s o f t / S T L / i s s u e s / 4 9 5 9 f o r m o r e d e t a i l s . " )
endif ( )
2022-11-30 16:28:13 +05:00
endif ( )
2023-01-06 17:12:03 +01:00
if ( CMAKE_SIZEOF_VOID_P EQUAL 4 )
message ( FATAL_ERROR "flang isn't supported on 32 bit CPUs" )
endif ( )
2025-02-11 14:32:30 +01:00
set ( MLIR_MAIN_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../mlir" CACHE PATH "Path to MLIR source tree" )
2022-01-19 06:45:07 +00:00
if ( FLANG_STANDALONE_BUILD )
2020-02-25 16:22:14 -07:00
set ( FLANG_BINARY_DIR ${ CMAKE_CURRENT_BINARY_DIR } )
2023-06-03 15:13:09 +02:00
set ( CMAKE_INCLUDE_CURRENT_DIR ON )
2020-02-25 16:22:14 -07:00
if ( NOT MSVC_IDE )
set ( LLVM_ENABLE_ASSERTIONS ${ ENABLE_ASSERTIONS }
C A C H E B O O L " E n a b l e a s s e r t i o n s " )
# Assertions follow llvm's configuration.
mark_as_advanced ( LLVM_ENABLE_ASSERTIONS )
endif ( )
2025-03-21 16:18:16 -04:00
# 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 ( )
2020-09-03 13:39:29 +02:00
# 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.
2025-01-13 18:18:12 +01:00
if ( LLVM_DIR )
get_filename_component ( LLVM_DIR_ABSOLUTE ${ LLVM_DIR }
R E A L P A T H B A S E _ D I R $ { C M A K E _ C U R R E N T _ B I N A R Y _ D I R } )
list ( APPEND CMAKE_MODULE_PATH ${ LLVM_DIR_ABSOLUTE } )
endif ( )
2025-01-10 19:04:57 +01:00
# We need a pre-built/installed version of LLVM.
find_package ( LLVM REQUIRED HINTS "${LLVM_DIR_ABSOLUTE}" )
2025-01-13 18:18:12 +01:00
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 ( )
2018-05-03 14:54:53 +02:00
2021-07-12 08:44:38 +00:00
# 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.
2025-01-13 18:18:12 +01:00
if ( CLANG_DIR )
get_filename_component (
C L A N G _ D I R _ A B S O L U T E
$ { C L A N G _ D I R }
R E A L P A T H
B A S E _ D I R $ { C M A K E _ C U R R E N T _ B I N A R Y _ D I R } )
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 } )
2025-01-10 19:04:57 +01:00
endif ( )
2020-02-25 16:22:14 -07:00
# If LLVM links to zlib we need the imported targets so we can too.
if ( LLVM_ENABLE_ZLIB )
find_package ( ZLIB REQUIRED )
endif ( )
[flang] Use LLVM's flags
Summary:
The only difference is that LLVM_ENABLE_WERROR is set to OFF
by default, but we enable this in a standalone flang build
This commit fixes some windows issues with the flags
Reviewers: DavidTruby, jdoerfert, sscalpone
Reviewed By: DavidTruby, sscalpone
Subscribers: ormris, richard.barton.arm, mehdi_amini, Meinersbur, ChinouneMehdi, tskeith, mgorny, llvm-commits
Tags: #llvm, #flang
Differential Revision: https://reviews.llvm.org/D78306
2020-06-08 15:08:35 +01:00
option ( LLVM_ENABLE_PEDANTIC "Compile with pedantic enabled." ON )
2020-08-11 07:20:13 -07:00
if ( CMAKE_COMPILER_IS_GNUCXX )
set ( USE_NO_MAYBE_UNINITIALIZED 1 )
endif ( )
2020-02-25 16:22:14 -07:00
2025-03-21 16:18:16 -04:00
# 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 ( )
2020-02-25 16:22:14 -07:00
include ( AddLLVM )
include ( HandleLLVMOptions )
include ( VersionFromVCS )
2021-08-20 10:25:11 +00:00
include ( GetErrcMessages )
2020-02-25 16:22:14 -07:00
2021-07-12 08:44:38 +00:00
include ( AddClang )
2020-10-14 17:40:29 +01:00
2021-02-10 18:23:10 +05:30
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.
2025-01-13 18:18:12 +01:00
if ( MLIR_DIR )
get_filename_component ( MLIR_DIR_ABSOLUTE ${ MLIR_DIR }
R E A L P A T H B A S E _ D I R $ { C M A K E _ C U R R E N T _ B I N A R Y _ D I R } )
list ( APPEND CMAKE_MODULE_PATH ${ MLIR_DIR_ABSOLUTE } )
endif ( )
2025-01-10 19:04:57 +01:00
find_package ( MLIR REQUIRED CONFIG HINTS ${ MLIR_DIR_ABSOLUTE } )
2025-01-13 18:18:12 +01:00
if ( NOT MLIR_DIR_ABSOLUTE )
list ( APPEND CMAKE_MODULE_PATH ${ MLIR_DIR } )
endif ( )
2024-04-19 08:51:26 -07:00
# Use SYSTEM for the same reasons as for LLVM includes
include_directories ( SYSTEM ${ MLIR_INCLUDE_DIRS } )
2021-02-10 18:23:10 +05:30
include ( AddMLIR )
find_program ( MLIR_TABLEGEN_EXE "mlir-tblgen" ${ LLVM_TOOLS_BINARY_DIR }
N O _ D E F A U L T _ P A T H )
2020-02-25 16:22:14 -07:00
option ( LLVM_INSTALL_TOOLCHAIN_ONLY
" O n l y i n c l u d e t o o l c h a i n f i l e s i n t h e ' i n s t a l l ' t a r g e t . " O F F )
2023-05-17 10:28:58 +02:00
option ( LLVM_FORCE_USE_OLD_TOOLCHAIN
2020-02-25 16:22:14 -07:00
" S e t t o O N t o f o r c e u s i n g a n o l d , u n s u p p o r t e d h o s t t o o l c h a i n . " O F F )
2020-01-14 16:20:49 +00:00
2020-02-25 16:22:14 -07:00
# 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 } )
2018-05-03 14:54:53 +02:00
2020-02-25 16:22:14 -07:00
# 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 ( )
2018-05-03 14:54:53 +02:00
2020-02-25 16:22:14 -07:00
link_directories ( "${LLVM_LIBRARY_DIR}" )
set ( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${ CMAKE_BINARY_DIR } /bin )
set ( CMAKE_LIBRARY_OUTPUT_DIRECTORY
2022-08-18 22:44:46 -04:00
$ { C M A K E _ B I N A R Y _ D I R } / l i b $ { L L V M _ L I B D I R _ S U F F I X } )
2020-02-25 16:22:14 -07:00
set ( CMAKE_ARCHIVE_OUTPUT_DIRECTORY
2022-08-18 22:44:46 -04:00
$ { C M A K E _ B I N A R Y _ D I R } / l i b $ { L L V M _ L I B D I R _ S U F F I X } )
2020-02-25 16:22:14 -07:00
set ( LLVM_EXTERNAL_LIT "${LLVM_TOOLS_BINARY_DIR}/llvm-lit" CACHE STRING "Command used to spawn lit" )
2025-02-15 20:50:14 +01:00
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" )
2020-02-25 16:22:14 -07:00
option ( FLANG_INCLUDE_TESTS
" G e n e r a t e b u i l d t a r g e t s f o r t h e F l a n g u n i t t e s t s . "
O N )
2020-06-02 22:45:44 +05:30
2021-08-20 10:25:11 +00:00
get_errc_messages ( LLVM_LIT_ERRC_MESSAGES )
2020-06-02 22:45:44 +05:30
#Handle unittests when out-of-tree
set ( FLANG_GTEST_AVAIL 0 )
if ( FLANG_INCLUDE_TESTS )
2022-11-23 13:19:47 +01:00
set ( UNITTEST_DIR ${ LLVM_THIRD_PARTY_DIR } /unittest )
2020-06-02 22:45:44 +05:30
if ( EXISTS ${ UNITTEST_DIR } /googletest/include/gtest/gtest.h )
2022-03-04 12:08:04 -08:00
if ( NOT TARGET llvm_gtest )
2022-11-23 16:07:03 +01:00
add_subdirectory ( ${ UNITTEST_DIR } third-party/unittest )
2020-06-02 22:45:44 +05:30
endif ( )
set ( FLANG_GTEST_AVAIL 1 )
else ( )
message ( WARNING
" U n i t - t e s t s w i l l b e s k i p p e d a s L L V M i n s t a l l d o e s n o t i n c l u d e g o o g l e - t e s t r e l a t e d h e a d e r s a n d l i b r a r i e s . " )
set ( FLANG_GTEST_AVAIL 0 )
endif ( )
endif ( )
if ( FLANG_GTEST_AVAIL )
add_custom_target ( check-all DEPENDS check-flang FlangUnitTests )
else ( )
2023-10-02 09:01:11 +00:00
add_custom_target ( check-all DEPENDS check-flang )
2020-06-02 22:45:44 +05:30
endif ( )
2020-04-27 14:52:36 +05:30
if ( LLVM_BUILD_DOCS )
add_custom_target ( doxygen ALL )
endif ( )
2020-02-25 16:22:14 -07:00
else ( )
option ( FLANG_INCLUDE_TESTS
" G e n e r a t e b u i l d t a r g e t s f o r t h e F l a n g u n i t t e s t s . "
$ { L L V M _ I N C L U D E _ T E S T S } )
2020-06-02 22:45:44 +05:30
set ( FLANG_GTEST_AVAIL 1 )
2020-08-01 20:53:27 +01:00
if ( FLANG_STANDALONE_BUILD )
set ( FLANG_BINARY_DIR ${ CMAKE_BINARY_DIR } /tools/flang )
else ( )
set ( FLANG_BINARY_DIR ${ CMAKE_CURRENT_BINARY_DIR } )
endif ( )
2025-02-11 14:32:30 +01:00
set ( MLIR_INCLUDE_DIRS ${ MLIR_MAIN_SRC_DIR } /include ) # --includedir
2021-02-10 18:23:10 +05:30
set ( MLIR_TABLEGEN_OUTPUT_DIR ${ CMAKE_BINARY_DIR } /tools/mlir/include )
2025-02-11 14:32:30 +01:00
include_directories ( SYSTEM ${ MLIR_INCLUDE_DIRS } )
2021-02-10 18:23:10 +05:30
include_directories ( SYSTEM ${ MLIR_TABLEGEN_OUTPUT_DIR } )
2020-02-25 16:22:14 -07:00
endif ( )
[cmake] Don't export `LLVM_TOOLS_INSTALL_DIR` anymore
First of all, `LLVM_TOOLS_INSTALL_DIR` put there breaks our NixOS
builds, because `LLVM_TOOLS_INSTALL_DIR` defined the same as
`CMAKE_INSTALL_BINDIR` becomes an *absolute* path, and then when
downstream projects try to install there too this breaks because our
builds always install to fresh directories for isolation's sake.
Second of all, note that `LLVM_TOOLS_INSTALL_DIR` stands out against the
other specially crafted `LLVM_CONFIG_*` variables substituted in
`llvm/cmake/modules/LLVMConfig.cmake.in`.
@beanz added it in d0e1c2a550ef348aae036d0fe78cab6f038c420c to fix a
dangling reference in `AddLLVM`, but I am suspicious of how this
variable doesn't follow the pattern.
Those other ones are carefully made to be build-time vs install-time
variables depending on which `LLVMConfig.cmake` is being generated, are
carefully made relative as appropriate, etc. etc. For my NixOS use-case
they are also fine because they are never used as downstream install
variables, only for reading not writing.
To avoid the problems I face, and restore symmetry, I deleted the
exported and arranged to have many `${project}_TOOLS_INSTALL_DIR`s.
`AddLLVM` now instead expects each project to define its own, and they
do so based on `CMAKE_INSTALL_BINDIR`. `LLVMConfig` still exports
`LLVM_TOOLS_BINARY_DIR` which is the location for the tools defined in
the usual way, matching the other remaining exported variables.
For the `AddLLVM` changes, I tried to copy the existing pattern of
internal vs non-internal or for LLVM vs for downstream function/macro
names, but it would good to confirm I did that correctly.
Reviewed By: nikic
Differential Revision: https://reviews.llvm.org/D117977
2022-06-11 06:11:59 +00:00
2025-02-16 15:39:52 +01:00
set ( FLANG_INCLUDE_RUNTIME_default ON )
if ( "flang-rt" IN_LIST LLVM_ENABLE_RUNTIMES )
set ( FLANG_INCLUDE_RUNTIME_default OFF )
endif ( )
option ( FLANG_INCLUDE_RUNTIME "Build the runtime in-tree (deprecated; to be replaced with LLVM_ENABLE_RUNTIMES=flang-rt)" ${ FLANG_INCLUDE_RUNTIME_default } )
if ( FLANG_INCLUDE_RUNTIME )
if ( "flang-rt" IN_LIST LLVM_ENABLE_RUNTIMES )
message ( WARNING "Building Flang-RT using LLVM_ENABLE_RUNTIMES. FLANG_INCLUDE_RUNTIME=${FLANG_INCLUDE_RUNTIME} ignored." )
set ( FLANG_INCLUDE_RUNTIME OFF )
else ( )
message ( STATUS "Building Flang-RT in-tree" )
endif ( )
else ( )
if ( "flang-rt" IN_LIST LLVM_ENABLE_RUNTIMES )
message ( STATUS "Building Flang-RT using LLVM_ENABLE_RUNTIMES" )
else ( )
message ( STATUS "Not building Flang-RT. For a usable Fortran toolchain, either add LLVM_ENABLE_RUNTIMES=flang-rt, or compile a standalone Flang-RT." )
endif ( )
endif ( )
2025-02-08 01:06:27 +01:00
[cmake] Don't export `LLVM_TOOLS_INSTALL_DIR` anymore
First of all, `LLVM_TOOLS_INSTALL_DIR` put there breaks our NixOS
builds, because `LLVM_TOOLS_INSTALL_DIR` defined the same as
`CMAKE_INSTALL_BINDIR` becomes an *absolute* path, and then when
downstream projects try to install there too this breaks because our
builds always install to fresh directories for isolation's sake.
Second of all, note that `LLVM_TOOLS_INSTALL_DIR` stands out against the
other specially crafted `LLVM_CONFIG_*` variables substituted in
`llvm/cmake/modules/LLVMConfig.cmake.in`.
@beanz added it in d0e1c2a550ef348aae036d0fe78cab6f038c420c to fix a
dangling reference in `AddLLVM`, but I am suspicious of how this
variable doesn't follow the pattern.
Those other ones are carefully made to be build-time vs install-time
variables depending on which `LLVMConfig.cmake` is being generated, are
carefully made relative as appropriate, etc. etc. For my NixOS use-case
they are also fine because they are never used as downstream install
variables, only for reading not writing.
To avoid the problems I face, and restore symmetry, I deleted the
exported and arranged to have many `${project}_TOOLS_INSTALL_DIR`s.
`AddLLVM` now instead expects each project to define its own, and they
do so based on `CMAKE_INSTALL_BINDIR`. `LLVMConfig` still exports
`LLVM_TOOLS_BINARY_DIR` which is the location for the tools defined in
the usual way, matching the other remaining exported variables.
For the `AddLLVM` changes, I tried to copy the existing pattern of
internal vs non-internal or for LLVM vs for downstream function/macro
names, but it would good to confirm I did that correctly.
Reviewed By: nikic
Differential Revision: https://reviews.llvm.org/D117977
2022-06-11 06:11:59 +00:00
set ( FLANG_TOOLS_INSTALL_DIR "${CMAKE_INSTALL_BINDIR}" CACHE PATH
" P a t h f o r b i n a r y subdirectory ( defaults to ' ${ CMAKE_INSTALL_BINDIR } ' ) " )
mark_as_advanced ( FLANG_TOOLS_INSTALL_DIR )
2021-03-15 08:02:58 -07:00
set ( FLANG_INTRINSIC_MODULES_DIR ${ CMAKE_BINARY_DIR } /include/flang )
2021-05-10 16:41:29 -07:00
set ( FLANG_INCLUDE_DIR ${ FLANG_BINARY_DIR } /include )
2020-01-14 16:20:49 +00:00
2021-07-12 08:44:38 +00:00
# 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 } )
2020-09-11 10:17:31 +01:00
endif ( )
2021-07-12 08:44:38 +00:00
include_directories ( SYSTEM ${ CLANG_INCLUDE_DIR } )
2020-09-11 10:17:31 +01:00
2021-02-10 18:23:10 +05:30
# 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 )
2019-03-13 12:41:15 -07:00
endif ( )
2021-02-10 18:23:10 +05:30
# Always build tco tool
set ( LLVM_BUILD_TOOLS ON )
2018-02-19 14:28:12 +01:00
2020-02-25 16:22:14 -07:00
include_directories ( BEFORE
$ { F L A N G _ B I N A R Y _ D I R } / i n c l u d e
$ { F L A N G _ S O U R C E _ D I R } / i n c l u d e )
2021-05-12 12:59:23 -07:00
# Add Flang-centric modules to cmake path.
2021-04-04 13:02:18 -04:00
list ( INSERT CMAKE_MODULE_PATH 0
" $ { F L A N G _ S O U R C E _ D I R } / c m a k e / m o d u l e s "
2022-01-01 17:51:16 +00:00
" $ { L L V M _ C O M M O N _ C M A K E _ U T I L S } / M o d u l e s "
2021-04-04 13:02:18 -04:00
)
2021-05-12 12:59:23 -07:00
include ( AddFlang )
2020-02-25 16:22:14 -07:00
if ( NOT DEFAULT_SYSROOT )
set ( DEFAULT_SYSROOT "" CACHE PATH
" T h e < p a t h > t o u s e f o r t h e s y s t e m r o o t f o r a l l c o m p i l e r invocations ( --sysroot=<path> ) . " )
endif ( )
if ( NOT ENABLE_LINKER_BUILD_ID )
set ( ENABLE_LINKER_BUILD_ID OFF CACHE BOOL "pass --build-id to ld" )
2018-02-19 14:28:12 +01:00
endif ( )
2020-02-25 16:22:14 -07:00
set ( FLANG_DEFAULT_LINKER "" CACHE STRING
" D e f a u l t l i n k e r t o use ( linker name or absolute path, empty for platform default ) " )
set ( FLANG_DEFAULT_RTLIB "" CACHE STRING
2025-02-08 18:02:54 +01:00
" D e f a u l t F o r t r a n r u n t i m e l i b r a r y t o use ( \"libflang_rt.runtime\"), leave empty for platform default. " )
2020-02-25 16:22:14 -07:00
if ( NOT(FLANG_DEFAULT_RTLIB STREQUAL "" ) )
message ( WARNING "Resetting Flang's default runtime library to use platform default." )
set ( FLANG_DEFAULT_RTLIB "" CACHE STRING
" D e f a u l t r u n t i m e l i b r a r y t o use ( empty for platform default ) " F O R C E )
endif ( )
2023-10-20 09:00:51 -07:00
2020-02-25 16:22:14 -07:00
set ( PACKAGE_VERSION "${LLVM_PACKAGE_VERSION}" )
[flang] Put ISO_Fortran_binding.h where it can be easily used (#70129)
The update stems from the discussion in
https://discourse.llvm.org/t/adding-flang-specific-header-files-to-clang/72442
This is my third attempt at this. My second attempt was in pull request
#69121.
This is my second attempt at this. My first attempt was in pull request
#68756.
This pull request has three changes from the second one:
- I put the test into the Driver directory rather than Examples so that
it would get run without require the define LLVM_BUILD_EXAMPLES.
- When installing ISO_Fortran_binding.h, I changed the location where it
was installed from.
- I changed the test so that it would work when flang was built with
shared libraries.
Here's the information from my previous attempts:
I decided to put ISO_Fortran_binding.h in a place where it would be
accessible with the include: "#include<ISO_Fortran_binding.h>" rather
than "#include<fortran/ISO_Fortran_binding.h>" because this is what
gfortran implements.
Note that the file is also installed into ".../include/flang", so if a
user wanted to access the file from a compiler other than clang, it
would be available.
I added a test in ".../flang/test/Driver". To make the test work, I also
needed to put ISO_Fortran_binding.h into the build area.
Although the flang project depends on clang, clang may not always be
available in a flang build. For example, when building just the
"check-flang" target, the "clang" executable may not be available at the
time the new test gets run. To account for this, I made the test's
script check for the existence of the "clang" executable. If "clang" is
not available, it simply prints "PASS". If it is available, it fully
builds and executes the test. On success, this will also print "PASS"
2023-10-30 06:44:09 -07:00
if ( NOT PACKAGE_VERSION )
set ( PACKAGE_VERSION ${ LLVM_VERSION_MAJOR } )
endif ( )
2023-10-20 09:00:51 -07:00
2020-02-25 16:22:14 -07:00
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.
2018-02-19 14:28:12 +01:00
set ( FLANG_VERSION "${FLANG_VERSION_MAJOR}.${FLANG_VERSION_MINOR}.${FLANG_VERSION_PATCHLEVEL}" )
2020-02-25 16:22:14 -07:00
message ( STATUS "Flang version: ${FLANG_VERSION}" )
# Flang executable version information
set ( FLANG_EXECUTABLE_VERSION
" $ { F L A N G _ V E R S I O N _ M A J O R } " C A C H E S T R I N G
" M a j o r v e r s i o n n u m b e r t o a p p e n d e d t o t h e f l a n g e x e c u t a b l e n a m e . " )
set ( LIBFLANG_LIBRARY_VERSION
" $ { F L A N G _ V E R S I O N _ M A J O R } " C A C H E S T R I N G
" M a j o r v e r s i o n n u m b e r t o a p p e n d e d t o t h e l i b f l a n g l i b r a r y . " )
2018-02-19 14:28:12 +01:00
2020-02-25 16:22:14 -07:00
mark_as_advanced ( FLANG_EXECUTABLE_VERSION LIBFLANG_LIBRARY_VERSION )
2018-02-19 14:28:12 +01:00
2020-02-25 16:22:14 -07:00
set ( FLANG_VENDOR ${ PACKAGE_VENDOR } CACHE STRING
" V e n d o r - s p e c i f i c F l a n g v e r s i o n i n f o r m a t i o n . " )
set ( FLANG_VENDOR_UTI "org.llvm.flang" CACHE STRING
" V e n d o r - s p e c i f i c u t i . " )
2018-02-19 14:28:12 +01:00
2020-02-25 16:22:14 -07:00
if ( FLANG_VENDOR )
add_definitions ( -DFLANG_VENDOR= "${FLANG_VENDOR} " )
endif ( )
2018-06-14 13:43:02 -07:00
2020-02-25 16:22:14 -07:00
set ( FLANG_REPOSITORY_STRING "" CACHE STRING
" V e n d o r - s p e c i f i c t e x t f o r s h o w i n g t h e r e p o s i t o r y t h e s o u r c e i s t a k e n f r o m . " )
if ( FLANG_REPOSITORY_STRING )
add_definitions ( -DFLANG_REPOSITORY_STRING= "${FLANG_REPOSITORY_STRING}" )
endif ( )
2018-02-19 14:28:12 +01:00
2020-02-25 16:22:14 -07:00
# Configure Flang's Version.inc file.
configure_file (
$ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / i n c l u d e / f l a n g / V e r s i o n . i n c . i n
$ { C M A K E _ C U R R E N T _ B I N A R Y _ D I R } / i n c l u d e / f l a n g / V e r s i o n . i n c )
# Configure Flang's version info header file.
2018-02-19 14:28:12 +01:00
configure_file (
$ { F L A N G _ S O U R C E _ D I R } / i n c l u d e / f l a n g / C o n f i g / c o n f i g . h . c m a k e
$ { F L A N G _ B I N A R Y _ D I R } / i n c l u d e / f l a n g / C o n f i g / c o n f i g . h )
2020-02-25 16:22:14 -07:00
[flang] Use LLVM's flags
Summary:
The only difference is that LLVM_ENABLE_WERROR is set to OFF
by default, but we enable this in a standalone flang build
This commit fixes some windows issues with the flags
Reviewers: DavidTruby, jdoerfert, sscalpone
Reviewed By: DavidTruby, sscalpone
Subscribers: ormris, richard.barton.arm, mehdi_amini, Meinersbur, ChinouneMehdi, tskeith, mgorny, llvm-commits
Tags: #llvm, #flang
Differential Revision: https://reviews.llvm.org/D78306
2020-06-08 15:08:35 +01:00
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 ( )
2020-02-25 16:22:14 -07:00
# 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 )
[flang] Use LLVM's flags
Summary:
The only difference is that LLVM_ENABLE_WERROR is set to OFF
by default, but we enable this in a standalone flang build
This commit fixes some windows issues with the flags
Reviewers: DavidTruby, jdoerfert, sscalpone
Reviewed By: DavidTruby, sscalpone
Subscribers: ormris, richard.barton.arm, mehdi_amini, Meinersbur, ChinouneMehdi, tskeith, mgorny, llvm-commits
Tags: #llvm, #flang
Differential Revision: https://reviews.llvm.org/D78306
2020-06-08 15:08:35 +01:00
set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated-copy" )
2020-02-25 16:22:14 -07:00
endif ( )
check_compiler_flag ( "-Wstring-conversion" CXX_SUPPORTS_NO_STRING_CONVERSION_FLAG )
if ( CXX_SUPPORTS_NO_STRING_CONVERSION_FLAG )
[flang] Use LLVM's flags
Summary:
The only difference is that LLVM_ENABLE_WERROR is set to OFF
by default, but we enable this in a standalone flang build
This commit fixes some windows issues with the flags
Reviewers: DavidTruby, jdoerfert, sscalpone
Reviewed By: DavidTruby, sscalpone
Subscribers: ormris, richard.barton.arm, mehdi_amini, Meinersbur, ChinouneMehdi, tskeith, mgorny, llvm-commits
Tags: #llvm, #flang
Differential Revision: https://reviews.llvm.org/D78306
2020-06-08 15:08:35 +01:00
set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-string-conversion" )
2020-02-25 16:22:14 -07:00
endif ( )
2022-08-16 17:42:45 +00:00
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 ( )
2020-02-25 16:22:14 -07:00
# 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-strict-aliasing -fno-semantic-interposition" )
else ( )
set ( CMAKE_CXX_FLAGS " ${ CMAKE_CXX_FLAGS } -Wno-unused-command-line-argument -Wstring-conversion \
- W c o v e r e d - s w i t c h - d e f a u l t " )
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 ( )
2020-05-29 14:03:21 +01:00
# Add to build type flags.
2020-02-25 16:22:14 -07:00
set ( CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEBUGF18" )
2020-05-29 14:03:21 +01:00
set ( CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL} -DCHECK=\" ( void ) \"")
2020-02-25 16:22:14 -07:00
# 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 ( )
2024-03-11 08:25:41 -03:00
# 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 ( )
2020-02-25 16:22:14 -07:00
list ( REMOVE_DUPLICATES CMAKE_CXX_FLAGS )
# Determine HOST_LINK_VERSION on Darwin.
set ( HOST_LINK_VERSION )
if ( APPLE )
set ( LD_V_OUTPUT )
execute_process (
C O M M A N D s h - c " $ { C M A K E _ L I N K E R } - v 2 > & 1 | h e a d - 1 "
R E S U L T _ V A R I A B L E H A D _ E R R O R
O U T P U T _ V A R I A B L E L D _ V _ O U T P U T )
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 ( )
2025-02-20 11:29:54 -08:00
# 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
" T h e m a x i m u m n u m b e r o f c o n c u r r e n t c o m p i l a t i o n j o b s f o r Flang ( Ninja only ) " )
if ( FLANG_PARALLEL_COMPILE_JOBS )
set_property ( GLOBAL APPEND PROPERTY JOB_POOLS flang_compile_job_pool= ${ FLANG_PARALLEL_COMPILE_JOBS } )
endif ( )
2020-02-25 16:22:14 -07:00
include ( AddFlang )
2025-02-16 15:39:52 +01:00
include ( FlangCommon )
2020-02-25 16:22:14 -07:00
2022-11-02 15:39:58 -07:00
if ( FLANG_INCLUDE_TESTS )
add_compile_definitions ( FLANG_INCLUDE_TESTS=1 )
endif ( )
2021-07-01 08:27:31 +00:00
2025-01-28 20:57:33 -08:00
option ( FLANG_CUF_RUNTIME
" C o m p i l e C U D A F o r t r a n r u n t i m e s o u r c e s " O F F )
if ( FLANG_CUF_RUNTIME )
find_package ( CUDAToolkit REQUIRED )
endif ( )
2020-02-25 16:22:14 -07:00
add_subdirectory ( include )
add_subdirectory ( lib )
add_subdirectory ( cmake/modules )
option ( FLANG_BUILD_TOOLS
" B u i l d t h e F l a n g t o o l s . I f O F F , j u s t g e n e r a t e b u i l d t a r g e t s . " O N )
if ( FLANG_BUILD_TOOLS )
add_subdirectory ( tools )
endif ( )
2024-08-02 10:02:34 -07:00
2025-02-08 01:06:27 +01:00
if ( FLANG_INCLUDE_RUNTIME )
add_subdirectory ( runtime )
endif ( )
2021-08-12 11:42:08 +01:00
2023-03-13 14:50:13 -07:00
if ( LLVM_INCLUDE_EXAMPLES )
add_subdirectory ( examples )
2021-08-12 16:11:54 +00:00
endif ( )
2020-02-25 16:22:14 -07:00
if ( FLANG_INCLUDE_TESTS )
add_subdirectory ( test )
2020-06-02 22:45:44 +05:30
if ( FLANG_GTEST_AVAIL )
add_subdirectory ( unittests )
endif ( )
2020-02-25 16:22:14 -07:00
endif ( )
2020-04-27 14:52:36 +05:30
option ( FLANG_INCLUDE_DOCS "Generate build targets for the Flang docs."
$ { L L V M _ I N C L U D E _ D O C S } )
if ( FLANG_INCLUDE_DOCS )
add_subdirectory ( docs )
endif ( )
2020-02-25 16:22:14 -07:00
# Custom target to install Flang libraries.
add_custom_target ( flang-libraries )
2024-05-25 17:24:58 +02:00
set_target_properties ( flang-libraries PROPERTIES FOLDER "Flang/Meta" )
2020-02-25 16:22:14 -07:00
if ( NOT LLVM_ENABLE_IDE )
add_llvm_install_targets ( install-flang-libraries
D E P E N D S f l a n g - l i b r a r i e s
C O M P O N E N T f l a n g - l i b r a r i e s )
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 )
2024-01-16 17:04:52 +00:00
add_llvm_install_targets ( install-flang-headers
C O M P O N E N T f l a n g - h e a d e r s )
2020-02-25 16:22:14 -07:00
install ( DIRECTORY include/flang
2021-04-04 13:02:18 -04:00
D E S T I N A T I O N " $ { C M A K E _ I N S T A L L _ I N C L U D E D I R } "
2020-02-25 16:22:14 -07:00
C O M P O N E N T f l a n g - h e a d e r s
F I L E S _ M A T C H I N G
P A T T E R N " * . d e f "
P A T T E R N " * . h "
P A T T E R N " * . i n c "
P A T T E R N " * . t d "
P A T T E R N " c o n f i g . h " E X C L U D E
P A T T E R N " . g i t " E X C L U D E
P A T T E R N " C M a k e F i l e s " E X C L U D E )
2022-03-04 12:08:04 -08:00
2021-05-10 16:41:29 -07:00
install ( DIRECTORY ${ FLANG_INCLUDE_DIR } /flang
2021-04-04 13:02:18 -04:00
D E S T I N A T I O N " $ { C M A K E _ I N S T A L L _ I N C L U D E D I R } "
2021-05-10 16:41:29 -07:00
C O M P O N E N T f l a n g - h e a d e r s
F I L E S _ M A T C H I N G
P A T T E R N " * . i n c "
)
2020-02-25 16:22:14 -07:00
endif ( )
[flang] Put ISO_Fortran_binding.h where it can be easily used (#70129)
The update stems from the discussion in
https://discourse.llvm.org/t/adding-flang-specific-header-files-to-clang/72442
This is my third attempt at this. My second attempt was in pull request
#69121.
This is my second attempt at this. My first attempt was in pull request
#68756.
This pull request has three changes from the second one:
- I put the test into the Driver directory rather than Examples so that
it would get run without require the define LLVM_BUILD_EXAMPLES.
- When installing ISO_Fortran_binding.h, I changed the location where it
was installed from.
- I changed the test so that it would work when flang was built with
shared libraries.
Here's the information from my previous attempts:
I decided to put ISO_Fortran_binding.h in a place where it would be
accessible with the include: "#include<ISO_Fortran_binding.h>" rather
than "#include<fortran/ISO_Fortran_binding.h>" because this is what
gfortran implements.
Note that the file is also installed into ".../include/flang", so if a
user wanted to access the file from a compiler other than clang, it
would be available.
I added a test in ".../flang/test/Driver". To make the test work, I also
needed to put ISO_Fortran_binding.h into the build area.
Although the flang project depends on clang, clang may not always be
available in a flang build. For example, when building just the
"check-flang" target, the "clang" executable may not be available at the
time the new test gets run. To account for this, I made the test's
script check for the existence of the "clang" executable. If "clang" is
not available, it simply prints "PASS". If it is available, it fully
builds and executes the test. On success, this will also print "PASS"
2023-10-30 06:44:09 -07:00
# Put ISO_Fortran_binding.h into the include files of the build area now
# so that we can run tests before installing
include ( GetClangResourceDir )
get_clang_resource_dir ( HEADER_BINARY_DIR PREFIX ${ LLVM_LIBRARY_OUTPUT_INTDIR } /.. SUBDIR include )
configure_file (
$ { F L A N G _ S O U R C E _ D I R } / i n c l u d e / f l a n g / I S O _ F o r t r a n _ b i n d i n g . h
2025-02-16 15:39:52 +01:00
$ { H E A D E R _ B I N A R Y _ D I R } / I S O _ F o r t r a n _ b i n d i n g . h C O P Y O N L Y )
# llvm-test-suite explicitly searches for this header file
# (`ISO_FORTRAN_C_HEADER`), cannot hide it in Clang's resource dir.
configure_file (
$ { F L A N G _ S O U R C E _ D I R } / i n c l u d e / f l a n g / I S O _ F o r t r a n _ b i n d i n g . h
$ { L L V M _ R U N T I M E _ O U T P U T _ I N T D I R } / . . / i n c l u d e / f l a n g / I S O _ F o r t r a n _ b i n d i n g . h C O P Y O N L Y )
[flang] Put ISO_Fortran_binding.h where it can be easily used (#70129)
The update stems from the discussion in
https://discourse.llvm.org/t/adding-flang-specific-header-files-to-clang/72442
This is my third attempt at this. My second attempt was in pull request
#69121.
This is my second attempt at this. My first attempt was in pull request
#68756.
This pull request has three changes from the second one:
- I put the test into the Driver directory rather than Examples so that
it would get run without require the define LLVM_BUILD_EXAMPLES.
- When installing ISO_Fortran_binding.h, I changed the location where it
was installed from.
- I changed the test so that it would work when flang was built with
shared libraries.
Here's the information from my previous attempts:
I decided to put ISO_Fortran_binding.h in a place where it would be
accessible with the include: "#include<ISO_Fortran_binding.h>" rather
than "#include<fortran/ISO_Fortran_binding.h>" because this is what
gfortran implements.
Note that the file is also installed into ".../include/flang", so if a
user wanted to access the file from a compiler other than clang, it
would be available.
I added a test in ".../flang/test/Driver". To make the test work, I also
needed to put ISO_Fortran_binding.h into the build area.
Although the flang project depends on clang, clang may not always be
available in a flang build. For example, when building just the
"check-flang" target, the "clang" executable may not be available at the
time the new test gets run. To account for this, I made the test's
script check for the existence of the "clang" executable. If "clang" is
not available, it simply prints "PASS". If it is available, it fully
builds and executes the test. On success, this will also print "PASS"
2023-10-30 06:44:09 -07:00
# And also install it into the install area
get_clang_resource_dir ( HEADER_INSTALL_DIR SUBDIR include )
install (
F I L E S i n c l u d e / f l a n g / I S O _ F o r t r a n _ b i n d i n g . h
D E S T I N A T I O N $ { H E A D E R _ I N S T A L L _ D I R } )
2024-07-19 19:37:24 +02:00