Can you help me?
Project is quite simple:
` // file DataLoader.cxx
export module data_loader;
export class DataLoader {
public:
virtual void instanceInfo() const = 0;
};
// file FileLoader.cxx
export module file_loader;
import data_loader;
import <iostream>;
import <string>;
export enum class FileType { csv };
export class FileLoader: public DataLoader {
public:
FileLoader(FileType fileType, std::string filePath);
FileLoader();
~FileLoader();
void instanceInfo() const override;
private:
static int count;
FileType fileType;
std::string filePath;
};
FileLoader::FileLoader(FileType fileType, std::string filePath):
fileType(fileType), filePath(filePath) {
++count;
}
FileLoader::FileLoader() { ++count; }
FileLoader::~FileLoader() { --count; }
int FileLoader::count = 0;
export void FileLoader::instanceInfo() const {
std::cout << "File #" << count;
if (filePath.length())
std::cout << " (" << filePath << ")";
std::cout << std::endl;
}
// file main.cxx
import file_loader;
import <memory>;
using namespace std;
int main() {
unique_ptr<FileLoader> fl(new FileLoader());
fl->instanceInfo();
unique_ptr<FileLoader> fl1(new FileLoader(FileType::csv, "test.csv"));
fl1->instanceInfo();
}
// file CMakeLists.txt
cmake_minimum_required(VERSION 3.28)
project(cpp-data-viz LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 20)
add_library(data_loader)
target_sources(data_loader PUBLIC
FILE_SET CXX_MODULES
FILES
DataLoader.cxx)
add_library(file_loader)
target_sources(file_loader PUBLIC
FILE_SET CXX_MODULES
FILES
FileLoader.cxx)
add_executable(main main.cxx)
target_link_libraries(main file_loader data_loader)`
But I get the error message below:
` cmake -GNinja ..
-- Configuring done (0.0s)
CMake Error in CMakeLists.txt:
The target named "data_loader" has C++ sources that may use modules, but
the compiler does not provide a way to discover the import graph
dependencies. See the cmake-cxxmodules(7) manual for details. Use the
CMAKE_CXX_SCAN_FOR_MODULES variable to enable or disable scanning.
CMake Error in CMakeLists.txt:
The target named "file_loader" has C++ sources that may use modules, but
the compiler does not provide a way to discover the import graph
dependencies. See the cmake-cxxmodules(7) manual for details. Use the
CMAKE_CXX_SCAN_FOR_MODULES variable to enable or disable scanning.
-- Generating done (0.0s)
CMake Generate step failed. Build files cannot be regenerated correctly.`
VERSIONS:
` g++ version 11.4.0
cmake version 3.29.3
ninja version 1.12.1
`
I just want to be able to compile and run C++20 modules with CMake, but it’s kind of tricky.