modules
modules copied to clipboard
Build fails if -Wpedantic-errors or -Weverything compiler flags are set
as the title says, the build process fails if either flags are included in my CMAKE_CXX_FLAGS. I've provided a replication of the error:
error:
CMake Error at cmake/modules.cmake:135 (add_library):
No SOURCES given to target: MODULES
Call Stack (most recent call first):
CMakeLists.txt:27 (add_module_library)
file structure:
.
├── cmake
│ └── modules.cmake
├── CMakeLists.txt
└── src
├── hello.cpp
├── main.cpp
└── subdir
└── bye.cpp
CMakeLists.txt:
cmake_minimum_required(VERSION 3.26)
project(modtest)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# this works
#set(CMAKE_CXX_FLAGS "-w -Wall -Wextra -Werror -Wshadow -Wconversion -Wunused -Wpedantic")
# but this doesn't
set(CMAKE_CXX_FLAGS "-w -Wall -Wextra -Werror -Wshadow -Wconversion -Wunused -Wpedantic -Wpedantic-errors -Weverything")
set(PROJECT "${CMAKE_CURRENT_SOURCE_DIR}")
set(TARGET "modtest")
file(GLOB_RECURSE SRC "${PROJECT}/src/*.cpp")
add_executable(${TARGET} ${PROJECT}/src/main.cpp)
include(cmake/modules.cmake)
add_module_library(MODULES ${SRC})
target_link_libraries(${TARGET} PRIVATE MODULES)
main:
import hello;
import bye;
int main() {
hello();
bye();
}
hello:
module;
#include <iostream>
export module hello;
export void hello() {
std::cout << "hello\n";
}
bye:
module;
#include <iostream>
export module bye;
export void bye() {
std::cout << "bye\n";
}