Skip to content
This repository was archived by the owner on Feb 5, 2019. It is now read-only.

Commit bba676f

Browse files
committed
[CMake] Introduce llvm_update_compile_flags(target_name) to update compile flags in target properties.
FIXME: Just add_unittest() is using it. FIXME: Cooperate with source properties. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@198683 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 9cca551 commit bba676f

File tree

1 file changed

+36
-24
lines changed

1 file changed

+36
-24
lines changed

cmake/modules/AddLLVM.cmake

Lines changed: 36 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,24 @@ include(LLVMParseArguments)
22
include(LLVMProcessSources)
33
include(LLVM-Config)
44

5+
function(llvm_update_compile_flags name)
6+
get_property(target_compile_flags TARGET ${name} PROPERTY COMPILE_FLAGS)
7+
if(NOT "${LLVM_COMPILE_FLAGS}" STREQUAL "")
8+
set(target_compile_flags "${target_compile_flags} ${LLVM_COMPILE_FLAGS}")
9+
endif()
10+
if(LLVM_NO_RTTI)
11+
list(APPEND LLVM_COMPILE_DEFINITIONS GTEST_HAS_RTTI=0)
12+
if (LLVM_COMPILER_IS_GCC_COMPATIBLE)
13+
set(target_compile_flags "${target_compile_flags} -fno-rtti")
14+
elseif (MSVC)
15+
llvm_replace_compiler_option(target_compile_flags "/GR" "/GR-")
16+
endif ()
17+
endif()
18+
19+
set_property(TARGET ${name} PROPERTY COMPILE_FLAGS "${target_compile_flags}")
20+
set_property(TARGET ${name} APPEND PROPERTY COMPILE_DEFINITIONS ${LLVM_COMPILE_DEFINITIONS})
21+
endfunction()
22+
523
function(add_llvm_symbol_exports target_name export_file)
624
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
725
set(native_export_file "${target_name}.exports")
@@ -343,6 +361,23 @@ function(add_unittest test_suite test_name)
343361
set(EXCLUDE_FROM_ALL ON)
344362
endif()
345363

364+
# Visual Studio 2012 only supports up to 8 template parameters in
365+
# std::tr1::tuple by default, but gtest requires 10
366+
if (MSVC AND MSVC_VERSION EQUAL 1700)
367+
list(APPEND LLVM_COMPILE_DEFINITIONS _VARIADIC_MAX=10)
368+
endif ()
369+
370+
include_directories(${LLVM_MAIN_SRC_DIR}/utils/unittest/googletest/include)
371+
if (NOT LLVM_ENABLE_THREADS)
372+
list(APPEND LLVM_COMPILE_DEFINITIONS GTEST_HAS_PTHREAD=0)
373+
endif ()
374+
375+
if (SUPPORTS_NO_VARIADIC_MACROS_FLAG)
376+
set(LLVM_COMPILE_FLAGS "-Wno-variadic-macros")
377+
endif ()
378+
379+
set(LLVM_NO_RTTI ON)
380+
346381
add_llvm_executable(${test_name} ${ARGN})
347382
set(outdir ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR})
348383
set_output_directory(${test_name} ${outdir} ${outdir})
@@ -357,30 +392,7 @@ function(add_unittest test_suite test_name)
357392
if (NOT ${test_suite_folder} STREQUAL "NOTFOUND")
358393
set_property(TARGET ${test_name} PROPERTY FOLDER "${test_suite_folder}")
359394
endif ()
360-
361-
# Visual Studio 2012 only supports up to 8 template parameters in
362-
# std::tr1::tuple by default, but gtest requires 10
363-
if (MSVC AND MSVC_VERSION EQUAL 1700)
364-
set_property(TARGET ${test_name} APPEND PROPERTY COMPILE_DEFINITIONS _VARIADIC_MAX=10)
365-
endif ()
366-
367-
include_directories(${LLVM_MAIN_SRC_DIR}/utils/unittest/googletest/include)
368-
set_property(TARGET ${test_name} APPEND PROPERTY COMPILE_DEFINITIONS GTEST_HAS_RTTI=0)
369-
if (NOT LLVM_ENABLE_THREADS)
370-
set_property(TARGET ${test_name} APPEND PROPERTY COMPILE_DEFINITIONS GTEST_HAS_PTHREAD=0)
371-
endif ()
372-
373-
get_property(target_compile_flags TARGET ${test_name} PROPERTY COMPILE_FLAGS)
374-
if (LLVM_COMPILER_IS_GCC_COMPATIBLE)
375-
set(target_compile_flags "${target_compile_flags} -fno-rtti")
376-
elseif (MSVC)
377-
llvm_replace_compiler_option(target_compile_flags "/GR" "/GR-")
378-
endif ()
379-
380-
if (SUPPORTS_NO_VARIADIC_MACROS_FLAG)
381-
set(target_compile_flags "${target_compile_flags} -Wno-variadic-macros")
382-
endif ()
383-
set_property(TARGET ${test_name} PROPERTY COMPILE_FLAGS "${target_compile_flags}")
395+
llvm_update_compile_flags(${test_name})
384396
endfunction()
385397

386398
# This function provides an automatic way to 'configure'-like generate a file

0 commit comments

Comments
 (0)