test_big_endian does not work with /WX linker flag in LTCG
This is on Windows, with Visual Studio 2017, and CMake 3.13. The files I have are:
hello.c:
#include <stdio.h>
int main()
{
printf("Hello World\n");
return 0;
}
CMakeLists.txt:
cmake_minimum_required(VERSION 3.9)
project(test_test_big_endian LANGUAGES C)
include(TestBigEndian)
# Set our important flags
set(CMAKE_C_FLAGS "/GL /O2 /WX /sdl")
set(_link_wx "")
set(_link_wx /WX)
set(CMAKE_EXE_LINKER_FLAGS "/LTCG:INCREMENTAL ${_link_wx}")
test_big_endian(WORDS_BIGENDIAN)
add_executable(hello hello.c)
To reproduce the issue from inside a build
directory:
git clean -fdx && cmake -G Ninja -DCMAKE_C_COMPILER=cl .. && ninja
The output I see is:
-- The C compiler identification is MSVC 19.16.27027.1
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/BuildTools/VC/Tools/MSVC/14.16.2702
3/bin/Hostx64/x64/cl.exe
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/BuildTools/VC/Tools/MSVC/14.16.2702
3/bin/Hostx64/x64/cl.exe -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check if the system is big endian
-- Searching 16 bit integer
-- Looking for sys/types.h
-- Looking for sys/types.h - not found
-- Looking for stdint.h
-- Looking for stdint.h - not found
-- Looking for stddef.h
-- Looking for stddef.h - not found
-- Check size of unsigned short
-- Check size of unsigned short - failed
-- Check size of unsigned int
-- Check size of unsigned int - failed
-- Check size of unsigned long
-- Check size of unsigned long - failed
CMake Error at C:/Program Files/CMake/share/cmake-3.13/Modules/TestBigEndian.cmake:49 (message):
no suitable type found
Call Stack (most recent call first):
CMakeLists.txt:13 (test_big_endian)
-- Configuring incomplete, errors occurred!
See also "C:/work/cmake-bug/build/CMakeFiles/CMakeOutput.log".
See also "C:/work/cmake-bug/build/CMakeFiles/CMakeError.log".
If I comment out set(_link_wx /WX)
then I don't get the error.