Skip to content

Commit

Permalink
add Makefile.clang-cl
Browse files Browse the repository at this point in the history
clang-cl does not support `-x` currently.
llvm/llvm-project#88006

On Unix, install https://github.com/mstorsjo/msvc-wine to /opt/msvc,
and pass CXXFLAGS="-winsysroot /opt/msvc -fuse-ld=lld" to Makefile.
  • Loading branch information
huangqinjin committed May 5, 2024
1 parent 40a1098 commit d03268b
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 0 deletions.
18 changes: 18 additions & 0 deletions header-unit/Makefile.clang-cl
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
default: hello.exe

hello.pcm: hello.hpp
clang-cl /std:c++20 /clang:--precompile /clang:-fmodule-header hello.hpp $(CXXFLAGS)

iostream.pcm:
clang-cl /std:c++20 /clang:--precompile -x c++-system-header iostream $(CXXFLAGS) && \
echo /clang:-fmodule-file=iostream.pcm > modules.obj || \
echo "" > modules.obj

hello.exe: main.cpp hello.pcm iostream.pcm
##### Only -fmodule-file=.pcm works for header units.
##### With the existing implementation -fprebuilt-module-path cannot be used for header units (since they are nominally anonymous).
clang-cl /std:c++20 /clang:-fmodule-file=hello.pcm @modules.obj main.cpp /Fe:hello.exe $(CXXFLAGS)

clean:
-rm *.pcm *.obj *.exe
-del *.pcm *.obj *.exe
18 changes: 18 additions & 0 deletions module-impl/Makefile.clang-cl
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
default:
clang-cl /std:c++20 /clang:-fmodule-output /clang:-fprebuilt-module-path=. hello.cppm impl.cpp main.cpp /Fe:hello.exe $(CXXFLAGS)

hello.obj hello.pcm: hello.ixx
clang-cl /std:c++20 /clang:-fmodule-output /c hello.cppm $(CXXFLAGS)

impl.obj: impl.cpp hello.pcm
clang-cl /std:c++20 /clang:-fprebuilt-module-path=. /c impl.cpp $(CXXFLAGS)

main.obj: main.cpp hello.pcm
clang-cl /std:c++20 /clang:-fprebuilt-module-path=. /c main.cpp $(CXXFLAGS)

hello.exe: main.obj hello.obj impl.obj
clang-cl main.obj hello.obj impl.obj /Fe:hello.exe $(CXXFLAGS)

clean:
-rm *.pcm *.obj *.exe
-del *.pcm *.obj *.exe
1 change: 1 addition & 0 deletions module-impl/hello.cppm
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "hello.ixx"
24 changes: 24 additions & 0 deletions module-partition/Makefile.clang-cl
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#default:
# The default -fmodule-output of partitions are not same as used by -fprebuilt-module-path.
# clang-cl /std:c++20 /clang:-fmodule-output /clang:-fprebuilt-module-path=. internal.cppm interface.cppm hello.cppm main.cpp /Fe:hello.exe $(CXXFLAGS)

default: hello.exe

internal.obj hello-internal.pcm: internal.cppm
clang-cl /std:c++20 /c internal.cppm /clang:-fmodule-output=hello-internal.pcm $(CXXFLAGS)

interface.obj hello-interface.pcm: interface.cppm hello-internal.pcm
clang-cl /std:c++20 /clang:-fprebuilt-module-path=. /c interface.cppm /clang:-fmodule-output=hello-interface.pcm $(CXXFLAGS)

hello.obj hello.pcm: hello.ixx hello-interface.pcm
clang-cl /std:c++20 /clang:-fprebuilt-module-path=. /c hello.cppm /clang:-fmodule-output $(CXXFLAGS)

main.obj: main.cpp hello.pcm
clang-cl /std:c++20 /clang:-fprebuilt-module-path=. /c main.cpp $(CXXFLAGS)

hello.exe: main.obj hello.obj interface.obj internal.obj
clang-cl main.obj hello.obj interface.obj internal.obj /Fe:hello.exe $(CXXFLAGS)

clean:
-rm *.pcm *.obj *.exe
-del *.pcm *.obj *.exe
1 change: 1 addition & 0 deletions module-partition/hello.cppm
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "hello.ixx"
18 changes: 18 additions & 0 deletions named-module/Makefile.clang-cl
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# https://clang.llvm.org/docs/StandardCPlusPlusModules.html
# BMI: Built Module Interface

default:
clang-cl /std:c++20 /clang:-fmodule-output /clang:-fprebuilt-module-path=. hello.cppm main.cpp /Fe:hello.exe $(CXXFLAGS)

hello.obj hello.pcm: hello.cppm
clang-cl /std:c++20 /clang:-fmodule-output /c hello.cppm $(CXXFLAGS)

main.obj: main.cpp hello.pcm
clang-cl /std:c++20 /clang:-fprebuilt-module-path=. /c main.cpp $(CXXFLAGS)

hello.exe: main.obj hello.obj
clang-cl main.obj hello.obj /Fe:hello.exe $(CXXFLAGS)

clean:
-rm *.pcm *.obj *.exe
-del *.pcm *.obj *.exe
14 changes: 14 additions & 0 deletions shared-lib/Makefile.clang-cl
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
hello.exe: main.cpp hello.lib hello.pcm
clang-cl /std:c++20 /clang:-fprebuilt-module-path=. \
/Zc:dllexportInlines- \
main.cpp /Fe:hello.exe hello.lib $(CXXFLAGS) /Zi /link /PDB:hello.exe.pdb /INCREMENTAL:NO

hello.dll hello.lib hello.pcm: hello.ixx
clang-cl /std:c++20 /clang:-fprebuilt-module-path=. /clang:-fmodule-output /LD \
/Zc:dllexportInlines- \
hello.cppm impl.cpp $(CXXFLAGS) /Zi /link /PDB:hello.dll.pdb

clean:
-rm *.pcm *.obj *.exe *.exp *.lib *.dll *.pdb
-del *.pcm *.obj *.exe *.exp *.lib *.dll *.pdb

1 change: 1 addition & 0 deletions shared-lib/hello.cppm
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "hello.ixx"

0 comments on commit d03268b

Please sign in to comment.