I have an empty project with some dummy CMakeLists.txts only, below is the structure of my directory and CMake files.
dummy
|
+- CMakeLists.txt
|
+- sub
|
+- CMakeListx.txt
# dummy/CMakeLists.txt
cmake_minimum_required(VERSION 3.16)
project(dummy)
set(CMAKE_CXX_COMPILER g++) # #1
add_subdirectory(sub)
# dummy/sub/CMakeLists.txt
cmake_minimum_required(VERSION 3.16)
project(sub) # #2
I do this because I want project sub be ready to be built standalone, while building it as a part of project dummy is also desirable.
The fact is, it doesn't work.
Trying to generate build files of project dummy gives me an error:
#####
CMake Error at sub/CMakeLists.txt:2 (project):
The CMAKE_CXX_COMPILER:
g++
is not a full path and was not found in the PATH.
Tell CMake where to find the compiler by setting either the environment
variable "CXX" or the CMake cache entry CMAKE_CXX_COMPILER to the full path
to the compiler, or to the compiler name if it is in the PATH.
-- Configuring incomplete, errors occurred!
#####
g++ is not the case, it's the my default compiler and placed in PATH appropriately.
But if I change line #1 to set($ENV{CXX} g++) (set env CXX), or remove line #2, build files can be generated successfully.
But what's the matter? Am I misunderstanding some basic concepts of CMake?