Skip to content

Commit

Permalink
Merge branch 'master' into v3.19.1
Browse files Browse the repository at this point in the history
  • Loading branch information
danoli3 authored Jul 9, 2024
2 parents 6d0b653 + 2a77aa4 commit c66a788
Show file tree
Hide file tree
Showing 11 changed files with 607 additions and 20 deletions.
63 changes: 63 additions & 0 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: "CMake build"

on:
push:
pull_request:
workflow_dispatch:

defaults:
run:
shell: bash

jobs:
build:
name: ${{ matrix.toolchain }} (C++${{ matrix.cppstandard }})
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
toolchain:
- linux-gcc
- macos-clang
- windows-msvc
- windows-mingw
cppstandard:
- 17
- 20
configuration:
- Debug
include:
- toolchain: linux-gcc
os: ubuntu-latest
compiler: gcc
- toolchain: macos-clang
os: macos-latest
compiler: clang
- toolchain: windows-msvc
os: windows-latest
compiler: msvc
- toolchain: windows-mingw
os: windows-latest
compiler: mingw
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Configure (${{ matrix.configuration }})
run: |
if [ "${{ matrix.compiler }}" == "msvc" ]; then
cmake -S . -B build -DBUILD_TESTS=ON -DCMAKE_CXX_STANDARD=${{ matrix.cppstandard }}
elif [ "${{ matrix.compiler }}" == "mingw" ]; then
cmake -S . -B build -DCMAKE_BUILD_TYPE=${{ matrix.configuration }} -DBUILD_TESTS=ON -DCMAKE_CXX_STANDARD=${{ matrix.cppstandard }} -G "MinGW Makefiles"
else
cmake -S . -B build -DCMAKE_BUILD_TYPE=${{ matrix.configuration }} -DBUILD_TESTS=ON -DCMAKE_CXX_STANDARD=${{ matrix.cppstandard }}
fi
- name: Build with ${{ matrix.compiler }}
run: |
if [ "${{ matrix.compiler }}" == "msvc" ]; then
cmake --build build --config ${{ matrix.configuration }}
else
cmake --build build -- -j8
fi
- name: Test
run: |
ctest --test-dir build --build-config ${{ matrix.configuration }} --verbose
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,10 @@ cmake-build/
*.bak

*.o-i386

# CMake and CTest build files #
###############################

build*/
cmake-build-*/
Testing/
98 changes: 82 additions & 16 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
cmake_minimum_required(VERSION 3.0)
cmake_minimum_required(VERSION 3.16)
project(FreeImage VERSION 3.19.0 LANGUAGES C CXX)

project(FreeImage)
# Options for configuring the build
option(BUILD_SHARED_LIBS "Build shared libraries" OFF)
option(BUILD_JXR "Build JPEG-XR support" WIN32)
option(BUILD_TESTS "Build the test suite" OFF)

option(BUILD_SHARED_LIBS "Build FreeImage as a shared library" OFF)

Expand Down Expand Up @@ -188,9 +192,42 @@ include_directories(Source/LibTIFF4)
include_directories(Source/LibOpenJPEG)


# Define the FreeImage library
add_subdirectory(Source)

# Preprocessor definitions
target_compile_definitions(${PROJECT_NAME} PUBLIC
DISABLE_PERF_MEASUREMENT
OPJ_STATIC
NO_LCMS
NO_WINDOWS
)
if (NOT BUILD_SHARED_LIBS)
target_compile_definitions(${PROJECT_NAME} PUBLIC FREEIMAGE_LIB)
endif ()

# Set C++ standard
target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_11)
set_target_properties(${PROJECT_NAME} PROPERTIES CXX_EXTENSIONS OFF)

# Emscripten support
if(EMSCRIPTEN)
add_executable(FreeImage_wasm)
target_link_libraries(FreeImage_wasm PRIVATE ${PROJECT_NAME}::${PROJECT_NAME})
endif()

# Apple-specific settings
if (APPLE)
set_target_properties(${PROJECT_NAME} PROPERTIES XCODE_ATTRIBUTE_ONLY_ACTIVE_ARCH "NO")
if(BUILD_PLATFORM_APPLE_IOS)
set_target_properties(${PROJECT_NAME} PROPERTIES XCODE_ATTRIBUTE_GCC_THUMB_SUPPORT "NO")
endif()
endif()

add_definitions(-DOPJ_STATIC -DNO_WINDOWS -DNDEBUG -DNO_LCMS -D__ANSI__ -DDISABLE_PERF_MEASUREMENT -DFREEIMAGE_LIB -DNO_LCMS)
# Enable Multi-core compilation in MSVC
if (MSVC)
target_compile_options(${PROJECT_NAME} PRIVATE /MP)
endif()

