CheckLanguage inconsistent with enable_language
Version 1
cmake_minimum_required(VERSION 3.12)
project(my_project LANGUAGES CXX)
include(CheckLanguage)
check_language(C)
if (CMAKE_C_COMPILER)
enable_language(C)
endif()
Version 2
cmake_minimum_required(VERSION 3.12)
project(my_project LANGUAGES CXX)
enable_language(C)
Invoke with mkdir build; cd build; CXX=/path/to/nondefault/g++ cmake ..
If /path/to/nondefault/g++
is not the "default compiler" that would be found with cmake ..
, the results of version 1 and version 2 are different, because enable_language
gives priority to paths where other compilers have already been found.
Version 1:
-- The CXX compiler identification is GNU 9.0.0
-- Check for working CXX compiler: /path/to/nondefault/g++
-- Check for working CXX compiler: /path/to/nondefault/g++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Looking for a C compiler
-- Looking for a C compiler - /usr/bin/cc
-- The C compiler identification is GNU 8.3.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /tmp/demonstrate/build
Version 2:
-- The CXX compiler identification is GNU 9.0.0
-- Check for working CXX compiler: /path/to/nondefault/g++
-- Check for working CXX compiler: /path/to/nondefault/g++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- The C compiler identification is GNU 9.0.0
-- Check for working C compiler: /path/to/nondefault/gcc
-- Check for working C compiler: /path/to/nondefault/gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /tmp/demonstrate/build
I don't think this is a very critical issue, but it looks like for the test project, CheckLanguage needs to enable the same languages that have been enabled in the calling project... But I am not even sure, if there is a deterministic way to let check_language
determine the same compilers as enable_language
.