1 #===-- runtime/CMakeLists.txt ----------------------------------------------===#
3 # Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 # See https://llvm.org/LICENSE.txt for license information.
5 # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 #===------------------------------------------------------------------------===#
9 if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
10 cmake_minimum_required(VERSION 3.13.4)
11 if ("${CMAKE_VERSION}" VERSION_LESS "3.20.0")
13 "Your CMake version is ${CMAKE_VERSION}. Starting with LLVM 17.0.0, the "
14 "minimum version of CMake required to build LLVM will become 3.20.0, and "
15 "using an older CMake will become an error. Please upgrade your CMake to "
16 "at least 3.20.0 now to avoid issues in the future!")
19 project(FlangRuntime C CXX)
21 set(CMAKE_CXX_STANDARD 17)
22 set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
23 set(CMAKE_CXX_EXTENSIONS OFF)
25 set(FLANG_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/..")
27 set(LLVM_COMMON_CMAKE_UTILS "${FLANG_SOURCE_DIR}/../cmake")
28 set(LLVM_CMAKE_UTILS "${FLANG_SOURCE_DIR}/../llvm/cmake")
30 # Add path for custom modules
31 list(INSERT CMAKE_MODULE_PATH 0
32 "${FLANG_SOURCE_DIR}/cmake"
33 "${FLANG_SOURCE_DIR}/cmake/modules"
34 "${LLVM_COMMON_CMAKE_UTILS}"
35 "${LLVM_COMMON_CMAKE_UTILS}/Modules"
37 "${LLVM_CMAKE_UTILS}/modules"
42 include(HandleLLVMOptions)
44 include(TestBigEndian)
45 test_big_endian(IS_BIGENDIAN)
47 add_compile_definitions(FLANG_BIG_ENDIAN=1)
49 add_compile_definitions(FLANG_LITTLE_ENDIAN=1)
51 include_directories(BEFORE
52 ${FLANG_SOURCE_DIR}/include)
55 include(CheckCXXSymbolExists)
56 include(CheckCXXSourceCompiles)
57 check_cxx_symbol_exists(strerror string.h HAVE_STRERROR)
58 check_cxx_symbol_exists(strerror_r string.h HAVE_STRERROR_R)
59 # Can't use symbol exists here as the function is overloaded in C++
60 check_cxx_source_compiles(
64 return strerror_s(buf, 4096, 0);
69 check_cxx_compiler_flag(-fno-lto FLANG_RUNTIME_HAS_FNO_LTO_FLAG)
70 if (FLANG_RUNTIME_HAS_FNO_LTO_FLAG)
71 set(NO_LTO_FLAGS "-fno-lto")
76 if (NOT (HAVE_STRERROR OR HAVE_STRERROR_R OR HAVE_DECL_STRERROR_S))
77 message(FATAL_ERROR "None of strerror, strerror_r, strerror_s found.")
80 configure_file(config.h.cmake config.h)
81 # include_directories is used here instead of target_include_directories
82 # because add_flang_library creates multiple objects (STATIC/SHARED, OBJECT)
83 # with different names
84 include_directories(AFTER ${CMAKE_CURRENT_BINARY_DIR})
86 append(${NO_LTO_FLAGS} CMAKE_C_FLAGS)
87 append(${NO_LTO_FLAGS} CMAKE_CXX_FLAGS)
89 # Disable libstdc++/libc++ assertions, even in an LLVM_ENABLE_ASSERTIONS build,
90 # to avoid an unwanted dependency on libstdc++/libc++.so.
91 add_definitions(-U_GLIBCXX_ASSERTIONS)
92 add_definitions(-U_LIBCPP_ENABLE_ASSERTIONS)
94 add_subdirectory(FortranMain)
96 add_flang_library(FortranRuntime
97 ISO_Fortran_binding.cpp
155 INSTALL_WITH_TOOLCHAIN