Skip to content

Instantly share code, notes, and snippets.

@ksyx
Last active April 20, 2021 12:41
Show Gist options
  • Save ksyx/a382118c0ae12ef513af294aba2a7219 to your computer and use it in GitHub Desktop.
Save ksyx/a382118c0ae12ef513af294aba2a7219 to your computer and use it in GitHub Desktop.
CMakeify CImg

This gist packs the header-only CImg library into CMake package to enable reusing code. To use it, follow the instructions below.

  • Clone the CImg library and change the command line path into this directory.
  • Run mkdir include && mv CImg.h include/ && mv plugins/ include/. This small change helps better managing the header files.
  • Put the following two CMake-related files in the CImg project directory.
  • Run mkdir build && cd build
  • Run cmake .. -G "MinGW Makefiles". You may change the generator as you want.
  • Run cmake install .

Nice! You can now see CImgConfig.cmake and CImgConfigVersion.cmake under the build directory. Then just add it into the PATH system variable and use FIND_PACKAGE (CImg REQUIRED CONFIG) and add ${CIMG_INCLUDE_DIR} into include paths. Enjoy!

set(CImg_VERSION 0.0.0)
@PACKAGE_INIT@
set_and_check(CIMG_INCLUDE_DIR "@PACKAGE_INCLUDE_INSTALL_DIR@")
check_required_components(CImg)
cmake_minimum_required(VERSION 3.16)
project(cimg)
set(INCLUDE_INSTALL_DIR include/)
set(LIB_INSTALL_DIR lib/)
set(SYSCONFIG_INSTALL_DIR "")
include(CMakePackageConfigHelpers)
configure_package_config_file(CImgConfig.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/CImgConfig.cmake
INSTALL_DESTINATION install/
PATH_VARS INCLUDE_INSTALL_DIR SYSCONFIG_INSTALL_DIR)
write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/CImgConfigVersion.cmake
VERSION 0.0.0
COMPATIBILITY SameMajorVersion )
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/CImgConfig.cmake
${CMAKE_CURRENT_BINARY_DIR}/CImgConfigVersion.cmake
DESTINATION ${LIB_INSTALL_DIR}/CImg/cmake )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment