diff options
author | Uwe Koloska <uwe.koloska@voiceinterconnect.de> | 2017-02-15 18:21:35 +0100 |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2017-02-15 15:08:37 -0500 |
commit | ac0962cead1db76b44cbb9d9a413956ca31a7982 (patch) | |
tree | 14fd05771cac3a990c166556ccce205e55b0c331 /Modules/TestBigEndian.cmake | |
parent | 72cfb3c3d2e8f6167cf08289691f7b0c61d0d331 (diff) | |
download | cmake-ac0962cead1db76b44cbb9d9a413956ca31a7982.tar.gz |
TestBigEndian: Fix to work with CXX without C
Diffstat (limited to 'Modules/TestBigEndian.cmake')
-rw-r--r-- | Modules/TestBigEndian.cmake | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/Modules/TestBigEndian.cmake b/Modules/TestBigEndian.cmake index 085be22d61..cc627d0168 100644 --- a/Modules/TestBigEndian.cmake +++ b/Modules/TestBigEndian.cmake @@ -19,21 +19,29 @@ macro(TEST_BIG_ENDIAN VARIABLE) message(STATUS "Check if the system is big endian") message(STATUS "Searching 16 bit integer") + if(CMAKE_C_COMPILER_LOADED) + set(_test_language "C") + elseif(CMAKE_CXX_COMPILER_LOADED) + set(_test_language "CXX") + else() + message(FATAL_ERROR "TEST_BIG_ENDIAN needs either C or CXX language enabled") + endif() + include(CheckTypeSize) - CHECK_TYPE_SIZE("unsigned short" CMAKE_SIZEOF_UNSIGNED_SHORT) + CHECK_TYPE_SIZE("unsigned short" CMAKE_SIZEOF_UNSIGNED_SHORT LANGUAGE ${_test_language}) if(CMAKE_SIZEOF_UNSIGNED_SHORT EQUAL 2) message(STATUS "Using unsigned short") set(CMAKE_16BIT_TYPE "unsigned short") else() - CHECK_TYPE_SIZE("unsigned int" CMAKE_SIZEOF_UNSIGNED_INT) + CHECK_TYPE_SIZE("unsigned int" CMAKE_SIZEOF_UNSIGNED_INT LANGUAGE ${_test_language}) if(CMAKE_SIZEOF_UNSIGNED_INT) message(STATUS "Using unsigned int") set(CMAKE_16BIT_TYPE "unsigned int") else() - CHECK_TYPE_SIZE("unsigned long" CMAKE_SIZEOF_UNSIGNED_LONG) + CHECK_TYPE_SIZE("unsigned long" CMAKE_SIZEOF_UNSIGNED_LONG LANGUAGE ${_test_language}) if(CMAKE_SIZEOF_UNSIGNED_LONG) message(STATUS "Using unsigned long") set(CMAKE_16BIT_TYPE "unsigned long") @@ -45,17 +53,21 @@ macro(TEST_BIG_ENDIAN VARIABLE) endif() + if(_test_language STREQUAL "CXX") + set(_test_file "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/TestEndianess.cpp") + else() + set(_test_file "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/TestEndianess.c") + endif() configure_file("${CMAKE_ROOT}/Modules/TestEndianess.c.in" - "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/TestEndianess.c" + ${_test_file} @ONLY) - file(READ "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/TestEndianess.c" - TEST_ENDIANESS_FILE_CONTENT) + file(READ ${_test_file} TEST_ENDIANESS_FILE_CONTENT) try_compile(HAVE_${VARIABLE} "${CMAKE_BINARY_DIR}" - "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/TestEndianess.c" + ${_test_file} OUTPUT_VARIABLE OUTPUT COPY_FILE "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/TestEndianess.bin" ) |