♻️ 使用module重构所有代码

This commit is contained in:
csh
2025-12-07 23:07:03 +08:00
parent 549f1d1b0a
commit f7d5a74615
369 changed files with 2272844 additions and 2202476 deletions
@@ -0,0 +1,30 @@
cmake_minimum_required(VERSION 4.0)
project(test_module LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
if(NOT CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
message(WARNING "test_module requires Clang for C++ modules; skipping")
return()
endif()
set(CMAKE_EXPERIMENTAL_CXX_MODULE_DYNDEP 1)
add_executable(test_module main.cppm)
target_sources(
test_module
PRIVATE
FILE_SET cxx_modules TYPE CXX_MODULES
BASE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}
FILES main.cppm math.cppm math2.cppm)
target_compile_features(test_module PRIVATE cxx_std_23)
target_compile_options(
test_module
PRIVATE
# Re-enable implicit modules for Clang std import within this test target
-fimplicit-modules -fimplicit-module-maps
-Wall -Wextra -Wpedantic $<$<CONFIG:Debug>:-g -O0>
-Wno-import-implementation-partition-unit-in-interface-unit
$<$<CONFIG:Release>:-O3>)
+17
View File
@@ -0,0 +1,17 @@
module;
export module lsp.test.module_demo.main;
import std;
import math;
import math2;
int main()
{
std::cout << "hello std module\n";
std::vector<int> v{ 1, 2, 3 };
math::print_sum(1, 2);
math2::print_sum(2, 3);
return 0;
}
+19
View File
@@ -0,0 +1,19 @@
module;
import std;
export module math;
namespace math
{
export int add(int a, int b)
{
return a + b;
}
export void print_sum(int a, int b)
{
std::cout << a << " + " << b << " = " << add(a, b) << "\n";
}
}
+19
View File
@@ -0,0 +1,19 @@
module;
import std;
export module math2;
namespace math2
{
export int add(int a, int b)
{
return a + b;
}
export void print_sum(int a, int b)
{
std::cout << a << " + " << b << " = " << add(a, b) << std::endl;
}
}