lvandeve / lodepng

PNG encoder and decoder in C and C++.
zlib License
2.06k stars 421 forks source link

Add cmake support with cmake-config file #82

Open NeroBurner opened 5 years ago

NeroBurner commented 5 years ago

Add full cmake support. The project can either be used with add_subdirectory or be installed into the system (or some other directory) and be found with find_package(lodepng). In both cases the cmake target lodepng::lodepng is all that needs to be linked.

Having an install target also makes packaging easier.

note: I was only able to install SDL2 from my package manager, but benchmark, example_opengl and example_sdl use SDL (1)

If you have any questions about this commit I'd be happy to clear out any misunderstandings

cmake -S . -B _build -DCMAKE_INSTALL_PREFIX="${PWD}/_install" -DCMAKE_BUILD_TYPE=Release
-- The C compiler identification is GNU 7.3.0
-- The CXX compiler identification is GNU 7.3.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /home/neroburner/repos/external/lodepng/_build

$ cmake --build _build --target install
Scanning dependencies of target lodepng
[ 12%] Building CXX object CMakeFiles/lodepng.dir/lodepng.cpp.o
[ 25%] Linking CXX static library liblodepng.a
[ 25%] Built target lodepng
Scanning dependencies of target lodepng_util
[ 37%] Building CXX object CMakeFiles/lodepng_util.dir/lodepng_util.cpp.o
[ 50%] Linking CXX static library liblodepng_util.a
[ 50%] Built target lodepng_util
Scanning dependencies of target lodepng_unittest
[ 62%] Building CXX object CMakeFiles/lodepng_unittest.dir/lodepng_unittest.cpp.o
[ 75%] Linking CXX executable lodepng_unittest
[ 75%] Built target lodepng_unittest
Scanning dependencies of target pngdetail
[ 87%] Building CXX object CMakeFiles/pngdetail.dir/pngdetail.cpp.o
[100%] Linking CXX executable pngdetail
[100%] Built target pngdetail
Install the project...
-- Install configuration: "Release"
-- Installing: /home/neroburner/repos/external/lodepng/_install/lib/liblodepng.a
-- Installing: /home/neroburner/repos/external/lodepng/_install/lib/liblodepng_util.a
-- Installing: /home/neroburner/repos/external/lodepng/_install/bin/pngdetail
-- Installing: /home/neroburner/repos/external/lodepng/_install/include/lodepng.h
-- Installing: /home/neroburner/repos/external/lodepng/_install/include/lodepng_util.h
-- Installing: /home/neroburner/repos/external/lodepng/_install/lib/cmake/lodepng/lodepng-config.cmake
-- Installing: /home/neroburner/repos/external/lodepng/_install/lib/cmake/lodepng/lodepng-targets.cmake
-- Installing: /home/neroburner/repos/external/lodepng/_install/lib/cmake/lodepng/lodepng-targets-release.cmake
ekg commented 5 years ago

I just realized that there are many cmakeification PRs here. Is this project not active anymore?

NeroBurner commented 5 years ago

not dead, @lvandeve still commits, but I think he is not interested in cmake support

ekg commented 5 years ago

In the end, it's just a CMakeLists.txt. It's very helpful when integrating this into other projects.

NeroBurner commented 3 years ago

@aleksey-nikolaev could you review my attempt at adding CMake support for lodepng? Anything missing here?