Files
CMake/Tests/RunCMake/try_compile/LinkOptions.cmake
Zsolt Parragi 091afa7342 Tests: Teach tests when to treat clang-cl as MSVC
* Disable the system include unused variable test in ExportImport when
  clang is in MSVC compatible mode.

* Disable CxxDialect testcase when clang is in MSVC compatible mode, as
  it doesn't support `typeof`.

* Teach Module.WriteCompilerDetectionHeader to treat clang-cl as MSVC.

* Disable the SystemIncludeDirectories testcase within
  IncludeDirectories when clang is in MSVC compatible mode.

* Disable the CMakeOnly.CheckCXXCompilerFlag testcase when clang is in
  MSVC compatible mode.

* Treat clang-cl as MSVC in LinkOptions.cmake in the try_run and
  try_compile testcases.
2019-02-11 15:04:28 +01:00

39 lines
1.1 KiB
CMake

enable_language(C)
cmake_policy(SET CMP0054 NEW)
set (lib_name "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}lib${CMAKE_STATIC_LIBRARY_SUFFIX}")
if (CMAKE_SYSTEM_NAME STREQUAL "Windows")
if (RunCMake_C_COMPILER_ID STREQUAL "MSVC" OR "x${CMAKE_C_SIMULATE_ID}" STREQUAL "xMSVC")
if (CMAKE_SIZEOF_VOID_P EQUAL 4)
set (undef_flag /INCLUDE:_func)
else()
set (undef_flag /INCLUDE:func)
endif()
else()
if (CMAKE_SIZEOF_VOID_P EQUAL 4)
set (undef_flag -u _func)
else()
set (undef_flag -u func)
endif()
endif()
elseif (CMAKE_SYSTEM_NAME STREQUAL "Darwin")
set (undef_flag -u _func)
else()
set (undef_flag -u func)
endif()
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
try_compile(result ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/lib.c
COPY_FILE "${lib_name}")
set(CMAKE_TRY_COMPILE_TARGET_TYPE EXECUTABLE)
try_compile(result ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/main.c
OUTPUT_VARIABLE out
LINK_OPTIONS ${undef_flag} "${lib_name}")
if(NOT result)
message(FATAL_ERROR "try_compile(... LINK_OPTIONS ...) failed:\n${out}")
endif()