I would like to create a basic library using c++20 modules and import it in an external simple project. I´m focus of the output package from a library based on modules.
I watched this video from CPPCon about export and packaging modules : https://youtu.be/-p9lvvV8F-w. Based on the conclusion of this talk, the best solution would be to create a modulde interface (.cc file) with a lib binary such as .dll or .lib.
I´m using this basic CMakelists.txt
cmake_minimum_required(VERSION 3.28)
project(MyLib LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_EXTENSIONS NO)
set(CMAKE_CXX_STANDARD_REQUIRED YES)
add_library(foo)
target_sources(foo
PUBLIC
FILE_SET CXX_MODULES FILES
foo.cppm)
Content of foo.cpm is from module exemple and it´s really simple :
module;
#include <iostream>
export module foo;
export class foo {
public:
foo() = default;
~foo() = default;
void helloworld();
};
void foo::helloworld() { std::cout << "hello world\n"; }
The only output I got for the moment is the .lib file. How can I generate the module interface and how to generate a decent package which can be used by the consumer project ?
We can consider the consumer will use the exact same dev environment to avoid binary compatibility issues.
My setup should be compliant with the latest requirements for modules :
- cmake 3.28
- MSVC 17.9.3