Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Makefile: Clean up cmake invocations #568

Merged
merged 3 commits into from
Dec 17, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Makefile: Clean up cmake invocations
Use cmake command to build and install instead of invoking make. Also
use -G option consistently. This allows to use other generators like
Ninja:

    make GENERATOR=Ninja

Use cmake -B option instead of switching directories.
nwellnhof committed Dec 17, 2024
commit fcf85e775cedbbc1fb4a5365df2f9323f609e0a0
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -16,3 +16,6 @@ indent_size = 2
trim_trailing_whitespace = true
indent_style = tab
indent_size = 8

[Makefile.nmake]
end_of_line = crlf
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
* text=auto eol=lf
Makefile.nmake eol=crlf
73 changes: 37 additions & 36 deletions Makefile
Original file line number Diff line number Diff line change
@@ -30,57 +30,56 @@ all: cmake_build man/man3/cmark.3
$(CMARK): cmake_build

cmake_build: $(BUILDDIR)
@$(MAKE) -j2 -C $(BUILDDIR)
cmake --build $(BUILDDIR)
@echo "Binaries can be found in $(BUILDDIR)/src"

$(BUILDDIR):
@cmake --version > /dev/null || (echo "You need cmake to build this program: http://www.cmake.org/download/" && exit 1)
mkdir -p $(BUILDDIR); \
cd $(BUILDDIR); \
cmake .. \
-G "$(GENERATOR)" \
-DCMAKE_BUILD_TYPE=$(BUILD_TYPE) \
-DCMAKE_INSTALL_PREFIX=$(INSTALL_PREFIX) \
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
-DBUILD_SHARED_LIBS=YES
cmake \
-S . -B $(BUILDDIR) -G "$(GENERATOR)" \
-DCMAKE_BUILD_TYPE=$(BUILD_TYPE) \
-DCMAKE_INSTALL_PREFIX=$(INSTALL_PREFIX) \
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
-DBUILD_SHARED_LIBS=YES

install: $(BUILDDIR)
$(MAKE) -C $(BUILDDIR) install
cmake --install $(BUILDDIR)

uninstall: $(BUILDDIR)/install_manifest.txt
xargs rm < $<

debug:
mkdir -p $(BUILDDIR); \
cd $(BUILDDIR); \
cmake .. \
-DCMAKE_BUILD_TYPE=Debug \
-DBUILD_SHARED_LIBS=YES; \
$(MAKE)
cmake \
-S . -B $(BUILDDIR) -G "$(GENERATOR)" \
-DCMAKE_BUILD_TYPE=Debug \
-DBUILD_SHARED_LIBS=YES
cmake --build $(BUILDDIR)

ubsan:
mkdir -p $(BUILDDIR); \
cd $(BUILDDIR); \
cmake .. -DCMAKE_BUILD_TYPE=Ubsan; \
$(MAKE)
cmake \
-S . -B $(BUILDDIR) -G "$(GENERATOR)" \
-DCMAKE_BUILD_TYPE=Ubsan
cmake --build $(BUILDDIR)

asan:
mkdir -p $(BUILDDIR); \
cd $(BUILDDIR); \
cmake .. -DCMAKE_BUILD_TYPE=Asan; \
$(MAKE)
cmake \
-S . -B $(BUILDDIR) -G "$(GENERATOR)" \
-DCMAKE_BUILD_TYPE=Asan
cmake --build $(BUILDDIR)

prof:
mkdir -p $(BUILDDIR); \
cd $(BUILDDIR); \
cmake .. -DCMAKE_BUILD_TYPE=Profile; \
$(MAKE)
cmake \
-S . -B $(BUILDDIR) -G "$(GENERATOR)" \
-DCMAKE_BUILD_TYPE=Profile
cmake --build $(BUILDDIR)

