Last active
September 4, 2023 05:47
-
-
Save KRMisha/99099d3c38efb038ff3b39e3c1bd6880 to your computer and use it in GitHub Desktop.
How to integrate Conan into a Makefile (https://github.com/KRMisha/Makefile) for SFML
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
[requires] | |
sfml/2.6.0 | |
[generators] | |
MakeDeps |
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
#include <SFML/Graphics.hpp> | |
int main() | |
{ | |
sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!"); | |
sf::CircleShape shape(100.0f); | |
shape.setFillColor(sf::Color::Green); | |
while (window.isOpen()) | |
{ | |
sf::Event event; | |
while (window.pollEvent(event)) | |
{ | |
if (event.type == sf::Event::Closed) | |
{ | |
window.close(); | |
} | |
} | |
window.clear(); | |
window.draw(shape); | |
window.display(); | |
} | |
} |
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
diff --git a/Makefile b/Makefile | |
index 9d5d7dc..51a16ed 100644 | |
--- a/Makefile | |
+++ b/Makefile | |
@@ -12,16 +12,25 @@ ASSETS_DIR = assets | |
ASSETS_OS_DIR := $(ASSETS_DIR)_os | |
INSTALL_DIR := ~/Desktop/$(EXEC) | |
+# Conan | |
+CONAN_DEFINE_FLAG = -D | |
+CONAN_INCLUDE_DIR_FLAG = -I | |
+CONAN_LIB_DIR_FLAG = -L | |
+CONAN_BIN_DIR_FLAG = -L | |
+CONAN_LIB_FLAG = -l | |
+CONAN_SYSTEM_LIB_FLAG = -l | |
+include $(BUILD_DIR_ROOT)/conandeps.mk | |
+ | |
# Sources (searches recursively inside the source directory) | |
SRC_DIR = src | |
SRCS := $(sort $(shell find $(SRC_DIR) -name '*.cpp')) | |
# Includes | |
INCLUDE_DIR = include | |
-INCLUDES := -I$(INCLUDE_DIR) | |
+INCLUDES := -I$(INCLUDE_DIR) $(CONAN_INCLUDE_DIRS) | |
# C preprocessor settings | |
-CPPFLAGS = $(INCLUDES) -MMD -MP | |
+CPPFLAGS = $(INCLUDES) -MMD -MP $(CONAN_DEFINES) | |
# C++ compiler settings | |
CXX = g++ | |
@@ -29,10 +38,10 @@ CXXFLAGS = -std=c++20 | |
WARNINGS = -Wall -Wpedantic -Wextra | |
# Linker flags | |
-LDFLAGS = | |
+LDFLAGS = $(CONAN_LIB_DIRS) | |
# Libraries to link | |
-LDLIBS = | |
+LDLIBS = $(CONAN_LIBS_SFML_GRAPHICS) $(CONAN_LIBS_SFML_WINDOW) $(CONAN_LIBS_SFML_SYSTEM) $(CONAN_SYSTEM_LIBS) | |
# Target OS detection | |
ifeq ($(OS),Windows_NT) # OS is a preexisting environment variable on Windows | |
@@ -189,6 +198,11 @@ clean: | |
@$(RM) -r $(BUILD_DIR_ROOT) | |
@$(RM) -r $(BIN_DIR_ROOT) | |
+# Generate Conan dependencies | |
+$(BUILD_DIR_ROOT)/conandeps.mk: conanfile.txt | |
+ @echo "Generating: $@" | |
+ @conan install . --output-folder=build --build=missing | |
+ | |
.PHONY: compdb | |
compdb: $(BUILD_DIR_ROOT)/compile_commands.json |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment