Switch from make to cmake

This commit is contained in:
blankie 2023-01-22 21:28:14 +07:00
parent 7f47dfe1e5
commit 430ed098a6
Signed by: blankie
GPG Key ID: CC15FC822C7F61F5
6 changed files with 87 additions and 99 deletions

3
.gitignore vendored
View File

@ -1,4 +1,3 @@
*.o
*.obj
/build
logmeow
logmeow.exe

76
CMakeLists.txt Normal file
View File

@ -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})

View File

@ -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)

View File

@ -1,6 +1,11 @@
#include <imgui.h>
#include <imgui_stdlib.h>
// for Test user assert
#ifndef NDEBUG
#include "myimconfig.h"
#endif
#include "log.h"
#include "config.h"
#include "logcat_thread.h"

View File

@ -13,6 +13,7 @@
#include <SDL_opengl.h>
#endif
#include "log.h"
#include "fonts.h"
#include "config.h"
#include "event_loop.h"

View File

@ -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