Skip to content

Commit

Permalink
Support import std for CMake
Browse files Browse the repository at this point in the history
  • Loading branch information
huangqinjin committed Apr 17, 2024
1 parent c0af48c commit 2f606ab
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
3 changes: 3 additions & 0 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,9 @@ fi
MSVCVER=$(basename $(echo vc/tools/msvc/* | awk '{print $1}'))
echo Using MSVC version $MSVCVER

# Support `import std` for CMake.
ln_s VC/Tools/MSVC/$MSVCVER/modules modules

cat $ORIG/wrappers/msvcenv.sh \
| sed 's/MSVCVER=.*/MSVCVER='$MSVCVER/ \
| sed 's/SDKVER=.*/SDKVER='$SDKVER/ \
Expand Down
8 changes: 8 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ if (WIN32)
endif()
add_executable(hello ${hello_SOURCES})

if(TARGET __CMAKE::CXX23) # Since cmake 3.30
add_executable(hello-cxx23 hello.cpp)
target_compile_features(hello-cxx23 PUBLIC cxx_std_23)
set_target_properties(hello-cxx23 PROPERTIES
CXX_SCAN_FOR_MODULES ON
CXX_MODULE_STD ON
)
endif()

if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC" AND DEFINED MSVCDIR)
add_library(cxxmodules STATIC "${MSVCDIR}/modules/std.ixx")
Expand Down
6 changes: 6 additions & 0 deletions test/hello.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import std;

int main()
{
std::println("{}", "Hello world!");
}
4 changes: 1 addition & 3 deletions test/test-cmake.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@ EXEC "" ninja -v

# Rerun ninja to make sure that dependencies aren't broken.
EXEC ninja-rerun ninja -d explain -v
DIFF ninja-rerun.err - <<EOF
EOF
DIFF ninja-rerun.out - <<EOF
DIFF ninja-rerun.out - <<EOF || cat ninja-rerun.err
ninja: no work to do.
EOF

Expand Down

0 comments on commit 2f606ab

Please sign in to comment.