diff --git a/examples/tools/README.md b/examples/tools/README.md index 8fee3df2..6a6bd68e 100644 --- a/examples/tools/README.md +++ b/examples/tools/README.md @@ -19,3 +19,8 @@ ### [tools.autotools](autotools) - Build a [Autotools project](autotools/autotoolstoolchain/string_formatter/) using Conan and [fmt](https://fmt.dev/). [Docs](https://docs.conan.io/2/examples/tools/autotools/autotools_toolchain/build_project_autotools_toolchain.rst) + + +### [tools.makefiles](makefiles) + +- Build a [Makefile project](makefile/makedeps/logger) using Conan and [make](https://www.gnu.org/software/make/). [Docs](https://docs.conan.io/2/examples/tools/makefile/makedeps/build_project_makefile.rst) diff --git a/examples/tools/makefile/makedeps/logger/Makefile b/examples/tools/makefile/makedeps/logger/Makefile new file mode 100644 index 00000000..e0cb3bb5 --- /dev/null +++ b/examples/tools/makefile/makedeps/logger/Makefile @@ -0,0 +1,17 @@ +ROOT_DIR:=$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST)))) +SRC_FOLDER = $(ROOT_DIR)/src +BUILD_FOLDER = $(ROOT_DIR)/build + +include $(BUILD_FOLDER)/conandeps.mk + +CXXFLAGS += $(CONAN_CXXFLAGS) -std=c++11 +CPPFLAGS += $(addprefix -I, $(CONAN_INCLUDE_DIRS)) +CPPFLAGS += $(addprefix -D, $(CONAN_DEFINES)) +LDFLAGS += $(addprefix -L, $(CONAN_LIB_DIRS)) +LDLIBS += $(addprefix -l, $(CONAN_LIBS)) +LDLIBS += $(addprefix -l, $(CONAN_SYSTEM_LIBS)) +EXELINKFLAGS += $(CONAN_EXELINKFLAGS) + + +all: + $(CXX) $(SRC_FOLDER)/main.cpp $(CPPFLAGS) $(CXXFLAGS) $(LDFLAGS) $(LDLIBS) $(EXELINKFLAGS) -o $(BUILD_FOLDER)/logger diff --git a/examples/tools/makefile/makedeps/logger/conanfile.txt b/examples/tools/makefile/makedeps/logger/conanfile.txt new file mode 100644 index 00000000..c0551c05 --- /dev/null +++ b/examples/tools/makefile/makedeps/logger/conanfile.txt @@ -0,0 +1,5 @@ +[requires] +spdlog/1.12.0 + +[generators] +MakeDeps diff --git a/examples/tools/makefile/makedeps/logger/run_example.sh b/examples/tools/makefile/makedeps/logger/run_example.sh new file mode 100755 index 00000000..4585465e --- /dev/null +++ b/examples/tools/makefile/makedeps/logger/run_example.sh @@ -0,0 +1,32 @@ +#!/bin/bash + +echo "- MakeDeps: The Makefile dependencies generator for Make -" + +set -ex + +# Remove cache +rm -rf build + +# Then generate conanbuild.sh +conan install -r conancenter . -of build --build=missing +source build/conanbuild.sh + +# Build the example +make + +source build/deactivate_conanbuild.sh + +# Make dynamic library available on PATH +source build/conanrun.sh + +output=$(build/logger) + +expected_str='To be a Cimmerian warrior, you must have both cunning and balance as well as speed and strength.' + +if [[ $expected_str -eq $output ]]; then + echo "ERROR: The String Formatter output does not match with the expected value: '$(expected_str)'" + exit 1 +fi + +echo 'MakeDeps example has been executed with SUCCESS!' +exit 0 diff --git a/examples/tools/makefile/makedeps/logger/src/main.cpp b/examples/tools/makefile/makedeps/logger/src/main.cpp new file mode 100644 index 00000000..3f1e46df --- /dev/null +++ b/examples/tools/makefile/makedeps/logger/src/main.cpp @@ -0,0 +1,8 @@ +#include +#include "spdlog/spdlog.h" + + +int main(void) { + spdlog::info("To be a Cimmerian warrior, you must have both cunning and balance as well as speed and strength."); + return EXIT_SUCCESS; +}