-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
162 lines (150 loc) · 5.49 KB
/
Copy pathCMakeLists.txt
File metadata and controls
162 lines (150 loc) · 5.49 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
# cmake -G Ninja -B build -DPTP_INCLUDE_EXAMPLES=ON -DPTP_INCLUDE_VCAM_TEST=ON -DPTP_INCLUDE_CLI=ON
cmake_minimum_required(VERSION 3.15)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
project(pict)
option(PTP_CANON_ADV "Include implementation for advanced Canon features" ON)
option(PTP_STUFF "Include extra functions for debugging/testing" ON)
option(PTP_DEFAULT_LOGGING "Include default log/panic/error implementation" ON)
option(PTP_INCLUDE_CLI "Include CLI program" OFF)
option(PTP_USE_LIBUSB "Use LibUSB backend on UNIX platforms" ON)
option(PTP_INCLUDE_EXAMPLES "Include examples" OFF)
option(PTP_INCLUDE_VCAM_TEST "Use vcam backend instead of libusb" OFF)
option(PTP_INCLUDE_BIND "Include optional bind.c" ON)
option(PTP_NO_USB "Compile src/no_usb.c in place of libusb/libwpd" OFF)
option(PTP_NO_TCP "Compile no_ip.c in place of TCP code" OFF)
#option(PTP_INCLUDE_WINDOWS_TEST "Pull in libwpd and test windows compilation" OFF)
set(PICT_CORE
src/operations.c
src/packet.c
src/enums.c
src/data.c
src/enum_dump.c
src/lib.c
src/canon.c
src/liveview.c
src/ml.c
src/conv.c
src/generic.c
src/transport.c
)
if(NOT PTP_NO_TCP)
list(APPEND PICT_CORE src/ip.c)
else()
list(APPEND PICT_CORE src/no_ip.c)
endif()
if(PTP_INCLUDE_BIND)
list(APPEND PICT_CORE src/bind.c)
endif()
if(PTP_CANON_ADV)
list(APPEND PICT_CORE src/canon_adv.c)
endif()
if(PTP_STUFF)
list(APPEND PICT_CORE src/stuff.c)
endif()
if(PTP_DEFAULT_LOGGING)
list(APPEND PICT_CORE src/log.c)
endif()
if(PTP_NO_USB)
set(PLATFORM_LIB_FILES src/no_usb.c)
endif()
if(PTP_INCLUDE_VCAM_TEST)
if(EXISTS "${CMAKE_SOURCE_DIR}/../vcam")
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../vcam ${CMAKE_CURRENT_BINARY_DIR}/vcam)
else()
include(FetchContent)
FetchContent_Declare(vcam GIT_REPOSITORY https://github.com/petabyt/vcam GIT_TAG master GIT_SHALLOW 1)
FetchContent_MakeAvailable(vcam)
endif()
find_package(PkgConfig REQUIRED)
pkg_check_modules(LIBUSB libusb-1.0)
add_library(include_libusb INTERFACE)
target_include_directories(include_libusb INTERFACE ${LIBUSB_INCLUDE_DIRS})
list(APPEND PICT_LIBS usb-vcam include_libusb)
list(APPEND PICT_CORE src/libusb.c)
elseif(UNIX AND PTP_USE_LIBUSB AND NOT PTP_NO_USB)
if(TARGET usb-1.0)
list(APPEND PICT_LIBS usb-1.0)
else()
find_package(PkgConfig)
if(PKG_CONFIG_FOUND)
pkg_check_modules(LIBUSB IMPORTED_TARGET GLOBAL libusb-1.0)
if(LIBUSB_FOUND)
list(APPEND PICT_LIBS PkgConfig::LIBUSB)
else()
message(FATAL_ERROR "install libusb")
endif()
else()
option(LIBUSB_BUILD_SHARED_LIBS "" OFF)
option(LIBUSB_INSTALL_TARGETS "" OFF)
include(FetchContent)
FetchContent_Declare(libusb GIT_REPOSITORY https://github.com/libusb/libusb-cmake.git GIT_TAG v1.0.28-0 GIT_SHALLOW 1)
FetchContent_MakeAvailable(libusb)
list(APPEND PICT_LIBS usb-1.0)
endif()
endif()
list(APPEND PICT_CORE src/libusb.c)
elseif(WIN32 AND NOT PTP_NO_USB)
list(APPEND PICT_CORE src/libwpd.c)
if(NOT TARGET wpd_static)
include(FetchContent)
FetchContent_Declare(libwpd GIT_REPOSITORY https://github.com/petabyt/libwpd.git GIT_TAG master GIT_SHALLOW 1)
FetchContent_MakeAvailable(libwpd)
endif()
set(PICT_LIBS wpd_static -lws2_32)
endif()
add_library(libpict STATIC ${PICT_CORE} ${PLATFORM_LIB_FILES})
target_compile_options(libpict
PRIVATE -Wall -Wshadow -Wcast-qual -Wpedantic -Werror=incompatible-pointer-types -Werror=incompatible-pointer-types -Werror=deprecated-declarations -Werror=narrowing -DVERBOSE
)
target_include_directories(libpict PUBLIC ${PROJECT_SOURCE_DIR}/src)
target_link_libraries(libpict PUBLIC ${PICT_LIBS})
set_target_properties(libpict PROPERTIES OUTPUT_NAME pict) # libpict.a
if(PTP_INCLUDE_VCAM_TEST)
add_executable(test test/test.c test/data.c)
target_link_libraries(test libpict usb-vcam)
endif()
if(PTP_INCLUDE_CLI)
find_package(PkgConfig REQUIRED)
pkg_check_modules(LIBPCAP REQUIRED IMPORTED_TARGET GLOBAL libpcap)
pkg_check_modules(LUA53 REQUIRED IMPORTED_TARGET GLOBAL lua5.3)
find_library(QUICKJS_LIB
NAMES quickjs
PATH_SUFFIXES quickjs
REQUIRED
)
add_executable(ptp
src/cli.c
src/dec.c
src/lua/lua.c
src/lua/lua-cjson/lua_cjson.c
src/lua/lua-cjson/strbuf.c
src/js/quickjs.c
)
target_include_directories(ptp PUBLIC ${PROJECT_SOURCE_DIR}/src ${PROJECT_SOURCE_DIR}/src/lua)
target_link_libraries(ptp libpict PkgConfig::LIBPCAP PkgConfig::LUA53 ${QUICKJS_LIB} m)
install(
TARGETS ptp
)
endif()
macro(add_example exe_name source)
add_executable(${exe_name} ${source})
target_include_directories(${exe_name} PUBLIC ${PROJECT_SOURCE_DIR}/src)
if(WIN32)
target_link_libraries(${exe_name} libpict -lpthread -lurlmon -luuid -lws2_32)
else()
target_link_libraries(${exe_name} libpict)
endif()
endmacro()
if(PTP_INCLUDE_EXAMPLES)
add_example(info examples/info.c)
add_example(optest examples/optest.c)
add_example(directprint examples/directprint.c)
add_example(eos examples/eos.c)
add_example(evtest examples/evtest.c)
add_example(live examples/live.c)
add_example(ml examples/ml.c)
add_example(pktest examples/pktest.c)
add_example(storage examples/storage.c)
add_example(usb examples/usb.c)
add_example(wifi examples/wifi.c)
endif()