From 8b43477e751f6cf219bd8c4bcf7de2b101e93bcf Mon Sep 17 00:00:00 2001 From: Lephenixnoir Date: Mon, 29 Aug 2022 20:54:14 +0200 Subject: [PATCH] build system update, with CMake find module --- .gitignore | 2 ++ Makefile.prizm | 43 ------------------------------ README.md | 23 +++++++++------- cmake/Findczlib.cmake | 62 +++++++++++-------------------------------- 4 files changed, 31 insertions(+), 99 deletions(-) create mode 100644 .gitignore delete mode 100644 Makefile.prizm diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9e933a9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/build-fx +/build-cg diff --git a/Makefile.prizm b/Makefile.prizm deleted file mode 100644 index 675a7c9..0000000 --- a/Makefile.prizm +++ /dev/null @@ -1,43 +0,0 @@ -# Makefile to build the SDL library - -INCLUDE = -I./include -I/home/sylvain/.local/share/giteapc/Lephenixnoir/sh-elf-gcc/lib/gcc/sh3eb-elf/11.1.0/include/openlibm/ -CFLAGS = -O2 $(INCLUDE) -lm -m4-nofpu -mb -ffreestanding -nostdlib -Wa,--dsp -AR = sh-elf-gcc-ar -RANLIB = sh-elf-gcc-ranlib -CC = sh-elf-gcc - -CONFIG_H = -TARGET = libczlib.a -SOURCES = \ - adler32.c \ - compress.c \ - crc32.c \ - deflate.c \ - gzclose.c \ - gzlib.c \ - gzread.c \ - gzwrite.c \ - infback.c \ - inffast.c \ - inflate.c \ - inftrees.c \ - trees.c \ - uncompr.c \ - zutil.c - - -OBJECTS = $(SOURCES:.c=.o) - -all: $(TARGET) - -$(TARGET): $(OBJECTS) - #cp $(CONFIG_H).default $(CONFIG_H) - $(AR) cr $@ $^ - $(RANLIB) $@ - #$(STRIP) --strip-unneeded $@ - -.c.o: - $(CC) $(INCLUDE) $(CFLAGS) -c $< -o $@ - -clean: - rm -f $(OBJECTS) $(TARGET) diff --git a/README.md b/README.md index ba26e61..a59aabf 100644 --- a/README.md +++ b/README.md @@ -2,18 +2,23 @@ Need to have a fully working gcc toolchain for SH3/SH4 architecture. -Compilation is done by using the adhoc Makefile : -`make -f Makefile.prizm` in the main directory +Compilation is done for all targets with a single: -It should produce the library libczlib.a +```bash +% fxsdk build-fx install +``` -The following steps are not automatically done, so please proceed with the following manipulations : -* copy the library `libczlib.a` into your SH3/SH4 compiler lib folder -* copy `zlib.h` and `zconf.h` files contained in the include folder into the include folder of the SH3/SH4 compiler +You can also use the `giteapc install Slyvtt/cZlib1_2_5` command to get an automatic install. -You can also use the `gitea install Slyvtt/cZlib1_2_5` command to get an automatic install +## Using in a program -when you compile a program for use with Zlib, do not forget to add a `-lczlib` option in your compilator command line. +With CMake: -and then a `#include ` in your C/C++ sources +```cmake +find_package(czlib 1.2.5 REQUIRED) +target_link_libraries( PRIVATE czlib::czlib) +``` +With make, link with `-lczlib`. + +In the C/C++ source, `#include `. diff --git a/cmake/Findczlib.cmake b/cmake/Findczlib.cmake index 0edc926..9294c85 100644 --- a/cmake/Findczlib.cmake +++ b/cmake/Findczlib.cmake @@ -1,49 +1,17 @@ -find_package(Gint 2.7 REQUIRED) -# Find libexample.a; if we had platform-specific versions we could look for -# libexample-${FXSDK_PLATFORM}.a instead. -execute_process( - COMMAND ${CMAKE_C_COMPILER} -print-file-name=libczlib.a - OUTPUT_VARIABLE EX_PATH OUTPUT_STRIP_TRAILING_WHITESPACE) -# EX_PATH is now the full path if libustl.a exists, "libustl.a" otherwise -if(NOT "${EX_PATH}" STREQUAL "libczlib.a") - # Find the version.h header - execute_process( - COMMAND ${CMAKE_C_COMPILER} -print-file-name=include/zconf.h - OUTPUT_VARIABLE EX_CONFIG OUTPUT_STRIP_TRAILING_WHITESPACE) - # Extract version information from the config.h header. This command prints - # the version on the line matching the regex and deletes every other line. - execute_process( - COMMAND sed -E "s/#define.*EX_VERSION\\s+\"(\\S+)\"$/\\1/p; d" ${EX_CONFIG} - OUTPUT_VARIABLE EX_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE) -endif() -# The commands above seem common for gint libraries, so the fxSDK provides a -# helper function to get that directly. We simply provide the archive name, -# header file name, macro name, and names for output variables. -# include(FindSimpleLibrary) -# find_simple_library(libexample.a include/example/config.h "EX_VERSION" -# PATH_VAR EX_PATH VERSION_VAR EX_VERSION) -# This CMake utility will handle the version comparisons and other checks. We -# just specify: -# -> Some variables that are defined only if the library is found (so if -# they're undefined, CMake will conclude libexample was not found) -# -> The version, so CMake can compare with the user's requested one +include(FindSimpleLibrary) include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(libczlib - REQUIRED_VARS EX_CONFIG EX_VERSION - VERSION_VAR EX_VERSION) -# We now have a LibExample_FOUND variable, let's create the target that users -# can link against with target_link_libraries() -if(Libczlib_FOUND) - # This is an imported target, we don't build it, we just claim it's here - add_library(libczlib::libczlib UNKNOWN IMPORTED) - # Here we declare the compiler and linker flags that every user of LibExample - # needs to use. - set_target_properties(libczlib::libczlib PROPERTIES - # If we specify where the library comes from, CMake will watch that file - # and relink any user application when the library is updated! - IMPORTED_LOCATION "${EX_PATH}" - # Linking options - INTERFACE_LINK_OPTIONS -lczlib - # Dependencies (for order on the command-line) - IMPORTED_LINK_INTERFACE_LIBRARIES Gint::Gint) + +find_simple_library(libczlib.a zlib.h "ZLIB_VERSION" + PATH_VAR CZLIB_PATH + VERSION_VAR CZLIB_VERSION) + +find_package_handle_standard_args(czlib + REQUIRED_VARS CZLIB_PATH CZLIB_VERSION + VERSION_VAR CZLIB_VERSION) + +if(czlib_FOUND) + add_library(czlib::czlib UNKNOWN IMPORTED) + set_target_properties(czlib::czlib PROPERTIES + IMPORTED_LOCATION "${CZLIB_PATH}" + INTERFACE_LINK_OPTIONS -lczlib) endif()