Skip to content

Commit f571409

Browse files
committedApr 13, 2017
[CMake][runtimes] Use -nodefaultlibs for the runtimes build
We may not have a working C++ standard library at this point so we shouldn't rely on it when running CMake checks. Differential Revision: https://reviews.llvm.org/D31942 llvm-svn: 300260
1 parent 1505ba8 commit f571409

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed
 

‎llvm/runtimes/CMakeLists.txt

+19-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR})
2929
# CMake module path.
3030
list(INSERT CMAKE_MODULE_PATH 0
3131
"${CMAKE_CURRENT_SOURCE_DIR}/../cmake"
32-
"${CMAKE_CURRENT_SOURCE_DIR}/../cmake/Modules"
32+
"${CMAKE_CURRENT_SOURCE_DIR}/../cmake/modules"
3333
"${LLVM_BINARY_DIR}/lib/cmake/llvm"
3434
)
3535

@@ -65,10 +65,28 @@ if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR})
6565
set(LLVM_ENABLE_LIBCXX ON CACHE BOOL "")
6666
endif()
6767

68+
set(SAFE_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
69+
set(SAFE_CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
70+
71+
include(CheckLibraryExists)
72+
include(CheckCCompilerFlag)
73+
74+
check_library_exists(c fopen "" LLVM_HAS_C_LIB)
75+
check_c_compiler_flag(-nodefaultlibs LLVM_HAS_NODEFAULTLIBS_FLAG)
76+
if(LLVM_HAS_NODEFAULTLIBS_FLAG)
77+
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -nodefaultlibs")
78+
if(LLVM_HAS_C_LIB)
79+
list(APPEND CMAKE_REQUIRED_LIBRARIES c)
80+
endif()
81+
endif()
82+
6883
# Handle common options used by all runtimes.
6984
include(AddLLVM)
7085
include(HandleLLVMOptions)
7186

87+
set(CMAKE_REQUIRED_FLAGS ${SAFE_CMAKE_REQUIRED_FLAGS})
88+
set(CMAKE_REQUIRED_LIBRARIES ${SAFE_CMAKE_REQUIRED_LIBRARIES})
89+
7290
foreach(entry ${runtimes})
7391
get_filename_component(projName ${entry} NAME)
7492

0 commit comments

Comments
 (0)
Please sign in to comment.