aboutsummaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorspicyjpeg <88942473+spicyjpeg@users.noreply.github.com>2021-09-12 19:39:17 +0200
committerspicyjpeg <88942473+spicyjpeg@users.noreply.github.com>2021-09-12 19:39:17 +0200
commitcea06fba6de344333365d7ee623ad30d152636a6 (patch)
treef546036c96bb16d50c6879d09e3a597a2b42b6b1 /tools
parent375322773f1961fe69699ac5691775235b0b39c5 (diff)
downloadpsn00bsdk-cea06fba6de344333365d7ee623ad30d152636a6.tar.gz
Migrated tools to CMake
Diffstat (limited to 'tools')
-rw-r--r--tools/CMakeLists.txt76
-rw-r--r--tools/lzpack/lzp/makefile30
-rw-r--r--tools/lzpack/main.cpp4
-rw-r--r--tools/lzpack/makefile46
-rw-r--r--tools/makefile12
-rw-r--r--tools/smxlink/makefile45
-rw-r--r--tools/util/makefile20
7 files changed, 78 insertions, 155 deletions
diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt
new file mode 100644
index 0000000..dd90109
--- /dev/null
+++ b/tools/CMakeLists.txt
@@ -0,0 +1,76 @@
+# PSn00bSDK tools build script
+# (C) 2021 spicyjpeg - MPL licensed
+
+cmake_minimum_required(VERSION 3.21)
+
+project(
+ PSn00bSDK-tools
+ LANGUAGES C CXX
+ DESCRIPTION "PSn00bSDK command-line tools"
+ HOMEPAGE_URL "http://lameguy64.net/?page=psn00bsdk"
+)
+
+include(GNUInstallDirs)
+
+## External dependencies
+
+# Let CMake attempt to find tinyxml2 on its own first. This avoids invoking
+# pkg-config where it might not be installed, and allows usage of package
+# managers like vcpkg. The path to tinyxml2 can also be specified manually by
+# passing -Dtinyxml2_ROOT.
+find_package(tinyxml2 CONFIG)
+
+if(NOT tinyxml2_FOUND)
+ find_package(PkgConfig REQUIRED)
+ pkg_search_module(_tinyxml2 REQUIRED IMPORTED_TARGET tinyxml2)
+
+ add_library(tinyxml2::tinyxml2 ALIAS PkgConfig::_tinyxml2)
+endif()
+
+## Internal dependencies
+
+# Build liblzp using sources from the libpsn00b tree. Hacky but it works.
+set(LIBPSN00B_PATH ${PROJECT_SOURCE_DIR}/../libpsn00b)
+file(
+ GLOB _sources
+ ${LIBPSN00B_PATH}/lzp/*.c
+ #${LIBPSN00B_PATH}/lzp/*.cpp
+)
+
+add_library(lzp STATIC ${_sources})
+target_include_directories(
+ lzp PUBLIC
+ lzpack/lzp
+ ${LIBPSN00B_PATH}/include/lzp
+)
+
+## Executables
+
+# This is required in order to properly link against tinyxml2 under MSVC.
+set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
+set(CMAKE_C_STANDARD 11)
+set(CMAKE_CXX_STANDARD 11)
+
+add_executable(elf2x util/elf2x.c)
+add_executable(elf2cpe util/elf2cpe.c)
+add_executable(smxlink smxlink/main.cpp smxlink/timreader.cpp)
+add_executable(lzpack lzpack/main.cpp lzpack/filelist.cpp)
+target_link_libraries(smxlink tinyxml2::tinyxml2)
+target_link_libraries(lzpack tinyxml2::tinyxml2 lzp)
+
+## Installation
+
+# Install the executables alongside the tinyxml2 DLL (if any) and copy the
+# Blender SMX export plugin to the data directory (for manual installation).
+install(
+ TARGETS elf2x elf2cpe smxlink lzpack
+ RUNTIME_DEPENDENCIES
+ PRE_EXCLUDE_REGEXES ".*"
+ PRE_INCLUDE_REGEXES "tinyxml2"
+)
+install(
+ DIRECTORY plugin
+ DESTINATION ${CMAKE_INSTALL_DATADIR}/psn00bsdk
+)
+
+include(InstallRequiredSystemLibraries)
diff --git a/tools/lzpack/lzp/makefile b/tools/lzpack/lzp/makefile
deleted file mode 100644
index 83da67d..0000000
--- a/tools/lzpack/lzp/makefile
+++ /dev/null
@@ -1,30 +0,0 @@
-# This LZP library builds off the lzp sources in libpsn00b/lzp. The only
-# difference is this is built with compression enabled specified in the
-# lzconfig.h file and the library is built for the host platform.
-
-TARGET = liblzp.a
-
-CFILES = $(wildcard ../../../libpsn00b/lzp/*.c)
-OFILES = $(addprefix build/, $(notdir $(CFILES:.c=.o)))
-
-INCLUDE = -I../include -I.
-
-CFLAGS = -g -O2
-
-CC = $(PREFIX)gcc
-AR = $(PREFIX)ar
-RANLIB = $(PREFIX)ranlib
-
-all: $(TARGET)
-
-$(TARGET): $(OFILES)
- $(AR) cr $(TARGET) $(OFILES)
- $(RANLIB) $(TARGET)
-
-# Dunno if there's a better way to do this but it works at least
-build/%.o: ../../../libpsn00b/lzp/%.c
- @mkdir -p $(dir $@)
- $(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@
-
-clean:
- rm -Rf build $(TARGET) \ No newline at end of file
diff --git a/tools/lzpack/main.cpp b/tools/lzpack/main.cpp
index 801cdd1..e57117e 100644
--- a/tools/lzpack/main.cpp
+++ b/tools/lzpack/main.cpp
@@ -1,8 +1,8 @@
#include <stdio.h>
#include <tinyxml2.h>
-#include "lzp/lzconfig.h"
-#include "lzp/lzp.h"
+#include "lzconfig.h"
+#include "lzp.h"
#include "filelist.h"
diff --git a/tools/lzpack/makefile b/tools/lzpack/makefile
deleted file mode 100644
index e11f5c7..0000000
--- a/tools/lzpack/makefile
+++ /dev/null
@@ -1,46 +0,0 @@
-TARGET := lzpack
-
-CPPFILES = main.cpp filelist.cpp
-CFLAGS = -O2
-LDFLAGS = -s
-
-LIBS = -ltinyxml2 -llzp
-
-CC = gcc
-CXX = g++
-
-OFILES = $(addprefix build/,$(CPPFILES:.cpp=.o))
-
-ifeq "$(OS)" "Windows_NT"
-
-# Config for Windows
-INCLUDE = -I/c/tinyxml2
-LIBDIRS = -L/c/tinyxml2
-TARGET := $(TARGET).exe
-
-else
-
-# Config for anything else that isn't Linux
-
-endif
-
-INCLUDE += -I../../libpsn00b
-LIBDIRS += -Llzp
-
-build/%.o: %.cpp
- @mkdir -p $(dir $@)
- $(CXX) $(CFLAGS) $(INCLUDE) -c $< -o $@
-
-all: $(OFILES)
- $(MAKE) -C lzp
- $(CXX) $(CFLAGS) $(LDFLAGS) $(LIBDIRS) $(OFILES) $(LIBS) -o $(TARGET)
-
-install:
- mkdir -p ../bin
- cp $(TARGET) ../bin/$(TARGET)
-
-clean:
- $(MAKE) -C lzp clean
- rm -Rf build $(TARGET)
-
-cleanall: clean
diff --git a/tools/makefile b/tools/makefile
deleted file mode 100644
index aec452c..0000000
--- a/tools/makefile
+++ /dev/null
@@ -1,12 +0,0 @@
-TOPTARGETS = all install clean
-
-TOOLDIRS = lzpack smxlink util
-
-$(TOPTARGETS): $(TOOLDIRS)
-$(TOOLDIRS):
- $(MAKE) -C $@ $(MAKECMDGOALS)
-
-clean: $(LIBDIRS)
- rm -Rf bin
-
-.PHONY: $(TOPTARGETS) $(TOOLDIRS)
diff --git a/tools/smxlink/makefile b/tools/smxlink/makefile
deleted file mode 100644
index ff759b1..0000000
--- a/tools/smxlink/makefile
+++ /dev/null
@@ -1,45 +0,0 @@
-TARGET := smxlink
-
-CPPFILES = main.cpp timreader.cpp
-CFLAGS = -O2
-LDFLAGS = -s
-
-INCLUDE =
-LIBDIRS =
-LIBS = -ltinyxml2
-
-CC = gcc
-CXX = g++
-
-OFILES = $(addprefix build/,$(CPPFILES:.cpp=.o))
-
-ifeq "$(OS)" "Windows_NT"
-
-# Config for Windows (comment out if in msys2)
-INCLUDE = -I/c/tinyxml2
-LIBDIRS = -L/c/tinyxml2
-
-TARGET := $(TARGET).exe
-
-else
-
-# Config for anything else that isn't Windows
-EXE_SUFFIX =
-
-endif
-
-build/%.o: %.cpp
- @mkdir -p $(dir $@)
- $(CXX) $(CFLAGS) $(INCLUDE) -c $< -o $@
-
-all: $(OFILES)
- $(CXX) $(CFLAGS) $(LDFLAGS) $(LIBDIRS) $(OFILES) $(LIBS) -o $(TARGET)
-
-install:
- mkdir -p ../bin
- cp $(TARGET) ../bin/$(TARGET)
-
-clean:
- rm -Rf build $(TARGET)
-
-cleanall: clean
diff --git a/tools/util/makefile b/tools/util/makefile
deleted file mode 100644
index fe7aed5..0000000
--- a/tools/util/makefile
+++ /dev/null
@@ -1,20 +0,0 @@
-CFLAGS = -O2 -s
-
-CC = gcc
-
-ifeq "$(OS)" "Windows_NT"
-EXE_SUFFIX = .exe
-else
-EXE_SUFFIX =
-endif
-
-all:
- $(CC) $(CFLAGS) elf2x.c -o elf2x$(EXE_SUFFIX)
- $(CC) $(CFLAGS) elf2cpe.c -o elf2cpe$(EXE_SUFFIX)
-
-install:
- mkdir -p ../bin
- cp elf2x$(EXE_SUFFIX) ../bin/elf2x$(EXE_SUFFIX)
-
-clean:
- rm -f elf2x$(EXE_SUFFIX)