-
Notifications
You must be signed in to change notification settings - Fork 102
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
165 lines (141 loc) · 4.74 KB
/
CMakeLists.txt
File metadata and controls
165 lines (141 loc) · 4.74 KB
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# Clip Library
# Copyright (c) 2015-2026 David Capello
cmake_minimum_required(VERSION 3.15)
project(clip LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
if(CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
# Use libc++ explicitly so we can compile for
# CMAKE_OSX_DEPLOYMENT_TARGET=10.7 or 10.8
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
endif()
option(BUILD_SHARED_LIBS "Build clip as a shared library" off)
option(CLIP_ENABLE_IMAGE "Compile with support to copy/paste images" on)
if(WIN32)
option(CLIP_ENABLE_LIST_FORMATS "Compile with support to list clipboard formats" off)
endif()
option(CLIP_EXAMPLES "Compile clip examples" on)
option(CLIP_TESTS "Compile clip tests" on)
option(CLIP_INSTALL "Enable clip installation" on)
if(UNIX AND NOT APPLE)
option(CLIP_X11_WITH_PNG "Compile with libpng to support copy/paste image in png format" on)
endif()
add_library(clip clip.cpp)
target_include_directories(clip INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
target_compile_definitions(clip PRIVATE -DCLIP_BUILDING_LIB=1)
if(BUILD_SHARED_LIBS)
target_compile_definitions(clip PUBLIC -DCLIP_SHARED=1)
endif()
if(CLIP_ENABLE_IMAGE)
target_sources(clip PRIVATE image.cpp)
target_compile_definitions(clip PUBLIC -DCLIP_ENABLE_IMAGE=1)
endif()
if(WIN32 AND CLIP_ENABLE_LIST_FORMATS)
target_compile_definitions(clip PUBLIC -DCLIP_ENABLE_LIST_FORMATS=1)
endif()
if(WIN32)
option(CLIP_SUPPORT_WINXP "Enable Windows XP support" OFF)
target_sources(clip PRIVATE clip_win.cpp)
if(CLIP_ENABLE_IMAGE)
target_sources(clip PRIVATE clip_win_bmp.cpp clip_win_wic.cpp)
target_link_libraries(clip shlwapi)
endif()
if(MSVC)
target_compile_definitions(clip PRIVATE -D_SCL_SECURE_NO_WARNINGS)
endif()
if (CLIP_SUPPORT_WINXP)
target_compile_definitions(clip PRIVATE -DCLIP_SUPPORT_WINXP)
endif()
# MinGW requires the windowscodecs just because CLSIDs are defined
# in the windowscodecs.a file instead of the wincodec.h file (?!)
if(MINGW)
find_library(CLIP_WINDOWSCODECS_LIBRARY windowscodecs)
if(CLIP_WINDOWSCODECS_LIBRARY)
target_link_libraries(clip ${CLIP_WINDOWSCODECS_LIBRARY})
endif()
endif()
elseif(APPLE)
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
target_compile_options(clip PRIVATE -fobjc-arc)
endif()
find_library(COCOA_LIBRARY Cocoa REQUIRED)
target_sources(clip PRIVATE clip_osx.mm)
target_link_libraries(clip ${COCOA_LIBRARY})
elseif(UNIX AND NOT EMSCRIPTEN)
include(CheckIncludeFiles)
check_include_files(xcb/xcb.h HAVE_XCB_XLIB_H)
if(NOT HAVE_XCB_XLIB_H)
message(FATAL_ERROR "xcb/xcb.h not found, install libxcb-dev package")
endif()
target_compile_definitions(clip PRIVATE -DHAVE_XCB_XLIB_H)
target_link_libraries(clip xcb pthread)
if(CLIP_ENABLE_IMAGE AND CLIP_X11_WITH_PNG)
check_include_files(png.h HAVE_PNG_H)
if(CLIP_X11_PNG_LIBRARY)
set(PNG_LIBRARY ${CLIP_X11_PNG_LIBRARY})
else()
find_library(PNG_LIBRARY png)
endif()
if(HAVE_PNG_H AND PNG_LIBRARY)
target_compile_definitions(clip PRIVATE -DHAVE_PNG_H)
endif()
target_link_libraries(clip ${PNG_LIBRARY})
endif()
target_sources(clip PRIVATE clip_x11.cpp)
else()
target_sources(clip PRIVATE clip_none.cpp)
endif()
if(CLIP_EXAMPLES)
add_subdirectory(examples)
if(WIN32 AND BUILD_SHARED_LIBS)
add_custom_command(
TARGET clip
BYPRODUCTS ${CMAKE_CURRENT_BINARY_DIR}/examples/clip.dll
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:clip> ${CMAKE_CURRENT_BINARY_DIR}/examples
COMMENT "Copy DLL to examples directory")
endif()
endif()
if(CLIP_TESTS)
enable_testing()
add_subdirectory(tests)
if(WIN32 AND BUILD_SHARED_LIBS)
add_custom_command(
TARGET clip
BYPRODUCTS ${CMAKE_CURRENT_BINARY_DIR}/tests/clip.dll
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:clip> ${CMAKE_CURRENT_BINARY_DIR}/tests
COMMENT "Copy DLL to tests directory")
endif()
endif()
if(CLIP_INSTALL)
include(GNUInstallDirs)
install(
FILES clip.h
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
install(
TARGETS clip
EXPORT clip-targets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
install(
EXPORT clip-targets
NAMESPACE clip::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/clip
)
include(CMakePackageConfigHelpers)
configure_package_config_file(
clip-config.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/clip-config.cmake
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/clip
)
install(
FILES ${CMAKE_CURRENT_BINARY_DIR}/clip-config.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/clip
)
endif()