added more keys (@equipter)
[RRG-proxmark3.git] / client / CMakeLists.txt
blob5c826790dcd2cb3e17104d0610d885b3ba5a3af6
1 # Usage:
2 #  mkdir build
3 #  cd build
4 #  cmake ..     (see below for options)
5 #  make         (VERBOSE=1 if needed)
7 # MINGW:
8 #  On ProxSpace 3.4:
9 #    cmake -G"MSYS Makefiles" ..
10 #  On Proxspace 3.3 or less, you need to install cmake:
11 #    pacman -S mingw-w64-x86_64-cmake
12 #    /mingw64/bin/cmake -G"MSYS Makefiles" ..
14 # Android cross-compilation: (ANDROID_ABI=arm64-v8a for a 64b version)
15 # cmake \
16 #    -DCMAKE_TOOLCHAIN_FILE=<path-to-your-android-ndk>/build/cmake/android.toolchain.cmake \
17 #    -DANDROID_ABI=armeabi-v7a \
18 #    -DANDROID_NATIVE_API_LEVEL=android-19 \
19 #    -DSKIPBT=1 -DSKIPPYTHON=1 -DSKIPPTHREAD=1 ..
21 message(STATUS "CMake ${CMAKE_VERSION}")
22 cmake_minimum_required(VERSION 3.10)
23 project(proxmark3)
24 SET (PM3_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/..)
26 if(CMAKE_VERSION VERSION_LESS "3.7.0")
27     set(CMAKE_INCLUDE_CURRENT_DIR ON)
28 endif()
30 find_package(PkgConfig)
32 if (NOT SKIPQT EQUAL 1)
33     if(APPLE AND EXISTS /usr/local/opt/qt5)
34         # Homebrew installs Qt5 (up to at least 5.11.0) in
35         # /usr/local/opt/qt5. Ensure that it can be found by CMake
36         # since it is not in the default /usr/local prefix.
37         # Add it to PATHS so that it doesn't override the
38         # CMAKE_PREFIX_PATH environment variable.
39         # QT_FIND_PACKAGE_OPTIONS should be passed to find_package,
40         # e.g. find_package(Qt5Core ${QT_FIND_PACKAGE_OPTIONS})
41         list(APPEND QT_FIND_PACKAGE_OPTIONS PATHS /usr/local/opt/qt5)
42     endif(APPLE AND EXISTS /usr/local/opt/qt5)
43     if(APPLE AND EXISTS /opt/homebrew/opt/qt5)
44         # Homebrew on Apple Silicon installs Qt5 in
45         # /opt/homebrew/opt/qt5. Ensure that it can be found by CMake
46         # since it is not in the default /usr/local prefix.
47         # Add it to PATHS so that it doesn't override the
48         # CMAKE_PREFIX_PATH environment variable.
49         # QT_FIND_PACKAGE_OPTIONS should be passed to find_package,
50         # e.g. find_package(Qt5Core ${QT_FIND_PACKAGE_OPTIONS})
51         list(APPEND QT_FIND_PACKAGE_OPTIONS PATHS /opt/homebrew/opt/qt5)
52     endif(APPLE AND EXISTS /opt/homebrew/opt/qt5)
53     set(QT_PACKAGELIST
54         Qt5Core
55         Qt5Widgets
56         Qt5Gui
57     )
58     set(Qt5_FOUND ON)
59     foreach(_qt_package IN LISTS QT_PACKAGELIST)
60         find_package(${_qt_package} QUIET ${QT_FIND_PACKAGE_OPTIONS})
61         set(Qt5_LIBRARIES ${${_qt_package}_LIBRARIES} ${Qt5_LIBRARIES})
62         if(NOT ${_qt_package}_FOUND)
63             set(Qt5_FOUND OFF)
64         endif(NOT ${_qt_package}_FOUND)
65     endforeach()
66 endif (NOT SKIPQT EQUAL 1)
68 if (NOT SKIPBT EQUAL 1)
69     pkg_search_module(BLUEZ QUIET bluez)
70 endif (NOT SKIPBT EQUAL 1)
72 if (NOT SKIPPYTHON EQUAL 1)
73     pkg_search_module(PYTHON3 QUIET python3)
74     pkg_search_module(PYTHON3EMBED QUIET python3-embed)
75 endif (NOT SKIPPYTHON EQUAL 1)
77 # If cross-compiled, we need to init source and build.
78 if (CMAKE_TOOLCHAIN_FILE)
79     set(CFLAGS_EXTERNAL_LIB "CFLAGS=--target=${CMAKE_C_COMPILER_TARGET} -w")
80     set(EMBED_READLINE ON)
81     set(EMBED_BZIP2 ON)
82 endif (CMAKE_TOOLCHAIN_FILE)
84 if (EMBED_READLINE OR EMBED_BZIP2)
85     include(ExternalProject)
86 endif (EMBED_READLINE OR EMBED_BZIP2)
88 if (NOT SKIPREADLINE EQUAL 1)
89     if (APPLE)
90       find_path(READLINE_INCLUDE_DIRS readline/readline.h /usr/local/opt/readline/include /opt/local/include /opt/include /usr/local/include /usr/include /opt/homebrew/opt/readline/include NO_DEFAULT_PATH)
91       find_library(READLINE_LIBRARIES readline /usr/local/opt/readline/lib /opt/local/lib /opt/lib /usr/local/lib /usr/lib /opt/homebrew/opt/readline/lib NO_DEFAULT_PATH)
92     endif (APPLE)
93     if (EMBED_READLINE)
94         ExternalProject_Add(ncurses
95             URL                   http://ftp.gnu.org/pub/gnu/ncurses/ncurses-6.1.tar.gz
96             PREFIX                deps/ncurses
97             DOWNLOAD_DIR          ${CMAKE_CURRENT_SOURCE_DIR}/deps/ncurses
98             CONFIGURE_COMMAND     ./configure CC=${CMAKE_C_COMPILER} CXX=${CMAKE_CXX_COMPILER} LD=${CMAKE_C_COMPILER} AR=${CMAKE_AR} RANLIB=${CMAKE_RANLIB} ${CFLAGS_EXTERNAL_LIB} --host=arm --disable-database  --with-fallbacks=ansi-generic,ansi-mini,color_xterm,dtterm,dumb,Eterm,Eterm-256color,Eterm-88color,eterm-color,gnome,gnome-256color,guru,hurd,iTerm.app,konsole,konsole-16color,konsole-256color,konsole-base,konsole-linux,konsole-solaris,konsole-vt100,kterm,kterm-color,linux,linux-16color,linux-basic,mac,mlterm,mlterm-256color,mrxvt,mrxvt-256color,mterm,mterm-ansi,mvterm,nsterm,nsterm-16color,nsterm-256color,pty,putty,putty-256color,putty-vt100,rxvt,rxvt-16color,rxvt-256color,rxvt-88color,rxvt-basic,rxvt-color,screen,screen-16color,screen-256color,simpleterm,st-16color,st-256color,st52,st52-color,stv52,tt,tt52,unknown,vt100,vt102,vte,vte-256color,xterm,xterm-16color,xterm-256color,xterm-88color,xterm-basic,xterm-bold,xterm-color,xterm-utf8,xterm-vt220,xterm-vt52,xterm1,xtermc,xtermm   --enable-termcap --without-ada --without-debug --without-dlsym --without-gpm --without-develop --without-tests --without-cxx-binding --with-termlib
99             BUILD_IN_SOURCE       ON
100             BUILD_COMMAND         make libs
101             INSTALL_COMMAND       ""
102             LOG_DOWNLOAD          ON
103         )
104         ExternalProject_Add_StepTargets(ncurses configure build install)
106         ExternalProject_Add(readline
107             URL                   ftp://ftp.gnu.org/gnu/readline/readline-8.1.tar.gz
108             PREFIX                deps/readline
109             DOWNLOAD_DIR          ${CMAKE_CURRENT_SOURCE_DIR}/deps/readline
110             CONFIGURE_COMMAND     ./configure CC=${CMAKE_C_COMPILER} CXX=${CMAKE_CXX_COMPILER} LD=${CMAKE_C_COMPILER} AR=${CMAKE_AR} RANLIB=${CMAKE_RANLIB} ${CFLAGS_EXTERNAL_LIB} --host=arm --enable-static
111             BUILD_IN_SOURCE       ON
112             BUILD_COMMAND         make
113             INSTALL_COMMAND       ""
114             LOG_DOWNLOAD          ON
115         )
116         ExternalProject_Add_StepTargets(readline configure build install)
117         set(READLINE_INCLUDE_DIRS ${CMAKE_CURRENT_BINARY_DIR}/deps/readline/src/)
118         set(READLINE_LIBRARIES ${CMAKE_CURRENT_BINARY_DIR}/deps/readline/src/readline/libreadline.a ${CMAKE_CURRENT_BINARY_DIR}/deps/ncurses/src/ncurses/lib/libtinfo.a)
119     else (EMBED_READLINE)
120         find_path(READLINE_INCLUDE_DIRS readline/readline.h)
121         find_library(READLINE_LIBRARIES readline)
122     endif (EMBED_READLINE)
123     if (READLINE_INCLUDE_DIRS AND READLINE_LIBRARIES)
124         set(READLINE_FOUND ON)
125     endif (READLINE_INCLUDE_DIRS AND READLINE_LIBRARIES)
126 endif (NOT SKIPREADLINE EQUAL 1)
128 if (NOT SKIPJANSSONSYSTEM EQUAL 1)
129     pkg_check_modules(PC_JANSSON QUIET jansson)
130     find_path(JANSSON_INCLUDE_DIRS
131             NAMES jansson.h
132             HINTS ${PC_JANSSON_INCLUDEDIR} ${PC_JANSSON_INCLUDE_DIRS})
133     find_library(JANSSON_LIBRARIES
134             NAMES jansson libjansson
135             HINTS ${PC_JANSSON_LIBDIR} ${PC_JANSSON_LIBRARY_DIRS})
136     if (JANSSON_INCLUDE_DIRS AND JANSSON_LIBRARIES)
137         set(JANSSON_FOUND ON)
138     endif (JANSSON_INCLUDE_DIRS AND JANSSON_LIBRARIES)
139 endif (NOT SKIPJANSSONSYSTEM EQUAL 1)
141 if(EMBED_BZIP2)
142     set(BZIP2_BUILD_DIR ${CMAKE_CURRENT_BINARY_DIR}/deps/bzip2/src/bzip2)
143     ExternalProject_Add(bzip2
144         GIT_REPOSITORY        https://android.googlesource.com/platform/external/bzip2
145         GIT_TAG               platform-tools-30.0.2
146         PREFIX                deps/bzip2
147         SOURCE_DIR            ${CMAKE_CURRENT_SOURCE_DIR}/deps/bzip2
148         CONFIGURE_COMMAND     mkdir -p ${BZIP2_BUILD_DIR} && git archive --format tar HEAD | tar -C ${BZIP2_BUILD_DIR} -x
149         BUILD_IN_SOURCE       ON
150         BUILD_COMMAND         make -C ${BZIP2_BUILD_DIR} -j4 CC=${CMAKE_C_COMPILER} CXX=${CMAKE_CXX_COMPILER} LD=${CMAKE_C_COMPILER} AR=${CMAKE_AR} RANLIB=${CMAKE_RANLIB} ${CFLAGS_EXTERNAL_LIB} libbz2.a
151         INSTALL_COMMAND       ""
152         LOG_DOWNLOAD          ON
153     )
154     ExternalProject_Add_StepTargets(bzip2 configure build install)
155     set(BZIP2_INCLUDE_DIRS ${CMAKE_CURRENT_BINARY_DIR}/deps/bzip2/src/bzip2)
156     set(BZIP2_LIBRARIES ${CMAKE_CURRENT_BINARY_DIR}/deps/bzip2/src/bzip2/libbz2.a)
157     set(BZIP2_FOUND ON)
158 else(EMBED_BZIP2)
159     find_package (BZip2 REQUIRED)
160 endif(EMBED_BZIP2)
162 if (NOT SKIPWHEREAMISYSTEM EQUAL 1)
163     find_path(WHEREAMI_INCLUDE_DIRS whereami.h)
164     find_library(WHEREAMI_LIBRARIES whereami)
165     if (WHEREAMI_INCLUDE_DIRS AND WHEREAMI_LIBRARIES)
166         set(WHEREAMI_FOUND ON)
167     endif (WHEREAMI_INCLUDE_DIRS AND WHEREAMI_LIBRARIES)
168 endif (NOT SKIPWHEREAMISYSTEM EQUAL 1)
170 add_subdirectory(${PM3_ROOT}/client/deps deps)
172 set (TARGET_SOURCES
173         ${PM3_ROOT}/common/commonutil.c
174         ${PM3_ROOT}/common/util_posix.c
175         ${PM3_ROOT}/common/parity.c
176         ${PM3_ROOT}/common/bucketsort.c
177         ${PM3_ROOT}/common/crapto1/crapto1.c
178         ${PM3_ROOT}/common/crapto1/crypto1.c
179         ${PM3_ROOT}/common/crc.c
180         ${PM3_ROOT}/common/crc16.c
181         ${PM3_ROOT}/common/crc32.c
182         ${PM3_ROOT}/common/crc64.c
183         ${PM3_ROOT}/common/lfdemod.c
184         ${PM3_ROOT}/common/legic_prng.c
185         ${PM3_ROOT}/common/iso15693tools.c
186         ${PM3_ROOT}/common/cardhelper.c
187         ${PM3_ROOT}/common/generator.c
188         ${PM3_ROOT}/client/src/crypto/asn1dump.c
189         ${PM3_ROOT}/client/src/crypto/asn1utils.c
190         ${PM3_ROOT}/client/src/crypto/libpcrypto.c
191         ${PM3_ROOT}/client/src/emv/test/cda_test.c
192         ${PM3_ROOT}/client/src/emv/test/crypto_test.c
193         ${PM3_ROOT}/client/src/emv/test/cryptotest.c
194         ${PM3_ROOT}/client/src/emv/test/dda_test.c
195         ${PM3_ROOT}/client/src/emv/test/sda_test.c
196         ${PM3_ROOT}/client/src/emv/cmdemv.c
197         ${PM3_ROOT}/client/src/emv/crypto.c
198         ${PM3_ROOT}/client/src/emv/crypto_polarssl.c
199         ${PM3_ROOT}/client/src/emv/dol.c
200         ${PM3_ROOT}/client/src/emv/emv_pk.c
201         ${PM3_ROOT}/client/src/emv/emv_pki.c
202         ${PM3_ROOT}/client/src/emv/emv_pki_priv.c
203         ${PM3_ROOT}/client/src/emv/emv_roca.c
204         ${PM3_ROOT}/client/src/emv/emv_tags.c
205         ${PM3_ROOT}/client/src/emv/emvcore.c
206         ${PM3_ROOT}/client/src/emv/emvjson.c
207         ${PM3_ROOT}/client/src/emv/tlv.c
208         ${PM3_ROOT}/client/src/fido/additional_ca.c
209         ${PM3_ROOT}/client/src/fido/cbortools.c
210         ${PM3_ROOT}/client/src/fido/cose.c
211         ${PM3_ROOT}/client/src/fido/fidocore.c
212         ${PM3_ROOT}/client/src/iso7816/apduinfo.c
213         ${PM3_ROOT}/client/src/iso7816/iso7816core.c
214         ${PM3_ROOT}/client/src/cipurse/cipursecrypto.c
215         ${PM3_ROOT}/client/src/cipurse/cipursecore.c
216         ${PM3_ROOT}/client/src/loclass/cipher.c
217         ${PM3_ROOT}/client/src/loclass/cipherutils.c
218         ${PM3_ROOT}/client/src/loclass/elite_crack.c
219         ${PM3_ROOT}/client/src/loclass/hash1_brute.c
220         ${PM3_ROOT}/client/src/loclass/ikeys.c
221         ${PM3_ROOT}/client/src/mifare/mad.c
222         ${PM3_ROOT}/client/src/mifare/mfkey.c
223         ${PM3_ROOT}/client/src/mifare/mifare4.c
224         ${PM3_ROOT}/client/src/mifare/mifaredefault.c
225         ${PM3_ROOT}/client/src/mifare/mifarehost.c
226         ${PM3_ROOT}/client/src/nfc/ndef.c
227         ${PM3_ROOT}/client/src/mifare/desfire_crypto.c
228         ${PM3_ROOT}/client/src/uart/uart_posix.c
229         ${PM3_ROOT}/client/src/uart/uart_win32.c
230         ${PM3_ROOT}/client/src/ui/overlays.ui
231         ${PM3_ROOT}/client/src/aiddesfire.c
232         ${PM3_ROOT}/client/src/aidsearch.c
233         ${PM3_ROOT}/client/src/cmdanalyse.c
234         ${PM3_ROOT}/client/src/cmdcrc.c
235         ${PM3_ROOT}/client/src/cmddata.c
236         ${PM3_ROOT}/client/src/cmdflashmem.c
237         ${PM3_ROOT}/client/src/cmdflashmemspiffs.c
238         ${PM3_ROOT}/client/src/cmdhf.c
239         ${PM3_ROOT}/client/src/cmdhf14a.c
240         ${PM3_ROOT}/client/src/cmdhf14b.c
241         ${PM3_ROOT}/client/src/cmdhf15.c
242         ${PM3_ROOT}/client/src/cmdhfcryptorf.c
243         ${PM3_ROOT}/client/src/cmdhfemrtd.c
244         ${PM3_ROOT}/client/src/cmdhfepa.c
245         ${PM3_ROOT}/client/src/cmdhffelica.c
246         ${PM3_ROOT}/client/src/cmdhffido.c
247         ${PM3_ROOT}/client/src/cmdhfcipurse.c
248         ${PM3_ROOT}/client/src/cmdhficlass.c
249         ${PM3_ROOT}/client/src/cmdhfjooki.c
250         ${PM3_ROOT}/client/src/cmdhflegic.c
251         ${PM3_ROOT}/client/src/cmdhflist.c
252         ${PM3_ROOT}/client/src/cmdhflto.c
253         ${PM3_ROOT}/client/src/cmdhfmf.c
254         ${PM3_ROOT}/client/src/cmdhfmfdes.c
255         ${PM3_ROOT}/client/src/cmdhfmfhard.c
256         ${PM3_ROOT}/client/src/cmdhfmfp.c
257         ${PM3_ROOT}/client/src/cmdhfmfu.c
258         ${PM3_ROOT}/client/src/cmdhfseos.c
259         ${PM3_ROOT}/client/src/cmdhfst.c
260         ${PM3_ROOT}/client/src/cmdhfst25ta.c
261         ${PM3_ROOT}/client/src/cmdhfthinfilm.c
262         ${PM3_ROOT}/client/src/cmdhftopaz.c
263         ${PM3_ROOT}/client/src/cmdhfwaveshare.c
264         ${PM3_ROOT}/client/src/cmdhw.c
265         ${PM3_ROOT}/client/src/cmdlf.c
266         ${PM3_ROOT}/client/src/cmdlfawid.c
267         ${PM3_ROOT}/client/src/cmdlfcotag.c
268         ${PM3_ROOT}/client/src/cmdlfdestron.c
269         ${PM3_ROOT}/client/src/cmdlfem.c
270         ${PM3_ROOT}/client/src/cmdlfem410x.c
271         ${PM3_ROOT}/client/src/cmdlfem4x05.c
272         ${PM3_ROOT}/client/src/cmdlfem4x50.c
273         ${PM3_ROOT}/client/src/cmdlfem4x70.c
274         ${PM3_ROOT}/client/src/cmdlffdxb.c
275         ${PM3_ROOT}/client/src/cmdlfgallagher.c
276         ${PM3_ROOT}/client/src/cmdlfguard.c
277         ${PM3_ROOT}/client/src/cmdlfhid.c
278         ${PM3_ROOT}/client/src/cmdlfhitag.c
279         ${PM3_ROOT}/client/src/cmdlfidteck.c
280         ${PM3_ROOT}/client/src/cmdlfindala.c
281         ${PM3_ROOT}/client/src/cmdlfio.c
282         ${PM3_ROOT}/client/src/cmdlfjablotron.c
283         ${PM3_ROOT}/client/src/cmdlfkeri.c
284         ${PM3_ROOT}/client/src/cmdlfmotorola.c
285         ${PM3_ROOT}/client/src/cmdlfnedap.c
286         ${PM3_ROOT}/client/src/cmdlfnexwatch.c
287         ${PM3_ROOT}/client/src/cmdlfnoralsy.c
288         ${PM3_ROOT}/client/src/cmdlfpac.c
289         ${PM3_ROOT}/client/src/cmdlfparadox.c
290         ${PM3_ROOT}/client/src/cmdlfpcf7931.c
291         ${PM3_ROOT}/client/src/cmdlfpresco.c
292         ${PM3_ROOT}/client/src/cmdlfpyramid.c
293         ${PM3_ROOT}/client/src/cmdlfsecurakey.c
294         ${PM3_ROOT}/client/src/cmdlft55xx.c
295         ${PM3_ROOT}/client/src/cmdlfti.c
296         ${PM3_ROOT}/client/src/cmdlfviking.c
297         ${PM3_ROOT}/client/src/cmdlfvisa2000.c
298         ${PM3_ROOT}/client/src/cmdmain.c
299         ${PM3_ROOT}/client/src/cmdnfc.c
300         ${PM3_ROOT}/client/src/cmdparser.c
301         ${PM3_ROOT}/client/src/cmdscript.c
302         ${PM3_ROOT}/client/src/cmdsmartcard.c
303         ${PM3_ROOT}/client/src/cmdtrace.c
304         ${PM3_ROOT}/client/src/cmdusart.c
305         ${PM3_ROOT}/client/src/cmdwiegand.c
306         ${PM3_ROOT}/client/src/comms.c
307         ${PM3_ROOT}/client/src/fileutils.c
308         ${PM3_ROOT}/client/src/flash.c
309         ${PM3_ROOT}/client/src/graph.c
310         ${PM3_ROOT}/client/src/jansson_path.c
311         ${PM3_ROOT}/client/src/preferences.c
312         ${PM3_ROOT}/client/src/pm3.c
313         ${PM3_ROOT}/client/src/pm3_binlib.c
314         ${PM3_ROOT}/client/src/pm3_bitlib.c
315         ${PM3_ROOT}/client/src/prng.c
316         ${PM3_ROOT}/client/src/scandir.c
317         ${PM3_ROOT}/client/src/scripting.c
318         ${PM3_ROOT}/client/src/tea.c
319         ${PM3_ROOT}/client/src/ui.c
320         ${PM3_ROOT}/client/src/util.c
321         ${PM3_ROOT}/client/src/wiegand_formats.c
322         ${PM3_ROOT}/client/src/wiegand_formatutils.c
323         ${CMAKE_BINARY_DIR}/version_pm3.c
324         )
326 add_custom_command(
327     OUTPUT  ${CMAKE_BINARY_DIR}/version_pm3.c
328     COMMAND sh ${PM3_ROOT}/tools/mkversion.sh > ${CMAKE_BINARY_DIR}/version_pm3.c || perl ${PM3_ROOT}/tools/mkversion.pl > ${CMAKE_BINARY_DIR}/version_pm3.c || ${CMAKE_COMMAND} -E copy ${PM3_ROOT}/common/default_version_pm3.c ${CMAKE_BINARY_DIR}/version_pm3.c
329     DEPENDS ${PM3_ROOT}/common/default_version_pm3.c
332 set(ADDITIONAL_SRC "")
333 set(ADDITIONAL_LNK "")
334 set(ADDITIONAL_DIRS "")
335 set(ADDITIONAL_LNKDIRS "")
336 set(X86_CPUS x86 x86_64 i686)
338 message(STATUS "CMAKE_SYSTEM_PROCESSOR := ${CMAKE_SYSTEM_PROCESSOR}")
340 if (APPLE)
341     message(STATUS "Apple device detected.")
342     set(ADDITIONAL_SRC ${PM3_ROOT}/client/src/util_darwin.h  ${PM3_ROOT}/client/src/util_darwin.m ${ADDITIONAL_SRC})
343     set(ADDITIONAL_LNK "-framework Foundation" "-framework AppKit")
344 endif (APPLE)
346 if ((NOT SKIPQT EQUAL 1) AND (Qt5_FOUND))
347     set(CMAKE_AUTOMOC ON)
348     set(CMAKE_AUTORCC ON)
349     set(CMAKE_AUTOUIC ON)
350     set (TARGET_SOURCES
351             ${PM3_ROOT}/client/src/proxgui.cpp
352             ${PM3_ROOT}/client/src/proxguiqt.cpp
353             ${TARGET_SOURCES})
355     add_definitions("-DHAVE_GUI")
356     set(ADDITIONAL_LNK ${Qt5_LIBRARIES} ${ADDITIONAL_LNK})
357 else ((NOT SKIPQT EQUAL 1) AND (Qt5_FOUND))
358     set(TARGET_SOURCES
359             ${PM3_ROOT}/client/src/guidummy.cpp
360             ${TARGET_SOURCES})
361 endif ((NOT SKIPQT EQUAL 1) AND (Qt5_FOUND))
363 if (NOT SKIPBT EQUAL 1)
364     if (BLUEZ_FOUND)
365         add_definitions("-DHAVE_BLUEZ")
366         set(ADDITIONAL_LNK ${BLUEZ_LIBRARIES} ${ADDITIONAL_LNK})
367     endif (BLUEZ_FOUND)
368 endif(NOT SKIPBT EQUAL 1)
370 if (JANSSON_FOUND)
371     set(ADDITIONAL_DIRS ${JANSSON_INCLUDE_DIRS} ${ADDITIONAL_DIRS})
372     set(ADDITIONAL_LNK ${JANSSON_LIBRARIES} ${ADDITIONAL_LNK})
373 endif (JANSSON_FOUND)
375 if (NOT SKIPPYTHON EQUAL 1)
376     if (PYTHON3EMBED_FOUND)
377         add_definitions(-DHAVE_PYTHON)
378         set(ADDITIONAL_DIRS ${PYTHON3EMBED_INCLUDE_DIRS} ${ADDITIONAL_DIRS})
379         set(ADDITIONAL_LNK ${PYTHON3EMBED_LIBRARIES} ${ADDITIONAL_LNK})
380         set(ADDITIONAL_LNKDIRS ${PYTHON3EMBED_LIBRARY_DIRS} ${ADDITIONAL_LNKDIRS})
381     elseif (PYTHON3_FOUND)
382         add_definitions(-DHAVE_PYTHON)
383         set(ADDITIONAL_DIRS ${PYTHON3_INCLUDE_DIRS} ${ADDITIONAL_DIRS})
384         set(ADDITIONAL_LNK ${PYTHON3_LIBRARIES} ${ADDITIONAL_LNK})
385         set(ADDITIONAL_LNKDIRS ${PYTHON3_LIBRARY_DIRS} ${ADDITIONAL_LNKDIRS})
386     endif (PYTHON3EMBED_FOUND)
387 endif (NOT SKIPPYTHON EQUAL 1)
389 if (NOT SKIPREADLINE EQUAL 1)
390     if (READLINE_FOUND)
391         add_definitions("-DHAVE_READLINE")
392         set(ADDITIONAL_DIRS ${READLINE_INCLUDE_DIRS} ${ADDITIONAL_DIRS})
393         set(ADDITIONAL_LNK ${READLINE_LIBRARIES} ${ADDITIONAL_LNK})
394     endif (READLINE_FOUND)
395 endif(NOT SKIPREADLINE EQUAL 1)
397 if (BZIP2_FOUND)
398     set(ADDITIONAL_DIRS ${BZIP2_INCLUDE_DIRS} ${ADDITIONAL_DIRS})
399     set(ADDITIONAL_LNK ${BZIP2_LIBRARIES} ${ADDITIONAL_LNK})
400 endif (BZIP2_FOUND)
402 if (WHEREAMI_FOUND)
403     set(ADDITIONAL_DIRS ${WHEREAMI_INCLUDE_DIRS} ${ADDITIONAL_DIRS})
404     set(ADDITIONAL_LNK ${WHEREAMI_LIBRARIES} ${ADDITIONAL_LNK})
405 endif (WHEREAMI_FOUND)
407 message(STATUS "===================================================================")
408 if (SKIPQT EQUAL 1)
409     message(STATUS "GUI support:       skipped")
410 else (SKIPQT EQUAL 1)
411     if (Qt5_FOUND)
412         message(STATUS "GUI support:       QT5 found, enabled")
413     else (Qt5_FOUND)
414         message(STATUS "GUI support:       QT5 not found, disabled")
415     endif (Qt5_FOUND)
416 endif (SKIPQT EQUAL 1)
418 if (SKIPBT EQUAL 1)
419     message(STATUS "native BT support: skipped")
420 else (SKIPBT EQUAL 1)
421     if (BLUEZ_FOUND)
422         message(STATUS "native BT support: Bluez found, enabled")
423     else (BLUEZ_FOUND)
424         message(STATUS "native BT support: Bluez not found, disabled")
425     endif (BLUEZ_FOUND)
426 endif(SKIPBT EQUAL 1)
428 if (EMBED_BZIP2)
429     message(STATUS "Bzip2 library:     embedded")
430 else (EMBED_BZIP2)
431     message(STATUS "Bzip2 library:     system library found")
432 endif (EMBED_BZIP2)
434 if (SKIPJANSSONSYSTEM EQUAL 1)
435     message(STATUS "Jansson library:   local library forced")
436 else (SKIPJANSSONSYSTEM EQUAL 1)
437     if (JANSSON_FOUND)
438         message(STATUS "Jansson library:   system library found")
439     else (JANSSON_FOUND)
440         message(STATUS "Jansson library:   system library not found, using local library")
441     endif (JANSSON_FOUND)
442 endif (SKIPJANSSONSYSTEM EQUAL 1)
444 if (SKIPPYTHON EQUAL 1)
445     message(STATUS "Python3 library:   skipped")
446 else (SKIPPYTHON EQUAL 1)
447     if (PYTHON3EMBED_FOUND)
448         message(STATUS "Python3 library:   Python3 embed found, enabled")
449     elseif (PYTHON3_FOUND)
450         message(STATUS "Python3 library:   Python3 found, enabled")
451     else (PYTHON3EMBED_FOUND)
452         message(STATUS "Python3 library:   Python3 not found, disabled")
453     endif (PYTHON3EMBED_FOUND)
454 endif(SKIPPYTHON EQUAL 1)
456 if (SKIPREADLINE EQUAL 1)
457     message(STATUS "Readline library:  skipped")
458 else (SKIPREADLINE EQUAL 1)
459     if (READLINE_FOUND)
460         if (EMBED_READLINE)
461             message(STATUS "Readline library:  embedded")
462         else (EMBED_READLINE)
463             message(STATUS "Readline library:  system library found")
464         endif (EMBED_READLINE)
465     else (READLINE_FOUND)
466         message(STATUS "Readline library:  Readline not found, disabled")
467     endif (READLINE_FOUND)
468 endif(SKIPREADLINE EQUAL 1)
470 if (SKIPWHEREAMISYSTEM EQUAL 1)
471     message(STATUS "Whereami library:  local library forced")
472 else (SKIPWHEREAMISYSTEM EQUAL 1)
473     if (WHEREAMI_FOUND)
474         message(STATUS "Whereami library:  system library found")
475     else (WHEREAMI_FOUND)
476         message(STATUS "Whereami library:  system library not found, using local library")
477     endif (WHEREAMI_FOUND)
478 endif (SKIPWHEREAMISYSTEM EQUAL 1)
480 # Lua SWIG
481 if (EXISTS ${PM3_ROOT}/client/src/pm3_luawrap.c)
482     set (TARGET_SOURCES
483             ${PM3_ROOT}/client/src/pm3_luawrap.c
484             ${TARGET_SOURCES})
485     add_definitions(-DHAVE_LUA_SWIG)
486     message(STATUS "Lua SWIG:          wrapper found")
487 endif (EXISTS ${PM3_ROOT}/client/src/pm3_luawrap.c)
489 # Python SWIG
490 if (NOT SKIPPYTHON EQUAL 1)
491     if (PYTHON3EMBED_FOUND OR PYTHON3_FOUND)
492         if (EXISTS ${PM3_ROOT}/client/src/pm3_pywrap.c)
493             set (TARGET_SOURCES
494                     ${PM3_ROOT}/client/src/pm3_pywrap.c
495                     ${TARGET_SOURCES})
496             add_definitions(-DHAVE_PYTHON_SWIG)
497             message(STATUS "Python SWIG:       wrapper found")
498         endif (EXISTS ${PM3_ROOT}/client/src/pm3_pywrap.c)
499     endif (PYTHON3EMBED_FOUND OR PYTHON3_FOUND)
500 endif (NOT SKIPPYTHON EQUAL 1)
501 message(STATUS "===================================================================")
503 add_executable(proxmark3
504         ${PM3_ROOT}/client/src/proxmark3.c
505         ${TARGET_SOURCES}
506         ${ADDITIONAL_SRC}
509 target_compile_options(proxmark3 PUBLIC -Wall -Werror -O3)
510 if (EMBED_READLINE)
511     if (NOT SKIPREADLINE EQUAL 1)
512         add_dependencies(proxmark3 ncurses readline)
513     endif (NOT SKIPREADLINE EQUAL 1)
514 endif (EMBED_READLINE)
515 if (EMBED_BZIP2)
516     add_dependencies(proxmark3 bzip2)
517 endif (EMBED_BZIP2)
519 if (MINGW)
520     # Mingw uses by default Microsoft printf, we want the GNU printf (e.g. for %z)
521     # and setting _ISOC99_SOURCE sets internally __USE_MINGW_ANSI_STDIO=1
522     # FTR __USE_MINGW_ANSI_STDIO seems deprecated in Mingw32
523     # but not Mingw64 https://fr.osdn.net/projects/mingw/lists/archive/users/2019-January/000199.html
524     target_compile_definitions(proxmark3 PRIVATE _ISOC99_SOURCE)
526     set(CMAKE_C_FLAGS "-mno-ms-bitfields -fexec-charset=cp850 ${CMAKE_C_FLAGS}")
527     set(CMAKE_CXX_FLAGS "-mno-ms-bitfields -fexec-charset=cp850 ${CMAKE_CXX_FLAGS}")
528 endif (MINGW)
530 target_include_directories(proxmark3 PRIVATE
531         ${PM3_ROOT}/common
532         ${PM3_ROOT}/common_fpga
533         ${PM3_ROOT}/include
534         ${PM3_ROOT}/client/src
535         ${PM3_ROOT}/client/include
536         ${ADDITIONAL_DIRS}
539 if (NOT APPLE)
540     # required for Raspberry Pi, but breaks with clang (OSX). Need to be at the end of the linker line.
541     set(ADDITIONAL_LNK ${ADDITIONAL_LNK} -Wl,--as-needed -latomic -Wl,--no-as-needed)
542 endif (NOT APPLE)
544 if (NOT JANSSON_FOUND)
545     set(ADDITIONAL_LNK pm3rrg_rdv4_jansson ${ADDITIONAL_LNK})
546 endif (NOT JANSSON_FOUND)
547 if (NOT WHEREAMI_FOUND)
548     set(ADDITIONAL_LNK pm3rrg_rdv4_whereami ${ADDITIONAL_LNK})
549 endif (NOT WHEREAMI_FOUND)
551 target_link_libraries(proxmark3 PRIVATE
552         m
553         pm3rrg_rdv4_mbedtls
554         pm3rrg_rdv4_cliparser
555         pm3rrg_rdv4_lua
556         pm3rrg_rdv4_tinycbor
557         pm3rrg_rdv4_amiibo
558         pm3rrg_rdv4_reveng
559         pm3rrg_rdv4_hardnested
560         ${ADDITIONAL_LNK})
562 if (NOT SKIPPTHREAD EQUAL 1)
563     target_link_libraries(proxmark3 PRIVATE pthread)
564 endif (NOT SKIPPTHREAD EQUAL 1)
566 if (NOT SKIPPYTHON EQUAL 1)
567     # OSX have a hard time compiling python3 dependency with older cmake.
568     if (PYTHON3EMBED_FOUND OR PYTHON3_FOUND)
569         if (NOT CMAKE_VERSION VERSION_LESS 3.13)
570                target_link_directories(proxmark3 PRIVATE ${ADDITIONAL_LNKDIRS})
571         elseif (APPLE)
572                message( SEND_ERROR "Your CMAKE version is too old for Apple platform, please update to a version >=3.13" )
573         endif (NOT CMAKE_VERSION VERSION_LESS 3.13)
574     endif (PYTHON3EMBED_FOUND OR PYTHON3_FOUND)
575 endif (NOT SKIPPYTHON EQUAL 1)
577 install(TARGETS proxmark3 DESTINATION "bin")
578 install(DIRECTORY cmdscripts lualibs luascripts pyscripts resources dictionaries DESTINATION "share/proxmark3")
580 add_custom_command(OUTPUT lualibs/pm3_cmd.lua
581         COMMAND "awk -f pm3_cmd_h2lua.awk ../include/pm3_cmd.h >  lualibs/pm3_cmd.lua"
582         COMMENT "Creating lualibs/pm3_cmd.lua"
583         )
585 add_custom_command(OUTPUT lualibs/mfc_default_keys.lua
586         COMMAND "awk -f default_keys_dic2lua.awk mfc_default_keys.dic >  lualibs/mfc_default_keys.lua"
587         COMMENT "Creating lualibs/mfc_default_keys.lua"
588         )
590 #"make package" will trigger this
591 SET(CPACK_GENERATOR "DEB")
592 SET(CPACK_DEBIAN_PACKAGE_MAINTAINER "Iceman")
593 INCLUDE(CPack)