forked from simonowen/samdisk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
190 lines (160 loc) · 7.34 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
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
cmake_minimum_required(VERSION 3.3)
file(GLOB CXXSRC src/*.cpp src/types/*.cpp)
file(GLOB CSRC src/*.c)
add_executable(samdisk ${CXXSRC} ${CSRC})
install(TARGETS samdisk DESTINATION bin)
target_include_directories(samdisk PRIVATE include src extern)
target_compile_definitions(samdisk PRIVATE RESOURCE_DIR="${CMAKE_INSTALL_PREFIX}/share/samdisk/")
target_compile_definitions(samdisk PRIVATE _FILE_OFFSET_BITS=64)
include(CheckIncludeFiles)
include(CheckFunctionExists)
include(CheckSymbolExists)
include(CheckTypeSize)
include(CheckCXXCompilerFlag)
if (DEFINED CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE} CACHE STRING "Choose the type of build, options are: None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel.")
else ()
set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "Choose the type of build, options are: None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel.")
endif ()
message(STATUS "CMAKE_BUILD_TYPE is: ${CMAKE_BUILD_TYPE}")
if (CMAKE_BUILD_TYPE MATCHES Debug)
target_compile_definitions(samdisk _DEBUG=1)
endif ()
set_property(TARGET samdisk PROPERTY CXX_STANDARD 14)
CHECK_CXX_COMPILER_FLAG("-Weffc++" COMPILER_SUPPORTS_EFFCXX)
if (COMPILER_SUPPORTS_EFFCXX)
target_compile_options(samdisk PRIVATE $<$<COMPILE_LANGUAGE:CXX>:-Weffc++>)
endif ()
if (CMAKE_BUILD_TOOL MATCHES "make")
target_compile_options(samdisk PRIVATE -Wall -Wshadow -pedantic)
elseif (CMAKE_BUILD_TOOL MATCHES "(msdev|devenv|nmake)")
target_compile_options(samdisk PRIVATE /W4)
endif ()
CHECK_CXX_COMPILER_FLAG("-Wsuggest-override" COMPILER_SUPPORTS_WSUGGEST)
if (COMPILER_SUPPORTS_WSUGGEST)
target_compile_options(samdisk PRIVATE $<$<COMPILE_LANGUAGE:CXX>:-Wsuggest-override>)
endif ()
CHECK_CXX_COMPILER_FLAG("-stdlib=libc++" COMPILER_SUPPORTS_LIBCXX)
CHECK_CXX_COMPILER_FLAG("-stdlib=libstdc++" COMPILER_SUPPORTS_LIBSTDCXX)
if (COMPILER_SUPPORTS_LIBSTDCXX AND NOT APPLE)
target_compile_options(samdisk PRIVATE $<$<COMPILE_LANGUAGE:CXX>:-stdlib=libstdc++>)
endif ()
check_type_size(ssize_t SSIZE_T)
check_symbol_exists(O_BINARY fcntl.h HAVE_O_BINARY)
check_include_files(io.h HAVE_IO_H)
check_include_files(winsock2.h HAVE_WINSOCK2_H)
check_include_files(paths.h HAVE_PATHS_H)
check_include_files(unistd.h HAVE_UNISTD_H)
check_include_files(sys/time.h HAVE_SYS_TIME_H)
check_include_files(sys/ioctl.h HAVE_SYS_IOCTL_H)
check_include_files(sys/disk.h HAVE_SYS_DISK_H)
check_include_files(sys/socket.h HAVE_SYS_SOCKET_H)
check_include_files(arpa/inet.h HAVE_ARPA_INET_H)
check_include_files(netinet/in.h HAVE_NETINET_IN_H)
check_include_files(linux/hdreg.h HAVE_LINUX_HDREG_H)
check_include_files(linux/fs.h HAVE_LINUX_FS_H)
check_include_files(scsi/scsi.h HAVE_SCSI_SCSI_H)
check_include_files(scsi/sg.h HAVE_SCSI_SG_H)
check_include_files(DiskArbitration/DiskArbitration.h HAVE_DISKARBITRATION_DISKARBITRATION_H)
check_include_files(fdrawcmd.h HAVE_FDRAWCMD_H)
check_function_exists(snprintf HAVE_SNPRINTF)
check_function_exists(strcasecmp HAVE_STRCASECMP)
check_function_exists(gettimeofday HAVE_GETTIMEOFDAY)
check_function_exists(lseek64 HAVE_LSEEK64)
check_function_exists(_lseeki64 HAVE__LSEEKI64)
check_function_exists(_strcmpi HAVE__STRCMPI)
check_function_exists(_snprintf HAVE__SNPRINTF)
check_function_exists(sysconf HAVE_SYSCONF)
set(CMAKE_THREAD_PREFER_PTHREAD pthread)
find_package(Threads REQUIRED)
target_link_libraries(samdisk ${CMAKE_THREAD_LIBS_INIT})
find_package(ZLIB)
if (ZLIB_FOUND)
target_compile_definitions(samdisk PRIVATE HAVE_ZLIB=1)
target_include_directories(samdisk PRIVATE ${ZLIB_INCLUDE_DIR})
target_link_libraries(samdisk ${ZLIB_LIBRARY})
endif ()
find_package(BZip2)
if (BZIP2_FOUND)
target_compile_definitions(samdisk PRIVATE HAVE_BZIP2=1)
target_include_directories(samdisk PRIVATE ${BZIP2_INCLUDE_DIR})
target_link_libraries(samdisk ${BZIP2_LIBRARIES})
endif ()
find_package(LibLZMA)
if (LIBLZMA_FOUND)
target_compile_definitions(samdisk PRIVATE HAVE_LZMA=1)
target_include_directories(samdisk PRIVATE ${LIBLZMA_INCLUDE_DIRS})
target_link_libraries(samdisk ${LIBLZMA_LIBRARIES})
endif ()
find_library(WINUSB_LIBRARY NAMES winusb)
find_path(WINUSB_INCLUDE_DIR NAMES winusb.h)
if (WINUSB_LIBRARY AND WINUSB_INCLUDE_DIR)
message(STATUS "Found WinUSB: ${LIBUSB1_LIBRARY}")
target_compile_definitions(samdisk PRIVATE HAVE_WINUSB=1)
target_include_directories(samdisk PRIVATE ${WINUSB_INCLUDE_DIR})
target_link_libraries(samdisk ${WINUSB_LIBRARY})
endif ()
find_library(LIBUSB1_LIBRARY NAMES usb-1.0 ENV LD_LIBRARY_PATH)
find_path(LIBUSB1_INCLUDE_DIR NAMES libusb.h PATH_SUFFIXES libusb-1.0)
if (LIBUSB1_LIBRARY AND LIBUSB1_INCLUDE_DIR)
message(STATUS "Found libusb-1.0: ${LIBUSB1_LIBRARY}")
target_compile_definitions(samdisk PRIVATE HAVE_LIBUSB1=1)
target_include_directories(samdisk PRIVATE ${LIBUSB1_INCLUDE_DIR})
target_link_libraries(samdisk ${LIBUSB1_LIBRARY})
endif ()
find_library(FTD2XX_LIBRARY NAMES ftd2xx ENV LD_LIBRARY_PATH)
find_path(FTD2XX_INCLUDE_DIR ftd2xx.h)
if (FTD2XX_LIBRARY AND FTD2XX_INCLUDE_DIR)
message(STATUS "Found FTD2XX: ${FTD2XX_LIBRARY}")
target_compile_definitions(samdisk PRIVATE HAVE_FTD2XX=1)
target_include_directories(samdisk PRIVATE ${FTD2XX_INCLUDE_DIR})
target_link_libraries(samdisk ${FTD2XX_LIBRARY})
endif ()
find_library(FTDI_LIBRARY NAMES ftdi ENV LD_LIBRARY_PATH)
find_path(FTDI_INCLUDE_DIR ftdi.h)
if (FTDI_LIBRARY AND FTDI_INCLUDE_DIR)
message(STATUS "Found FTDI: ${FTDI_LIBRARY}")
target_compile_definitions(samdisk PRIVATE HAVE_FTDI=1)
target_include_directories(samdisk PRIVATE ${FTDI_INCLUDE_DIR})
target_link_libraries(samdisk ${FTDI_LIBRARY})
endif ()
find_library(CAPSIMAGE_LIBRARY NAMES CAPSimage capsimage CAPSimg PATHS extern ENV LD_LIBRARY_PATH)
find_path(CAPSIMAGE_INCLUDE_DIR caps/CapsLibAll.h PATHS extern)
if (CAPSIMAGE_LIBRARY AND CAPSIMAGE_INCLUDE_DIR)
message(STATUS "Found CAPSimage: ${CAPSIMAGE_LIBRARY}")
set(CMAKE_REQUIRED_LIBRARIES ${CAPSIMAGE_LIBRARY})
check_function_exists(CAPSSetRevolution HAVE_CAPSSETREVOLUTION)
if (CAPSIMAGE_INCLUDE_DIR AND HAVE_CAPSSETREVOLUTION)
target_compile_definitions(samdisk PRIVATE HAVE_CAPSIMAGE=1)
target_include_directories(samdisk PRIVATE ${CAPSIMAGE_INCLUDE_DIR})
if (APPLE)
set_target_properties(samdisk PROPERTIES LINK_FLAGS "-F /Library/Frameworks -weak_framework CAPSImage")
else ()
target_link_libraries(samdisk ${CAPSIMAGE_LIBRARY})
endif ()
else ()
message(STATUS "CAPSimage is too old, version 5.1 or later required!")
endif ()
elseif (CAPSIMAGE_LIBRARY)
message(WARNING "CAPSimage library found but header files are missing!\nPlease ensure caps/CapsLibAll.h is in your include path.")
else ()
message(STATUS "CAPSimage not found")
endif ()
find_library(WINUSB_LIBRARY NAMES winusb)
if (WINUSB_LIBRARY)
target_link_libraries(samdisk ${WINUSB_LIBRARY})
endif ()
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.in ${CMAKE_CURRENT_SOURCE_DIR}/include/config.h)
target_compile_definitions(samdisk PRIVATE HAVE_CONFIG_H=1)
if (WIN32)
target_compile_definitions(samdisk PRIVATE _WIN32=1)
target_link_libraries(samdisk setupapi ws2_32)
endif ()
if (APPLE)
set(CMAKE_OSX_DEPLOYMENT_TARGET 10.9)
set(CMAKE_OSX_ARCHITECTURES i386;x86_64)
find_library(DA_FRAMEWORK DiskArbitration)
find_library(CF_FRAMEWORK CoreFoundation)
find_library(IOKIT_FRAMEWORK IOKit)
target_link_libraries(samdisk ${DA_FRAMEWORK} ${CF_FRAMEWORK} ${IOKIT_FRAMEWORK})
endif ()