I am trying to run a very simple C++ program during configuration. My first attempt:
Test.cxx:
#include <iostream>
int main()
{
std::cout << "test" << std::endl;
}
CMakeLists.txt
cmake_minimum_required(VERSION 3.14)
project(test LANGUAGES CXX)
try_run(
RUN_RESULT
COMPILE_RESULT
${CMAKE_SOURCE_DIR}/Test.cxx
COMPILE_OUTPUT_VARIABLE COMPILEOUT
RUN_OUTPUT_VARIABLE RUNOUT
)
But got this:
CMake Error ...
The test project needs language C which is not enabled.
I was confused by the message and first thought I needed to tell try_run somehow which language it needs to compile, but couldn’t find any according information in the documentation…
I then realized that I had forgot to specify SOURCES
in front of my .cxx file. I know it was my stupid mistake, but if possible, it might help future users to get a more meaningful error message, such as “No source files specified” in that case?