Last active
February 22, 2021 21:34
-
-
Save shimarin/99b995cb5fc7970fd7243e5f451f81b4 to your computer and use it in GitHub Desktop.
VS Codeで、複数のC++ソースファイルが置いてあるフォルダで編集中ファイルの実行をできるようにするための tasks.jsonと外部 Makefile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
rwildcard=$(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2) $(filter $(subst *,%,$2),$d)) | |
OBJS=$(subst .cpp,.o,$(call rwildcard,,*.cpp)) | |
BINS=$(subst .cpp,,$(call rwildcard,,*.cpp)) | |
HEADERS=$(call rwildcard,,*.h) | |
CXXFLAGS ?= -std=c++2a | |
all: $(BINS) | |
libproj.a: $(OBJS) | |
ar r $@ $(OBJS) | |
%: %.cpp libproj.a | |
g++ $(CXXFLAGS) -o $@ -D__MAIN_MODULE__ $< -L . -lproj | |
%.o: %.cpp $(HEADERS) | |
g++ $(CXXFLAGS) -c $< -o $@ | |
clean: | |
rm -f $(BINS) $(OBJS) libproj.a |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"tasks": [ | |
{ | |
"type": "cppbuild", | |
"label": "C/C++: g++ アクティブなファイルのビルド", | |
"command": "make", | |
"args": [ | |
"CXXFLAGS=-std=c++2a -g", | |
"-j", "-f", "Makefile.vscode", | |
"${fileDirname}/${fileBasenameNoExtension}" | |
], | |
"options": { | |
"cwd": "${workspaceFolder}" | |
}, | |
"problemMatcher": [ | |
"$gcc" | |
], | |
"group": { | |
"kind": "build", | |
"isDefault": true | |
}, | |
"detail": "デバッガーによって生成されたタスクを外部Makefileを利用するよう改造したもの。" | |
} | |
], | |
"version": "2.0.0" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
編集中のソースファイルは -D__MAIN_MODULE__でコンパイルされるので、各ソースで下記のようにして条件付きで main関数が有効になるようにする。