ComicSansMS / CMake_Modules

A simple Hello World example for C++20 Modules support with CMake
The Unlicense
8 stars 0 forks source link

CMake Error Missing variable CMAKE_EXPERIMENTAL_CXX_SCANDEP_SOURCE #2

Open insinfo opened 1 year ago

insinfo commented 1 year ago

@ComicSansMS I am accepting this error with your example on Windows with cmake 3.27.6 and g++.exe (GCC) 13.2.0

C:\cmake\bin\cmake.exe -DCMAKE_BUILD_TYPE=Debug -DCMAKE_MAKE_PROGRAM=C:/ninja/ninja.exe -DCMAKE_C_COMPILER=C:/w64devkit/bin/gcc.exe -DCMAKE_CXX_COMPILER=C:/w64devkit/bin/g++.exe -G Ninja -S C:\my_projects_cpp\teste_cpp20 -B C:\my_projects_cpp\teste_cpp20\cmake-build-debug
-- The C compiler identification is GNU 13.2.0
-- The CXX compiler identification is GNU 13.2.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/w64devkit/bin/gcc.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/w64devkit/bin/g++.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Warning (dev) at CMakeLists.txt:14 (target_sources):
  CMake's C++ module support is experimental.  It is meant only for
  experimentation and feedback to CMake developers.
This warning is for project developers.  Use -Wno-dev to suppress it.

-- Configuring done (1.8s)
CMake Error: Error required internal CMake variable not set, cmake may not be built correctly.
Missing variable is:
CMAKE_EXPERIMENTAL_CXX_SCANDEP_SOURCE
-- Generating done (0.0s)
CMake Generate step failed.  Build files cannot be regenerated correctly.

[Failed to reload]
cmake_minimum_required(VERSION 3.27)

set(CMAKE_EXPERIMENTAL_CXX_MODULE_CMAKE_API aa1f7df0-828a-4fcd-9afc-2dc80491aca7)

project(modules-example)

set(CMAKE_CXX_STANDARD 20)

add_executable(demo)
target_sources(demo
        PUBLIC
        main.cpp
)
target_sources(demo
        PUBLIC
        FILE_SET all_my_modules TYPE CXX_MODULES FILES
        helloworld.cppm
)

set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT demo)
// helloworld.cppm
module;

#include <iostream>

export module helloworld;  // module declaration
//import <iostream>;         // import declaration

export void hello() {      // export declaration
    std::cout << "Hello world from module!\n";
}

// main.cpp
import helloworld;  // import declaration

#include <iostream>
int main() {
    hello();
    std::cout << "Hello world from main!\n";
    return 0;
}