add_library(FreeImage STATIC
${FreeImage_SOURCES}
Expand Down Expand Up @@ -222,18 +259,47 @@ endif()

if (APPLE)
set_target_properties(FreeImage PROPERTIES XCODE_ATTRIBUTE_ONLY_ACTIVE_ARCH "NO")
# Append -d to debug build so we can have both debug and release builds in the same directory
set_target_properties(${PROJECT_NAME} PROPERTIES DEBUG_POSTFIX -d)

# Test suite
if (BUILD_TESTS)
include(CTest)
enable_testing()
add_subdirectory(TestAPI)
endif ()

# Install the library
install(TARGETS ${PROJECT_NAME}
EXPORT ${PROJECT_NAME}Targets
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
INCLUDES DESTINATION include
)
install(FILES Source/FreeImage.h DESTINATION include)

if(BUILD_PLATFORM_APPLE_IOS)
set_target_properties(FreeImage PROPERTIES XCODE_ATTRIBUTE_GCC_THUMB_SUPPORT "NO")
endif()
endif()

set(FreeImage_INCLUDE_DIR "${FreeImage_SOURCE_DIR}/Source" CACHE PATH "" FORCE)
set(FreeImage_LIBRARY_DBG FreeImage CACHE STRING "" FORCE)
set(FreeImage_LIBRARY_REL FreeImage CACHE STRING "" FORCE)
mark_as_advanced(FreeImage_INCLUDE_DIR FreeImage_LIBRARY_DBG FreeImage_LIBRARY_REL)
# Install the CMake Targets
install(EXPORT ${PROJECT_NAME}Targets
FILE ${PROJECT_NAME}Targets.cmake
NAMESPACE ${PROJECT_NAME}::
DESTINATION lib/cmake/${PROJECT_NAME}
)

INSTALL (
DIRECTORY ${CMAKE_SOURCE_DIR}/Source/
DESTINATION include
FILES_MATCHING PATTERN "*.h*")
# Install the CMake config
include(CMakePackageConfigHelpers)
configure_package_config_file(
${PROJECT_SOURCE_DIR}/cmake/${PROJECT_NAME}Config.cmake.in
${PROJECT_NAME}Config.cmake
INSTALL_DESTINATION lib/cmake/${PROJECT_NAME}
)
write_basic_package_version_file(
${PROJECT_NAME}ConfigVersion.cmake
VERSION ${PACKAGE_VERSION}
COMPATIBILITY SameMajorVersion
)
install(FILES
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
DESTINATION lib/cmake/${PROJECT_NAME}
)
60 changes: 59 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,65 @@ What is FreeImage ?
FreeImage is an Open Source library project for developers who would like to support popular graphics image formats like PNG, BMP, JPEG, TIFF and others as needed by today's multimedia applications.
FreeImage is easy to use, fast, multithreading safe, and cross-platform (works with Windows, Linux and Mac OS X).

Thanks to it's ANSI C interface, FreeImage is usable in many languages including C, C++, VB, C#, Delphi, Java and also in common scripting languages such as Perl, Python, PHP, TCL, Lua or Ruby.
### This GitHub Fork/Patch of FreeImage
- Numerous Sub-Dependancy patches (Security/Bugs/Latest)
- With patches applied from nVidia Devs and OpenSource additions
- CMake Build ability allowing compiling easily for all targets and platforms

Thanks to it's ANSI C interface, FreeImage is usable in many languages including C, C++, VB, C#, Delphi, Java and also in common scripting languages such as Perl, Python, PHP, TCL, Lua or Ruby.
The library comes in two versions: a binary DLL distribution that can be linked against any WIN32/WIN64 C/C++ compiler and a source distribution.
Workspace files for Microsoft Visual Studio provided, as well as makefiles for Linux, Mac OS X and other systems.

## Original Source Code Upstream
https://sourceforge.net/projects/freeimage
Original library can be found : https://freeimage.sourceforge.io

## Status

[![CMake build](https://github.com/danoli3/FreeImage/actions/workflows/cmake.yml/badge.svg)](https://github.com/danoli3/FreeImage/actions/workflows/cmake.yml)

## Building this fork

By default, JPEG-XR support is only included on Windows, but not on other platforms.

### Simply build it

```bash
cmake . -B cmake-build
cmake --build cmake-build # On Linux, add -j$(nproc) for multicore build
```

### Build and install Debug and Release configuration

```bash
cmake . -B cmake-build-debug -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=install_dir
cmake --build cmake-build-debug --config Debug --target install # Linux: -j$(nproc)

cmake . -B cmake-build-release -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=install_dir
cmake --build cmake-build-release --config Release --target install # Linux: -j$(nproc)
```
Now `install_dir` contains the compiled binaries for debug and release, as well as the header file and the CMake Config files.

## Using compiled binaries

First, build and install it like explained above.

Then, in another project add the following CMake code:
```cmake
set(CMAKE_PREFIX_PATH <freeimage_install_location>)
find_package(FreeImage CONFIG REQUIRED)
...
target_link_libraries(<your_target> PRIVATE FreeImage::FreeImage)
```

For `find_package` to work, simply set `CMAKE_PREFIX_PATH` to the directory where the compiled binaries are installed (the `install_dir` folder from above).

## Running tests

```bash
cmake . -B cmake-build-debug -DCMAKE_BUILD_TYPE=Debug -DBUILD_TESTS=ON
cmake --build cmake-build-debug --config Debug # Linux: -j$(nproc)
ctest --test-dir cmake-build-debug -C Debug # Optionally --rerun-failed --output-on-failure
```

> This ctest command only works with CMake 3.20 or higher. For earlier versions, you must `cd` into `cmake-build-debug` and call ctest without `--test-dir cmake-build-debug`.
Loading

0 comments on commit c66a788

Please sign in to comment.