-
Notifications
You must be signed in to change notification settings - Fork 27
/
CMakeLists.txt
83 lines (71 loc) · 2.72 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
cmake_minimum_required(VERSION 3.15)
project(imageinfo)
set(CMAKE_CXX_STANDARD 11)
set(IMAGEINFO_IS_MASTER_PROJECT OFF)
if (${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR})
set(IMAGEINFO_IS_MASTER_PROJECT ON)
endif ()
option(IMAGEINFO_BUILD_TOOLS "Build tools" ${IMAGEINFO_IS_MASTER_PROJECT})
option(IMAGEINFO_BUILD_TESTS "Build tests" ${IMAGEINFO_IS_MASTER_PROJECT})
option(IMAGEINFO_BUILD_INSTALL "Build install" ${IMAGEINFO_IS_MASTER_PROJECT})
add_library(imageinfo INTERFACE)
add_library(imageinfo::imageinfo ALIAS imageinfo)
include(GNUInstallDirs)
target_include_directories(imageinfo INTERFACE
"$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>"
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>"
)
if (IMAGEINFO_BUILD_TOOLS)
add_executable(imageinfo_cli cli/main.cpp)
target_link_libraries(imageinfo_cli PRIVATE imageinfo)
set_target_properties(imageinfo_cli PROPERTIES OUTPUT_NAME "imageinfo")
endif ()
if (IMAGEINFO_BUILD_TESTS)
enable_testing()
add_executable(imageinfo_tests tests/tests.cpp)
target_link_libraries(imageinfo_tests PRIVATE imageinfo)
target_compile_definitions(imageinfo_tests PRIVATE
-DIMAGES_DIR="${CMAKE_CURRENT_SOURCE_DIR}/images/"
)
add_test(NAME imageinfo_tests COMMAND imageinfo_tests)
if (CMAKE_CONFIGURATION_TYPES)
add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND}
--force-new-ctest-process --output-on-failure
--build-config "$<CONFIGURATION>")
else ()
add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND}
--force-new-ctest-process --output-on-failure)
endif ()
endif ()
if (IMAGEINFO_BUILD_INSTALL)
install(TARGETS imageinfo EXPORT imageinfo)
install(
FILES "${CMAKE_CURRENT_SOURCE_DIR}/include/imageinfo.hpp"
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
)
install(
EXPORT imageinfo
FILE imageinfo-config.cmake
DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/imageinfo"
NAMESPACE imageinfo::
)
if (IMAGEINFO_BUILD_TOOLS)
install(TARGETS imageinfo_cli)
endif ()
endif ()
if (IMAGEINFO_IS_MASTER_PROJECT)
find_program(CLANG_FORMAT clang-format)
if (CLANG_FORMAT)
set(ALL_SOURCES include/imageinfo.hpp cli/main.cpp tests/tests.cpp)
add_custom_target(
format
COMMAND "${CLANG_FORMAT}" -i --verbose ${ALL_SOURCES}
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
)
add_custom_target(
check-format
COMMAND "${CLANG_FORMAT}" --dry-run --Werror --verbose ${ALL_SOURCES}
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
)
endif ()
endif ()