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/CMakeLists.txt b/CMakeLists.txt index ff3e7c5..d8af02f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,5 @@ cmake_minimum_required(VERSION 3.16) project(Libcjpg VERSION 1.5.30 LANGUAGES C) -find_package(Gint 2.9.0 REQUIRED) set(SOURCES jcapimin.c @@ -50,27 +49,15 @@ set(SOURCES jutils.c jmemname.c ) -include_directories( - "${PROJECT_SOURCE_DIR}" - "${PROJECT_BINARY_DIR}/include" - "${FXSDK_INCLUDE}") -add_compile_options(-Os -lm -m4-nofpu -mb -std=c11 -ffreestanding -nostdlib -Wa,--dsp) + # Target name is "cJPG", output file is "libcJPG.a" (by default) add_library(cJPG STATIC ${SOURCES}) +target_compile_options(cJPG PRIVATE -Os -std=c11) # After building, install the target (that is, libcJPG.a) in the compiler install(TARGETS cJPG DESTINATION "${FXSDK_LIB}") -# Install jpeglib.h from the build dir -install(FILES "${PROJECT_SOURCE_DIR}/jpeglib.h" - DESTINATION "${FXSDK_INCLUDE}") -# Install jconfig.h from the build dir -install(FILES "${PROJECT_SOURCE_DIR}/jconfig.h" - DESTINATION "${FXSDK_INCLUDE}") -# Install jmorecfg.h from the build dir -install(FILES "${PROJECT_SOURCE_DIR}/jmorecfg.h" - DESTINATION "${FXSDK_INCLUDE}") -# Install jerror.h from the build dir -install(FILES "${PROJECT_SOURCE_DIR}/jerror.h" +# Install headers from the source dir +install(FILES jpeglib.h jconfig.h jmorecfg.h jerror.h DESTINATION "${FXSDK_INCLUDE}") # Install FindcPNG.cmake so that users can do find_package(LibcPNG) install(FILES cmake/FindcJPG.cmake diff --git a/cmake/FindcJPG.cmake b/cmake/FindcJPG.cmake index 2ab6af5..6f42594 100644 --- a/cmake/FindcJPG.cmake +++ b/cmake/FindcJPG.cmake @@ -1,49 +1,19 @@ -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=libcJPG.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 "libcPNG.a") - # Find the version.h header - execute_process( - COMMAND ${CMAKE_C_COMPILER} -print-file-name=include/jconfig.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(libcJPG - 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(LibcJPG_FOUND) - # This is an imported target, we don't build it, we just claim it's here - add_library(libcJPG::libcJPG UNKNOWN IMPORTED) - # Here we declare the compiler and linker flags that every user of LibExample - # needs to use. - set_target_properties(libcJPG::libcJPG 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 -lcJPG - # Dependencies (for order on the command-line) - IMPORTED_LINK_INTERFACE_LIBRARIES Gint::Gint) + +find_simple_library(libcJPG.a jpeglib.h _ + PATH_VAR CJPG_PATH + OTHER_MACROS JPEG_LIB_VERSION_MAJOR JPEG_LIB_VERSION_MINOR) + +set(JPEG_VERSION "${JPEG_LIB_VERSION_MAJOR}.${JPEG_LIB_VERSION_MINOR}") + +find_package_handle_standard_args(cJPG + REQUIRED_VARS CJPG_PATH + VERSION_VAR JPEG_VERSION) + +if(cJPG_FOUND) + add_library(cJPG::cJPG UNKNOWN IMPORTED) + set_target_properties(cJPG::cJPG PROPERTIES + IMPORTED_LOCATION "${CJPG_PATH}" + INTERFACE_LINK_OPTIONS "-lm;-lcJPG") endif() diff --git a/giteapc.make b/giteapc.make index 453f68d..86d040e 100644 --- a/giteapc.make +++ b/giteapc.make @@ -4,23 +4,17 @@ configure: @ fxsdk build-fx -c - @ fxsdk build-cg -c build: @ fxsdk build-fx - @ fxsdk build-cg install: @ fxsdk build-fx install - @ fxsdk build-cg install uninstall: @ if [ -e build-fx/install_manifest.txt ]; then \ xargs rm -f < build-fx/install_manifest.txt; \ fi - @ if [ -e build-cg/install_manifest.txt ]; then \ - xargs rm -f < build-cg/install_manifest.txt; \ - fi .PHONY: configure build install uninstall