|
| 1 | +cmake_minimum_required(VERSION 3.16) |
| 2 | +project(pixelmatch-cpp17 LANGUAGES CXX) |
| 3 | + |
| 4 | +set(CMAKE_CXX_STANDARD 20) |
| 5 | +set(CMAKE_CXX_STANDARD_REQUIRED ON) |
| 6 | + |
| 7 | +option(PIXELMATCH_BUILD_TESTS "Enable building tests" OFF) |
| 8 | + |
| 9 | +# stb libraries for tests and image_utils. Not used in pixelmatch-cpp17 itself. |
| 10 | +add_library(stb_image STATIC third_party/stb/stb_image.cpp) |
| 11 | +target_include_directories(stb_image PUBLIC third_party) |
| 12 | +target_compile_options(stb_image PRIVATE -Wno-unused-function -Wno-self-assign) |
| 13 | + |
| 14 | +add_library(stb_image_write STATIC third_party/stb/stb_image_write.cpp) |
| 15 | +target_include_directories(stb_image_write PUBLIC third_party) |
| 16 | +target_compile_options(stb_image_write PRIVATE -Wno-unused-function -Wno-self-assign) |
| 17 | + |
| 18 | +# Main library |
| 19 | +add_library(pixelmatch-cpp17 src/pixelmatch/pixelmatch.cc) |
| 20 | +target_include_directories(pixelmatch-cpp17 PUBLIC src) |
| 21 | + |
| 22 | +# image_utils helper library (uses stb to load and save images) |
| 23 | +add_library(image_utils src/pixelmatch/image_utils.cc) |
| 24 | +target_include_directories(image_utils PUBLIC src) |
| 25 | +target_link_libraries(image_utils PUBLIC pixelmatch-cpp17 stb_image stb_image_write) |
| 26 | + |
| 27 | +if(PIXELMATCH_BUILD_TESTS) |
| 28 | +include(FetchContent) |
| 29 | +FetchContent_Declare( |
| 30 | + googletest |
| 31 | + URL https://github.com/google/googletest/archive/refs/tags/v1.14.0.zip |
| 32 | +) |
| 33 | +set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) |
| 34 | +FetchContent_MakeAvailable(googletest) |
| 35 | + |
| 36 | +enable_testing() |
| 37 | +add_library(test_base INTERFACE) |
| 38 | +target_link_libraries(test_base INTERFACE GTest::gtest_main GTest::gmock_main m) |
| 39 | + |
| 40 | +add_executable(pixelmatch_tests tests/pixelmatch_tests.cc) |
| 41 | +target_link_libraries(pixelmatch_tests PRIVATE test_base pixelmatch-cpp17 image_utils) |
| 42 | +add_test(NAME pixelmatch_tests COMMAND pixelmatch_tests) |
| 43 | +set_tests_properties(pixelmatch_tests PROPERTIES WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}) |
| 44 | + |
| 45 | +add_executable(image_utils_tests tests/image_utils_tests.cc) |
| 46 | +target_link_libraries(image_utils_tests PRIVATE test_base image_utils) |
| 47 | +add_test(NAME image_utils_tests COMMAND image_utils_tests) |
| 48 | +set_tests_properties(image_utils_tests PROPERTIES WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}) |
| 49 | + |
| 50 | +endif() # PIXELMATCH_BUILD_TESTS |
0 commit comments