afl:
@[ -n "$(AFL_PATH)" ] || { echo '$$AFL_PATH not set'; false; }
mkdir -p $(BUILDDIR)
cd $(BUILDDIR) && cmake .. -DBUILD_TESTING=NO -DCMAKE_C_COMPILER=$(AFL_PATH)/afl-clang
$(MAKE)
cmake \
-S . -B $(BUILDDIR) -G "$(GENERATOR)" \
-DBUILD_TESTING=NO \
-DCMAKE_C_COMPILER=$(AFL_PATH)/afl-clang
cmake --build $(BUILDDIR)
$(AFL_PATH)/afl-fuzz \
-i fuzz/afl_test_cases \
-o fuzz/afl_results \
@@ -90,7 +89,7 @@ afl:

libFuzzer:
cmake \
-S . -B $(BUILDDIR) \
-S . -B $(BUILDDIR) -G "$(GENERATOR)" \
-DCMAKE_C_COMPILER=clang \
-DCMAKE_CXX_COMPILER=clang++ \
-DCMAKE_BUILD_TYPE=Asan \
@@ -110,10 +109,12 @@ lint: $(BUILDDIR)
exit $$errs

mingw:
mkdir -p $(MINGW_BUILDDIR); \
cd $(MINGW_BUILDDIR); \
cmake .. -DCMAKE_TOOLCHAIN_FILE=../toolchain-mingw32.cmake -DCMAKE_INSTALL_PREFIX=$(MINGW_INSTALLDIR) ;\
$(MAKE) && $(MAKE) install
cmake \
-S . -B $(MINGW_BUILDDIR) -G "$(GENERATOR)" \
-DCMAKE_TOOLCHAIN_FILE=toolchain-mingw32.cmake \
-DCMAKE_INSTALL_PREFIX=$(MINGW_INSTALLDIR)
cmake --build $(MINGW_BUILDDIR)
cmake --install $(MINGW_BUILDDIR)

man/man3/cmark.3: src/cmark.h | $(CMARK)
python3 man/make_man_page.py $< > $@ \
62 changes: 29 additions & 33 deletions Makefile.nmake
Original file line number Diff line number Diff line change
@@ -1,33 +1,29 @@
SRCDIR=src
DATADIR=data
BUILDDIR=build
INSTALLDIR=windows
SPEC=test/spec.txt
PROG=$(BUILDDIR)\src\cmark.exe
GENERATOR=NMake Makefiles

all: $(BUILDDIR)/CMakeFiles
@cd $(BUILDDIR) && $(MAKE) /nologo && cd ..

$(BUILDDIR)/CMakeFiles:
@-mkdir $(BUILDDIR) 2> nul
cd $(BUILDDIR) && \
cmake \
-G "$(GENERATOR)" \
-D CMAKE_BUILD_TYPE=$(BUILD_TYPE) \
-D CMAKE_INSTALL_PREFIX=$(INSTALLDIR) \
.. && \
cd ..

install: all
@cd $(BUILDDIR) && $(MAKE) /nologo install && cd ..

clean:
-rmdir /s /q $(BUILDDIR) $(MINGW_INSTALLDIR) 2> nul

test: $(SPEC) all
@cd $(BUILDDIR) && $(MAKE) /nologo test ARGS="-V" && cd ..

distclean: clean
del /q src\scanners.c 2> nul
del /q spec.md spec.html 2> nul
SRCDIR=src
DATADIR=data
BUILDDIR=build
INSTALLDIR=windows
SPEC=test/spec.txt
PROG=$(BUILDDIR)\src\cmark.exe
GENERATOR=NMake Makefiles

all: $(BUILDDIR)/CMakeFiles
cmake --build $(BUILDDIR)

$(BUILDDIR)/CMakeFiles:
cmake \
-S . -B $(BUILDDIR) -G "$(GENERATOR)" \
-D CMAKE_BUILD_TYPE=$(BUILD_TYPE) \
-D CMAKE_INSTALL_PREFIX=$(INSTALLDIR)

install: all
cmake --install $(BUILDDIR)

clean:
-rmdir /s /q $(BUILDDIR) $(MINGW_INSTALLDIR) 2> nul

test: $(SPEC) all
ctest --test-dir $(BUILDDIR) --output-on-failure

distclean: clean
del /q src\scanners.c 2> nul
del /q spec.md spec.html 2> nul