From 430ed098a6377c6b6ab98aa79dbe5f170d42fe4b Mon Sep 17 00:00:00 2001 From: blankie Date: Sun, 22 Jan 2023 21:28:14 +0700 Subject: [PATCH] Switch from make to cmake --- .gitignore | 3 +- CMakeLists.txt | 76 +++++++++++++++++++++++++++++++++++++++ Makefile | 96 -------------------------------------------------- event_loop.cpp | 5 +++ main.cpp | 1 + myimconfig.h | 5 ++- 6 files changed, 87 insertions(+), 99 deletions(-) create mode 100644 CMakeLists.txt delete mode 100644 Makefile diff --git a/.gitignore b/.gitignore index 668de5b..bcafe24 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,3 @@ -*.o -*.obj +/build logmeow logmeow.exe diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..ea786c8 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,76 @@ +cmake_minimum_required(VERSION 3.25) + +project(logmeow CXX) +set(CMAKE_C_COMPILER "clang") +set(CMAKE_CXX_COMPILER "clang++") + +set(LINUX_GL_LIBS -lGL) +## --------------------------------------------------------------------- +## OPENGL ES +## --------------------------------------------------------------------- + +## This assumes a GL ES library available in the system, e.g. libGLESv2.so +# set(FLAGS "${FLAGS} -DIMGUI_IMPL_OPENGL_ES2") +# set(LINUX_GL_LIBS -lGLESv2) +## If you're on a Raspberry Pi and want to use the legacy drivers, +## use the following instead: +# set(LINUX_GL_LIBS -L/opt/vc/lib -lbrcmGLESv2) + +## --------------------------------------------------------------------- +## GENERIC BUILD FLAGS +## --------------------------------------------------------------------- + +find_package(SDL2 REQUIRED) +find_package(Freetype 2 REQUIRED) +set(LIBS -lpcre2-8 -lpcre2-posix SDL2 imgui) +set(IMGUI_LIBS SDL2 Freetype::Freetype) + +set(INCLUDES imgui imgui/backends imgui/misc/cpp imgui/freetype /usr/include/SDL2) +set(SOURCES main.cpp event_loop.cpp logcat_thread.cpp logcat_entry.cpp log.cpp config.cpp misc.cpp pcre2_wrapper.cpp) +set(IMGUI_SOURCES imgui/imgui.cpp imgui/imgui_draw.cpp imgui/imgui_widgets.cpp imgui/imgui_tables.cpp + imgui/misc/cpp/imgui_stdlib.cpp imgui/misc/freetype/imgui_freetype.cpp + imgui/backends/imgui_impl_sdl.cpp imgui/backends/imgui_impl_opengl3.cpp) +if (CMAKE_BUILD_TYPE STREQUAL "Debug") + set(IMGUI_SOURCES ${IMGUI_SOURCES} imgui/imgui_demo.cpp) +endif() + +set(FLAGS "-fsanitize=undefined,thread") +# https://t.me/NightShadowsHangout/670691 +set(FLAGS "${FLAGS} -Werror -Wall -Wextra -Wshadow -Wpedantic -Wno-gnu-anonymous-struct -fno-rtti -fPIC -Wconversion -Wno-unused-parameter -Wimplicit-fallthrough") +# https://sourceforge.net/p/valgrind/mailman/valgrind-users/thread/Ygze8PzaQAYWlKDj%40wildebeest.org/ +set(FLAGS "${FLAGS} -gdwarf-4") + +## --------------------------------------------------------------------- +## BUILD FLAGS PER PLATFORM +## --------------------------------------------------------------------- + +if (LINUX) + find_package(Fontconfig) + set(LIBS ${LIBS} ${LINUX_GL_LIBS} -ldl) + set(IMGUI_LIBS ${IMGUI_LIBS} ${LINUX_GL_LIBS} -ldl) + if (Fontconfig_FOUND) + set(FLAGS "${FLAGS} -DUSE_FONTCONFIG") + set(LIBS ${LIBS} Fontconfig::Fontconfig) + set(SOURCES ${SOURCES} fonts.cpp) + endif() +elseif (APPLE) + set(LIBS ${LIBS} -framework OpenGL -framework Cocoa -framework IOKit -framework CoreVideo -L/usr/local/lib -L/opt/local/lib) + set(INCLUDES ${INCLUDES} /usr/local/include /opt/local/include) +elseif (WIN32) + set(LIBS ${LIBS} -lgdi32 -lopengl32 -limm32) +endif() + +add_link_options(-fuse-ld=lld) +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${FLAGS}") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${FLAGS}") +set(CMAKE_CXX_STANDARD 20) + +add_library(imgui STATIC ${IMGUI_SOURCES}) +target_include_directories(imgui PRIVATE ${INCLUDES}) +target_link_libraries(imgui PRIVATE ${IMGUI_LIBS}) +# dear imgui has some fucky wucky with -Wconversion, hence -Wno-conversion +target_compile_options(imgui PRIVATE -Wno-conversion -DIMGUI_USER_CONFIG="../myimconfig.h") + +add_executable(${PROJECT_NAME} ${SOURCES}) +target_include_directories(${PROJECT_NAME} PRIVATE ${INCLUDES}) +target_link_libraries(${PROJECT_NAME} PRIVATE ${LIBS}) diff --git a/Makefile b/Makefile deleted file mode 100644 index fdd1aea..0000000 --- a/Makefile +++ /dev/null @@ -1,96 +0,0 @@ -# -# Cross Platform Makefile -# Compatible with MSYS2/MINGW, Ubuntu 14.04.1 and Mac OS X -# -# You will need SDL2 (http://www.libsdl.org): -# Linux: -# apt-get install libsdl2-dev -# Mac OS X: -# brew install sdl2 -# MSYS2: -# pacman -S mingw-w64-i686-SDL2 -# - -#CXX = g++ -CXX = clang++ - -EXE = logmeow -IMGUI_DIR = imgui -SOURCES = $(wildcard *.cpp) -SOURCES += $(IMGUI_DIR)/imgui.cpp $(IMGUI_DIR)/imgui_demo.cpp $(IMGUI_DIR)/imgui_draw.cpp $(IMGUI_DIR)/imgui_tables.cpp $(IMGUI_DIR)/imgui_widgets.cpp -SOURCES += $(IMGUI_DIR)/misc/cpp/imgui_stdlib.cpp $(IMGUI_DIR)/misc/freetype/imgui_freetype.cpp -SOURCES += $(IMGUI_DIR)/backends/imgui_impl_sdl.cpp $(IMGUI_DIR)/backends/imgui_impl_opengl3.cpp -OBJS = $(addsuffix .o, $(basename $(notdir $(SOURCES)))) -UNAME_S := $(shell uname -s) -LINUX_GL_LIBS = -lGL - -CXXFLAGS += -fsanitize=undefined,thread -std=c++20 -I$(IMGUI_DIR) -I$(IMGUI_DIR)/misc/cpp -I$(IMGUI_DIR)/backends -D'IMGUI_USER_CONFIG="../myimconfig.h"' -# https://t.me/NightShadowsHangout/670691 -CXXFLAGS += -g -Werror -Wall -Wextra -Wshadow -Wpedantic -Wno-gnu-anonymous-struct -fno-rtti -fPIC -Wconversion -Wno-unused-parameter -Wimplicit-fallthrough -# https://sourceforge.net/p/valgrind/mailman/valgrind-users/thread/Ygze8PzaQAYWlKDj%40wildebeest.org/ -CXXFLAGS += -gdwarf-4 -LIBS = - -##--------------------------------------------------------------------- -## OPENGL ES -##--------------------------------------------------------------------- - -## This assumes a GL ES library available in the system, e.g. libGLESv2.so -# CXXFLAGS += -DIMGUI_IMPL_OPENGL_ES2 -# LINUX_GL_LIBS = -lGLESv2 -## If you're on a Raspberry Pi and want to use the legacy drivers, -## use the following instead: -# LINUX_GL_LIBS = -L/opt/vc/lib -lbrcmGLESv2 - -##--------------------------------------------------------------------- -## BUILD FLAGS PER PLATFORM -##--------------------------------------------------------------------- - -ifeq ($(UNAME_S), Linux) #LINUX - LIBS += $(LINUX_GL_LIBS) -ldl `sdl2-config --libs` `pkg-config --libs freetype2 fontconfig` -lpcre2-8 -lpcre2-posix - - CXXFLAGS += `sdl2-config --cflags` `pkg-config --cflags freetype2` -DUSE_FONTCONFIG - CFLAGS = $(CXXFLAGS) -endif - -ifeq ($(UNAME_S), Darwin) #APPLE - LIBS += -framework OpenGL -framework Cocoa -framework IOKit -framework CoreVideo `sdl2-config --libs` `pkg-config --libs freetype2` -lpcre2-8 -lpcre2-posix - LIBS += -L/usr/local/lib -L/opt/local/lib - - CXXFLAGS += `sdl2-config --cflags` `pkg-config --cflags freetype2` - CXXFLAGS += -I/usr/local/include -I/opt/local/include - CFLAGS = $(CXXFLAGS) -endif - -ifeq ($(OS), Windows_NT) - LIBS += -lgdi32 -lopengl32 -limm32 `pkg-config --static --libs sdl2 freetype2` -lpcre2-8 -lpcre2-posix - - CXXFLAGS += `pkg-config --cflags sdl2 freetype2` - CFLAGS = $(CXXFLAGS) -endif - -##--------------------------------------------------------------------- -## BUILD RULES -##--------------------------------------------------------------------- - -$(EXE): $(OBJS) - $(CXX) -o $@ $^ $(CXXFLAGS) -fuse-ld=lld $(LIBS) - -%.o:%.cpp - $(CXX) $(CXXFLAGS) -c -o $@ $< - -# dear imgui has some fucky wucky with -Wconversion, hence -Wno-conversion -%.o:$(IMGUI_DIR)/%.cpp - $(CXX) $(CXXFLAGS) -Wno-conversion -c -o $@ $< - -%.o:$(IMGUI_DIR)/misc/cpp/%.cpp - $(CXX) $(CXXFLAGS) -Wno-conversion -c -o $@ $< - -%.o:$(IMGUI_DIR)/misc/freetype/%.cpp - $(CXX) $(CXXFLAGS) -Wno-conversion -c -o $@ $< - -%.o:$(IMGUI_DIR)/backends/%.cpp - $(CXX) $(CXXFLAGS) -Wno-conversion -c -o $@ $< - -clean: - rm -f $(EXE) $(OBJS) diff --git a/event_loop.cpp b/event_loop.cpp index cffaaf7..5cba8a3 100644 --- a/event_loop.cpp +++ b/event_loop.cpp @@ -1,6 +1,11 @@ #include #include +// for Test user assert +#ifndef NDEBUG +#include "myimconfig.h" +#endif + #include "log.h" #include "config.h" #include "logcat_thread.h" diff --git a/main.cpp b/main.cpp index 55cd87c..b63e322 100644 --- a/main.cpp +++ b/main.cpp @@ -13,6 +13,7 @@ #include #endif +#include "log.h" #include "fonts.h" #include "config.h" #include "event_loop.h" diff --git a/myimconfig.h b/myimconfig.h index 59f1314..c74db57 100644 --- a/myimconfig.h +++ b/myimconfig.h @@ -7,5 +7,8 @@ #define IMGUI_ENABLE_FREETYPE #ifndef NDEBUG -#define IMGUI_DEBUG_PARANOID + #define IMGUI_DEBUG_PARANOID +#else + #define IMGUI_DISABLE_DEMO_WINDOWS + #define IMGUI_DISABLE_DEBUG_TOOLS #endif