From 5de624b759fbd0cc253145ceee46f094d7bea0d7 Mon Sep 17 00:00:00 2001 From: Blaxar Waldarax Date: Sun, 18 Dec 2022 15:54:25 +0100 Subject: [PATCH] Add CMake support to the project --- CMakeLists.txt | 14 ++++++++++++++ README.md | 27 +++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..03b1cb9 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,14 @@ +cmake_minimum_required(VERSION 3.0) +project(img2tim LANGUAGES CXX) + +find_library(freeimage_lib NAMES FreeImage freeimage) +find_path(freeimage_inc NAMES FreeImage.h freeimage.h) + +if(freeimage_lib STREQUAL "freeimage_lib-NOTFOUND" OR + freeimage_inc STREQUAL "freeimage_inc-NOTFOUND") + message(FATAL_ERROR "Could not find FreeImage library on your system") +endif() + +add_executable(img2tim tim.cpp main.cpp) +target_include_directories(img2tim PUBLIC "${freeimage_inc}" "${PROJECT_SOURCE_DIR}") +target_link_libraries(img2tim "${freeimage_lib}") diff --git a/README.md b/README.md index edf5ef9..15a3c62 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,33 @@ The latest precompiled Win32 binary of this program can be downloaded here: Previous versions: [img2tim_(v0.60).zip](http://lameguy64.github.io/img2tim/img2tim_(v0.60).zip) +## Building + +You can build the `img2tim` binary executable using either _Code Blocks_ or _CMake_ right away as long as you have the _FreeImage_ library installed on your system (and, of course, either _Code Blocks_ or _CMake_ as well). + +### Using Code Blocks + +Open the already-provided `img2tim.cbp` file in _CodeBlocks_, assuming that the editor is already properly configured on your side: you should be able to build everything from there. + +### Using CMake + +Open a bash terminal, navigate to the root of the project and run the following command: +`mkdir -p build && cd build && cmake -S ..` +This will create a `build/` folder, then _CMake_ will generate the build files in it. +You will be notified in case of failure if, for example, the _FreeImage_ library could not be found. + +Then, assuming the default _CMake_ generator was targeting _make_: just run `make` to build the program. +If it was targeting _ninja_ instead: run `ninja`. + +At the end of it: the `img2tim` executable (with `.exe` extension on Windows) will be ready in the `build/` folder. + +#### Custom CMake generator + +You can select which generator you prefer by using the `-G` option with `cmake`, you can even generate a whole _Code Blocks_ project file from it, for example: +`cmake -G "CodeBlocks - Unix Makefiles" -B build` will produce a `img2tim.cbp` file in `build/`, which you can open with _Code Blocks_ (and it will use `make` behind the curtains to build the project). + +To see the list of all available generators on your system: just run `cmake --help`. + ## Changelog **Version 0.75** * Fixed a bug where a false error message is thrown when converting 4-bit images with -bpp 4.