Skip to content

Commit

Permalink
msvc import std
Browse files Browse the repository at this point in the history
  • Loading branch information
huangqinjin committed Sep 23, 2023
1 parent 1909990 commit 49640bb
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 0 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ add_subdirectory(named-module)
add_subdirectory(module-partition)
add_subdirectory(module-impl)
# add_subdirectory(header-unit)
add_subdirectory(import-std)
26 changes: 26 additions & 0 deletions import-std/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
cmake_minimum_required(VERSION 3.27)
project(import-std)

set(CMAKE_CXX_STANDARD 23)

add_executable(${PROJECT_NAME} main.cpp)
add_test(NAME ${PROJECT_NAME} COMMAND ${PROJECT_NAME})

if(CMAKE_GENERATOR MATCHES "Visual Studio")
# https://gitlab.kitware.com/cmake/cmake/-/issues/24922
file(CONFIGURE OUTPUT Directory.Build.props CONTENT [[
<Project>
<ItemDefinitionGroup>
<ClCompile>
<BuildStlModules>true</BuildStlModules>
</ClCompile>
</ItemDefinitionGroup>
</Project>
]] @ONLY)
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
cmake_path(CONVERT $ENV{VCTOOLSINSTALLDIR}/modules TO_CMAKE_PATH_LIST modules NORMALIZE)
target_sources(${PROJECT_NAME} PUBLIC FILE_SET CXX_MODULES
BASE_DIRS ${modules}
FILES ${modules}/std.ixx
)
endif()
6 changes: 6 additions & 0 deletions import-std/Makefile.msvc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
hello.exe: main.cpp
cl /nologo /EHsc /std:c++latest "$(VCTOOLSINSTALLDIR)/modules/std.ixx" main.cpp /Fe:hello

clean:
-del *.ifc *.obj *.exe
-rm *.ifc *.obj *.exe
6 changes: 6 additions & 0 deletions import-std/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import std;

int main()
{
std::println("{}", "Hello, World!");
}

0 comments on commit 49640bb

Please sign in to comment.