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 16:12:32 +00:00
|
|
|
cmake_minimum_required(VERSION 3.20.0)
|
2016-02-05 07:00:13 +00:00
|
|
|
|
2022-01-16 05:52:22 +00:00
|
|
|
set(LLVM_COMMON_CMAKE_UTILS ${CMAKE_CURRENT_SOURCE_DIR}/../cmake)
|
|
|
|
|
|
|
|
# Add path for custom modules
|
|
|
|
list(INSERT CMAKE_MODULE_PATH 0
|
|
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/cmake"
|
|
|
|
"${LLVM_COMMON_CMAKE_UTILS}/Modules"
|
|
|
|
)
|
2017-11-29 19:31:48 +00:00
|
|
|
|
2017-11-29 19:31:43 +00:00
|
|
|
# llvm/runtimes/ will set OPENMP_STANDALONE_BUILD.
|
|
|
|
if (OPENMP_STANDALONE_BUILD OR "${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}")
|
|
|
|
set(OPENMP_STANDALONE_BUILD TRUE)
|
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 16:12:32 +00:00
|
|
|
project(openmp C CXX ASM)
|
2022-01-22 06:33:49 +00:00
|
|
|
endif()
|
2017-11-29 19:31:43 +00:00
|
|
|
|
2022-01-22 06:33:49 +00:00
|
|
|
# Must go below project(..)
|
|
|
|
include(GNUInstallDirs)
|
|
|
|
|
|
|
|
if (OPENMP_STANDALONE_BUILD)
|
2017-11-29 19:31:43 +00:00
|
|
|
# CMAKE_BUILD_TYPE was not set, default to Release.
|
|
|
|
if (NOT CMAKE_BUILD_TYPE)
|
|
|
|
set(CMAKE_BUILD_TYPE Release)
|
|
|
|
endif()
|
|
|
|
|
2017-11-29 19:31:48 +00:00
|
|
|
# Group common settings.
|
|
|
|
set(OPENMP_ENABLE_WERROR FALSE CACHE BOOL
|
|
|
|
"Enable -Werror flags to turn warnings into errors for supporting compilers.")
|
2022-08-19 02:44:46 +00:00
|
|
|
set(OPENMP_LIBDIR_SUFFIX "" CACHE STRING
|
|
|
|
"Suffix of lib installation directory, e.g. 64 => lib64")
|
|
|
|
# Do not use OPENMP_LIBDIR_SUFFIX directly, use OPENMP_INSTALL_LIBDIR.
|
|
|
|
set(OPENMP_INSTALL_LIBDIR "lib${OPENMP_LIBDIR_SUFFIX}")
|
2017-11-29 19:31:48 +00:00
|
|
|
|
2017-11-29 19:31:52 +00:00
|
|
|
# Group test settings.
|
|
|
|
set(OPENMP_TEST_C_COMPILER ${CMAKE_C_COMPILER} CACHE STRING
|
|
|
|
"C compiler to use for testing OpenMP runtime libraries.")
|
|
|
|
set(OPENMP_TEST_CXX_COMPILER ${CMAKE_CXX_COMPILER} CACHE STRING
|
|
|
|
"C++ compiler to use for testing OpenMP runtime libraries.")
|
2023-08-29 21:27:30 +00:00
|
|
|
set(OPENMP_TEST_Fortran_COMPILER ${CMAKE_Fortran_COMPILER} CACHE STRING
|
|
|
|
"FORTRAN compiler to use for testing OpenMP runtime libraries.")
|
2017-11-29 19:31:43 +00:00
|
|
|
set(OPENMP_LLVM_TOOLS_DIR "" CACHE PATH "Path to LLVM tools for testing.")
|
[OpenMP] Use CMAKE_CXX_STANDARD for setting the C++ version
Previously, we tried to check whether the -std=c++17 option was
supported and manually add the flag. That doesn't work for compilers
that do support C++17 but use a different option syntax, like
clang-cl.
OpenMP itself probably doesn't specifically require C++17, therefore
CXX_STANDARD_REQUIRED is left off, but in some cases, we may
have code that only works in C++17 mode.
In particular, 46262cab24312c71717ca70a9d0700481aa59152 made a
refactoring that works when built with Clang in C++17 mode, but not
in C++14 mode. MSVC accepts the construct in both language modes.
For libomptarget, we've had specific checks that require C++17
(or the -std=c++17 option) to be supported. It's doubtful that
libomptarget has got any code which more specifically requires C++17;
this seems to be a remnant from when libomptarget was added
originally in 2467df6e4f04e3d0e8e78d662473ba1b87c0a885 / D14031.
At that point, the rest of OpenMP didn't require C++11, while
libomptarget did require it. Now, it's unlikely that anyone attempts
building it with a toolchain that doesn't support C++11.
At this point, we could also probably just set CXX_STANDARD_REQUIRED
to true, requiring C++17 as baseline for all the OpenMP libraries.
This fixes building OpenMP with clang-cl after
46262cab24312c71717ca70a9d0700481aa59152.
Differential Revision: https://reviews.llvm.org/D149726
2023-05-03 06:57:22 +00:00
|
|
|
|
|
|
|
set(CMAKE_CXX_STANDARD 17 CACHE STRING "C++ standard to conform to")
|
|
|
|
set(CMAKE_CXX_STANDARD_REQUIRED NO)
|
|
|
|
set(CMAKE_CXX_EXTENSIONS NO)
|
2017-11-29 19:31:48 +00:00
|
|
|
else()
|
|
|
|
set(OPENMP_ENABLE_WERROR ${LLVM_ENABLE_WERROR})
|
2022-08-19 02:44:46 +00:00
|
|
|
# If building in tree, we honor the same install suffix LLVM uses.
|
|
|
|
set(OPENMP_INSTALL_LIBDIR "lib${LLVM_LIBDIR_SUFFIX}")
|
2017-11-29 19:31:52 +00:00
|
|
|
|
|
|
|
if (NOT MSVC)
|
|
|
|
set(OPENMP_TEST_C_COMPILER ${LLVM_RUNTIME_OUTPUT_INTDIR}/clang)
|
|
|
|
set(OPENMP_TEST_CXX_COMPILER ${LLVM_RUNTIME_OUTPUT_INTDIR}/clang++)
|
|
|
|
else()
|
|
|
|
set(OPENMP_TEST_C_COMPILER ${LLVM_RUNTIME_OUTPUT_INTDIR}/clang.exe)
|
|
|
|
set(OPENMP_TEST_CXX_COMPILER ${LLVM_RUNTIME_OUTPUT_INTDIR}/clang++.exe)
|
|
|
|
endif()
|
[OpenMP] Use CMAKE_CXX_STANDARD for setting the C++ version
Previously, we tried to check whether the -std=c++17 option was
supported and manually add the flag. That doesn't work for compilers
that do support C++17 but use a different option syntax, like
clang-cl.
OpenMP itself probably doesn't specifically require C++17, therefore
CXX_STANDARD_REQUIRED is left off, but in some cases, we may
have code that only works in C++17 mode.
In particular, 46262cab24312c71717ca70a9d0700481aa59152 made a
refactoring that works when built with Clang in C++17 mode, but not
in C++14 mode. MSVC accepts the construct in both language modes.
For libomptarget, we've had specific checks that require C++17
(or the -std=c++17 option) to be supported. It's doubtful that
libomptarget has got any code which more specifically requires C++17;
this seems to be a remnant from when libomptarget was added
originally in 2467df6e4f04e3d0e8e78d662473ba1b87c0a885 / D14031.
At that point, the rest of OpenMP didn't require C++11, while
libomptarget did require it. Now, it's unlikely that anyone attempts
building it with a toolchain that doesn't support C++11.
At this point, we could also probably just set CXX_STANDARD_REQUIRED
to true, requiring C++17 as baseline for all the OpenMP libraries.
This fixes building OpenMP with clang-cl after
46262cab24312c71717ca70a9d0700481aa59152.
Differential Revision: https://reviews.llvm.org/D149726
2023-05-03 06:57:22 +00:00
|
|
|
|
2023-09-01 18:57:28 +00:00
|
|
|
# Check for flang
|
|
|
|
if (NOT MSVC)
|
|
|
|
set(OPENMP_TEST_Fortran_COMPILER ${LLVM_RUNTIME_OUTPUT_INTDIR}/flang-new)
|
|
|
|
else()
|
|
|
|
set(OPENMP_TEST_Fortran_COMPILER ${LLVM_RUNTIME_OUTPUT_INTDIR}/flang-new.exe)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# Set fortran test compiler if flang is found
|
|
|
|
if (EXISTS "${OPENMP_TEST_Fortran_COMPILER}")
|
|
|
|
message("Using local flang build at ${OPENMP_TEST_Fortran_COMPILER}")
|
|
|
|
else()
|
|
|
|
unset(OPENMP_TEST_Fortran_COMPILER)
|
2023-08-29 21:27:30 +00:00
|
|
|
endif()
|
|
|
|
|
[OpenMP] Use CMAKE_CXX_STANDARD for setting the C++ version
Previously, we tried to check whether the -std=c++17 option was
supported and manually add the flag. That doesn't work for compilers
that do support C++17 but use a different option syntax, like
clang-cl.
OpenMP itself probably doesn't specifically require C++17, therefore
CXX_STANDARD_REQUIRED is left off, but in some cases, we may
have code that only works in C++17 mode.
In particular, 46262cab24312c71717ca70a9d0700481aa59152 made a
refactoring that works when built with Clang in C++17 mode, but not
in C++14 mode. MSVC accepts the construct in both language modes.
For libomptarget, we've had specific checks that require C++17
(or the -std=c++17 option) to be supported. It's doubtful that
libomptarget has got any code which more specifically requires C++17;
this seems to be a remnant from when libomptarget was added
originally in 2467df6e4f04e3d0e8e78d662473ba1b87c0a885 / D14031.
At that point, the rest of OpenMP didn't require C++11, while
libomptarget did require it. Now, it's unlikely that anyone attempts
building it with a toolchain that doesn't support C++11.
At this point, we could also probably just set CXX_STANDARD_REQUIRED
to true, requiring C++17 as baseline for all the OpenMP libraries.
This fixes building OpenMP with clang-cl after
46262cab24312c71717ca70a9d0700481aa59152.
Differential Revision: https://reviews.llvm.org/D149726
2023-05-03 06:57:22 +00:00
|
|
|
# If not standalone, set CMAKE_CXX_STANDARD but don't set the global cache value,
|
|
|
|
# only set it locally for OpenMP.
|
|
|
|
set(CMAKE_CXX_STANDARD 17)
|
|
|
|
set(CMAKE_CXX_STANDARD_REQUIRED NO)
|
|
|
|
set(CMAKE_CXX_EXTENSIONS NO)
|
2017-11-29 19:31:43 +00:00
|
|
|
endif()
|
2016-02-05 07:00:13 +00:00
|
|
|
|
2017-11-29 19:31:48 +00:00
|
|
|
# Check and set up common compiler flags.
|
|
|
|
include(config-ix)
|
|
|
|
include(HandleOpenMPOptions)
|
|
|
|
|
2017-11-29 19:31:52 +00:00
|
|
|
# Set up testing infrastructure.
|
|
|
|
include(OpenMPTesting)
|
|
|
|
|
|
|
|
set(OPENMP_TEST_FLAGS "" CACHE STRING
|
|
|
|
"Extra compiler flags to send to the test compiler.")
|
2017-11-30 17:08:31 +00:00
|
|
|
set(OPENMP_TEST_OPENMP_FLAGS ${OPENMP_TEST_COMPILER_OPENMP_FLAGS} CACHE STRING
|
2017-11-29 19:31:52 +00:00
|
|
|
"OpenMP compiler flag to use for testing OpenMP runtime libraries.")
|
|
|
|
|
2017-11-22 17:15:18 +00:00
|
|
|
set(ENABLE_LIBOMPTARGET ON)
|
2017-03-21 18:19:09 +00:00
|
|
|
# Currently libomptarget cannot be compiled on Windows or MacOS X.
|
|
|
|
# Since the device plugins are only supported on Linux anyway,
|
|
|
|
# there is no point in trying to compile libomptarget on other OSes.
|
2023-01-18 18:39:58 +00:00
|
|
|
# 32-bit systems are not supported either.
|
2024-01-08 13:33:00 +00:00
|
|
|
if (APPLE OR WIN32 OR WASM OR NOT "cxx_std_17" IN_LIST CMAKE_CXX_COMPILE_FEATURES
|
|
|
|
OR NOT CMAKE_SIZEOF_VOID_P EQUAL 8 OR ${CMAKE_SYSTEM_NAME} MATCHES "AIX")
|
2017-07-26 13:55:00 +00:00
|
|
|
set(ENABLE_LIBOMPTARGET OFF)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
option(OPENMP_ENABLE_LIBOMPTARGET "Enable building libomptarget for offloading."
|
|
|
|
${ENABLE_LIBOMPTARGET})
|
2021-01-28 12:24:19 +00:00
|
|
|
option(OPENMP_ENABLE_LIBOMP_PROFILING "Enable time profiling for libomp." OFF)
|
2021-01-25 22:10:50 +00:00
|
|
|
|
2022-09-07 12:48:10 +00:00
|
|
|
# Header install location
|
|
|
|
if(${OPENMP_STANDALONE_BUILD})
|
|
|
|
set(LIBOMP_HEADERS_INSTALL_PATH "${CMAKE_INSTALL_INCLUDEDIR}")
|
|
|
|
else()
|
2023-06-03 06:29:44 +00:00
|
|
|
include(GetClangResourceDir)
|
|
|
|
get_clang_resource_dir(LIBOMP_HEADERS_INSTALL_PATH SUBDIR include)
|
2022-09-07 12:48:10 +00:00
|
|
|
endif()
|
|
|
|
|
2021-01-25 22:10:50 +00:00
|
|
|
# Build host runtime library, after LIBOMPTARGET variables are set since they are needed
|
|
|
|
# to enable time profiling support in the OpenMP runtime.
|
|
|
|
add_subdirectory(runtime)
|
|
|
|
|
2017-07-26 13:55:00 +00:00
|
|
|
if (OPENMP_ENABLE_LIBOMPTARGET)
|
2020-01-04 03:03:42 +00:00
|
|
|
# Check that the library can actually be built.
|
2017-11-29 19:31:48 +00:00
|
|
|
if (APPLE OR WIN32)
|
|
|
|
message(FATAL_ERROR "libomptarget cannot be built on Windows and MacOS X!")
|
[OpenMP] Use CMAKE_CXX_STANDARD for setting the C++ version
Previously, we tried to check whether the -std=c++17 option was
supported and manually add the flag. That doesn't work for compilers
that do support C++17 but use a different option syntax, like
clang-cl.
OpenMP itself probably doesn't specifically require C++17, therefore
CXX_STANDARD_REQUIRED is left off, but in some cases, we may
have code that only works in C++17 mode.
In particular, 46262cab24312c71717ca70a9d0700481aa59152 made a
refactoring that works when built with Clang in C++17 mode, but not
in C++14 mode. MSVC accepts the construct in both language modes.
For libomptarget, we've had specific checks that require C++17
(or the -std=c++17 option) to be supported. It's doubtful that
libomptarget has got any code which more specifically requires C++17;
this seems to be a remnant from when libomptarget was added
originally in 2467df6e4f04e3d0e8e78d662473ba1b87c0a885 / D14031.
At that point, the rest of OpenMP didn't require C++11, while
libomptarget did require it. Now, it's unlikely that anyone attempts
building it with a toolchain that doesn't support C++11.
At this point, we could also probably just set CXX_STANDARD_REQUIRED
to true, requiring C++17 as baseline for all the OpenMP libraries.
This fixes building OpenMP with clang-cl after
46262cab24312c71717ca70a9d0700481aa59152.
Differential Revision: https://reviews.llvm.org/D149726
2023-05-03 06:57:22 +00:00
|
|
|
elseif (NOT "cxx_std_17" IN_LIST CMAKE_CXX_COMPILE_FEATURES)
|
2022-12-20 19:39:44 +00:00
|
|
|
message(FATAL_ERROR "Host compiler must support C++17 to build libomptarget!")
|
2023-01-18 18:39:58 +00:00
|
|
|
elseif (NOT CMAKE_SIZEOF_VOID_P EQUAL 8)
|
|
|
|
message(FATAL_ERROR "libomptarget on 32-bit systems are not supported!")
|
2017-11-29 19:31:48 +00:00
|
|
|
endif()
|
|
|
|
|
2017-02-10 17:13:28 +00:00
|
|
|
add_subdirectory(libomptarget)
|
|
|
|
endif()
|
2017-11-29 19:31:52 +00:00
|
|
|
|
2019-11-18 00:23:31 +00:00
|
|
|
set(ENABLE_OMPT_TOOLS ON)
|
|
|
|
# Currently tools are not tested well on Windows or MacOS X.
|
|
|
|
if (APPLE OR WIN32)
|
|
|
|
set(ENABLE_OMPT_TOOLS OFF)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
option(OPENMP_ENABLE_OMPT_TOOLS "Enable building ompt based tools for OpenMP."
|
|
|
|
${ENABLE_OMPT_TOOLS})
|
|
|
|
if (OPENMP_ENABLE_OMPT_TOOLS)
|
|
|
|
add_subdirectory(tools)
|
|
|
|
endif()
|
|
|
|
|
2021-11-11 19:08:25 +00:00
|
|
|
option(OPENMP_MSVC_NAME_SCHEME "Build dll with MSVC naming scheme." OFF)
|
2020-09-16 21:15:56 +00:00
|
|
|
|
2022-12-14 04:36:30 +00:00
|
|
|
# Build libompd.so
|
|
|
|
add_subdirectory(libompd)
|
|
|
|
|
2020-09-16 21:15:56 +00:00
|
|
|
# Build documentation
|
|
|
|
add_subdirectory(docs)
|
|
|
|
|
2020-04-04 03:06:29 +00:00
|
|
|
# Now that we have seen all testsuites, create the check-openmp target.
|
2017-11-29 19:31:52 +00:00
|
|
|
construct_check_openmp_target()
|