vitaut/modules

Simple C++20 module support for CMake

CMake

213

89 commits

updated Nov 17, 2023

See the code

README

Simple C++20 module support for CMake

Provides the add_module_library CMake function that is a wrapper around add_library with additional module-specific rules.

This module currently supports:

  • Clang 15+
  • GCC 11+
  • MSVC 19.28+

This module can also fallback to a non-modular library for compatibility.

Projects using add_module_library:

  • {fmt}: a modern formatting library

Example

hello.cc:

module;

#include <cstdio>

export module hello;

export void hello() { std::printf("Hello, modules!\n"); }

main.cc:

import hello;

int main() { hello(); }

CMakeLists.txt:

cmake_minimum_required(VERSION 3.11)
project(HELLO CXX)

include(modules.cmake)

add_module_library(hello hello.cc)

add_executable(main main.cc)
target_link_libraries(main hello)

Building with clang:

CXX=clang++ cmake .
make

Running:

$ ./main
Hello, modules!

License

The code is distributed under the permissive MIT license with an optional exception that allows distributing binary code without attribution.

Contributors

vitaut

61 commits

Mixaill

24 commits

Klaim

2 commits

namniav

1 commits

Languages

CMake

96.4%

C++

3.3%

vitaut/modules

Simple C++20 module support for CMake

CMake

213

89 commits

updated Nov 17, 2023

See the code

README

Simple C++20 module support for CMake

Provides the add_module_library CMake function that is a wrapper around add_library with additional module-specific rules.

This module currently supports:

  • Clang 15+
  • GCC 11+
  • MSVC 19.28+

This module can also fallback to a non-modular library for compatibility.

Projects using add_module_library:

  • {fmt}: a modern formatting library

Example

hello.cc:

module;

#include <cstdio>

export module hello;

export void hello() { std::printf("Hello, modules!\n"); }

main.cc:

import hello;

int main() { hello(); }

CMakeLists.txt:

cmake_minimum_required(VERSION 3.11)
project(HELLO CXX)

include(modules.cmake)

add_module_library(hello hello.cc)

add_executable(main main.cc)
target_link_libraries(main hello)

Building with clang:

CXX=clang++ cmake .
make

Running:

$ ./main
Hello, modules!

License

The code is distributed under the permissive MIT license with an optional exception that allows distributing binary code without attribution.

Contributors

vitaut

61 commits

Mixaill

24 commits

Klaim

2 commits

namniav

1 commits

Languages

CMake

96.4%

C++

3.3%