Last active
October 27, 2024 23:44
-
-
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 hidden or 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/.gitignore b/.gitignore | |
index 542fa54..2a5e664 100644 | |
--- a/.gitignore | |
+++ b/.gitignore | |
@@ -2,6 +2,9 @@ | |
.DS_Store | |
Thumbs.db | |
+# Python virtual environment for Conan | |
+.venv/ | |
+ | |
# Build output | |
/build/ | |
This file contains hidden or 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.1 | |
[generators] | |
MakeDeps |
This file contains hidden or 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 hidden or 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 ae5c329..18f412a 100644 | |
--- a/Makefile | |
+++ b/Makefile | |
@@ -25,11 +25,11 @@ TEST_SRCS := $(sort $(shell find $(TEST_DIR) -name '*.cpp' 2> /dev/null)) | |
# Includes | |
INCLUDE_DIR = | |
-INCLUDES = $(addprefix -I,$(SRC_DIR) $(INCLUDE_DIR)) | |
+INCLUDES = $(addprefix -I,$(SRC_DIR) $(INCLUDE_DIR)) $(CONAN_INCLUDE_DIRS) | |
TEST_INCLUDES = -I$(TEST_DIR) | |
# C preprocessor settings | |
-CPPFLAGS = $(INCLUDES) -MMD -MP | |
+CPPFLAGS = $(INCLUDES) -MMD -MP $(CONAN_DEFINES) | |
# C++ compiler settings | |
CXX = g++ | |
@@ -37,11 +37,11 @@ CXXFLAGS = -std=c++20 | |
WARNINGS = -Wall -Wpedantic -Wextra | |
# Linker flags | |
-LDFLAGS = | |
+LDFLAGS = $(CONAN_LIB_DIRS) | |
TEST_LDFLAGS = | |
# Libraries to link | |
-LDLIBS = | |
+LDLIBS = $(CONAN_LIBS_SFML_GRAPHICS) $(CONAN_LIBS_SFML_WINDOW) $(CONAN_LIBS_SFML_SYSTEM) $(CONAN_SYSTEM_LIBS) | |
TEST_LDLIBS = | |
# Target OS detection | |
@@ -103,9 +103,21 @@ else | |
CXXFLAGS += -O0 -g | |
endif | |
-# Object and bin directories | |
+# Object, bin, and Conan directories | |
OBJ_DIR := $(BUILD_DIR)/obj | |
BIN_DIR := $(BUILD_DIR)/bin | |
+CONAN_DIR := $(BUILD_DIR)/conan | |
+ | |
+# Conan | |
+ifneq ($(MAKECMDGOALS),clean) | |
+ CONAN_DEFINE_FLAG = -D | |
+ CONAN_INCLUDE_DIR_FLAG = -isystem | |
+ CONAN_LIB_DIR_FLAG = -L | |
+ CONAN_BIN_DIR_FLAG = -L | |
+ CONAN_LIB_FLAG = -l | |
+ CONAN_SYSTEM_LIB_FLAG = -l | |
+ include $(CONAN_DIR)/conandeps.mk | |
+endif | |
# Object files | |
MAIN_SRC = $(SRC_DIR)/main.cpp | |
@@ -134,6 +146,12 @@ FILES := $(shell find $(SRC_DIR) $(TEST_DIR) $(INCLUDE_DIR) -name '*.cpp' -o -na | |
.PHONY: all | |
all: $(BIN_DIR)/$(EXEC) $(if $(TEST_SRCS),$(BIN_DIR)/$(TEST_EXEC)) | |
+# Generate Conan dependencies | |
+$(CONAN_DIR)/conandeps.mk: conanfile.txt | |
+ @echo "Generating: $@" | |
+ @mkdir -p $(@D) | |
+ @conan install . --output-folder=$(CONAN_DIR) --build=missing | |
+ | |
# Build executable | |
$(BIN_DIR)/$(EXEC): $(MAIN_OBJ) $(SRC_OBJS_WITHOUT_MAIN) | |
@echo "Building executable: $@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment