-
Notifications
You must be signed in to change notification settings - Fork 335
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
863 lines (734 loc) · 25.6 KB
/
CMakeLists.txt
File metadata and controls
863 lines (734 loc) · 25.6 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
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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
cmake_minimum_required(VERSION 3.10)
# set the project name
project(openFPGALoader VERSION "1.1.1" LANGUAGES CXX)
add_definitions(-DVERSION=\"v${PROJECT_VERSION}\")
#if(CMAKE_SYSTEM_NAME STREQUAL "Windows" AND NOT CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows")
# set(WINDOWS_CROSSCOMPILE ON)
#else()
# set(WINDOWS_CROSSCOMPILE OFF)
#endif()
####################################################################################################
# Generics Options
####################################################################################################
option(ENABLE_OPTIM "Enable build with -O3 optimization level" ON)
option(BUILD_STATIC "Whether or not to build with static libraries" OFF)
option(USE_PKGCONFIG "Use pkgconfig to find libraries" ON)
option(LINK_CMAKE_THREADS "Use CMake find_package to link the threading library" OFF)
option(WINDOWS_CROSSCOMPILE "Enable cross-compile on windows" OFF)
option(WINDOWS_STATIC_ZLIB "Link zlib statically for Windows builds" ON)
if (${CMAKE_SYSTEM_NAME} MATCHES "Windows")
set(ENABLE_UDEV OFF)
else()
option(ENABLE_UDEV "use udev to search JTAG adapter from /dev/xx" ON)
endif()
option(ENABLE_USB_SCAN "Enable USB Scan option" ON)
####################################################################################################
# CABLES Options
####################################################################################################
# set all cable on by default
option(ENABLE_CABLE_ALL "Enable all cables" ON)
option(ENABLE_ANLOGIC_CABLE "enable Anlogic cable (requires libUSB)" ${ENABLE_CABLE_ALL})
option(ENABLE_CH347 "enable CH347 cable (requires libUSB)" ${ENABLE_CABLE_ALL})
# CMSIS-DAP requires hidapi which is complex to cross-compile, disable by default for cross-compilation
if (NOT WINDOWS_CROSSCOMPILE)
option(ENABLE_CMSISDAP "enable cmsis DAP interface (requires hidapi)" ${ENABLE_CABLE_ALL})
else()
option(ENABLE_CMSISDAP "enable cmsis DAP interface (requires hidapi)" OFF)
endif()
option(ENABLE_DIRTYJTAG "enable dirtyJtag cable (requires libUSB)" ${ENABLE_CABLE_ALL})
option(ENABLE_ESP_USB "enable ESP32S3 cable (requires libUSB)" ${ENABLE_CABLE_ALL})
option(ENABLE_JLINK "enable JLink cable (requires libUSB)" ${ENABLE_CABLE_ALL})
option(ENABLE_DFU "enable DFU support (requires libUSB)" ${ENABLE_CABLE_ALL})
option(ENABLE_FTDI_BASED_CABLE "enable cables based on FTDI (requires libFTDI" ${ENABLE_CABLE_ALL})
option(ENABLE_GOWIN_GWU2X "enable Gowin GWU2X interface" ${ENABLE_CABLE_ALL})
option(ENABLE_SVF_JTAG "enable SVF support" ${ENABLE_CABLE_ALL})
option(ENABLE_USB_BLASTERI "enable Altera USB Blaster I support" ${ENABLE_CABLE_ALL})
option(ENABLE_USB_BLASTERII "enable Altera USB Blaster II support" ${ENABLE_CABLE_ALL})
set(BLASTERII_PATH "" CACHE STRING "usbBlasterII firmware directory")
set(ISE_PATH "/opt/Xilinx/14.7" CACHE STRING "ise root directory (default: /opt/Xilinx/14.7)")
# Libgpiod is only available on Linux OS.
if (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
option(ENABLE_LIBGPIOD "enable libgpiod bitbang driver (requires libgpiod)" ${ENABLE_CABLE_ALL})
else()
set(ENABLE_LIBGPIOD OFF)
endif()
# XVC and RemoteBitbang are not available on Windows OS.
if (NOT ${CMAKE_SYSTEM_NAME} MATCHES "Windows")
option(ENABLE_REMOTEBITBANG "enable remote bitbang driver" ${ENABLE_CABLE_ALL})
option(ENABLE_XILINX_VIRTUAL_CABLE_CLIENT "enable Xilinx Virtual Cable (XVC) client support" ${ENABLE_CABLE_ALL})
option(ENABLE_XILINX_VIRTUAL_CABLE_SERVER "enable Xilinx Virtual Cable (XVC) server support" ${ENABLE_CABLE_ALL})
else()
set(ENABLE_REMOTEBITBANG OFF)
set(ENABLE_XILINX_VIRTUAL_CABLE_CLIENT OFF)
set(ENABLE_XILINX_VIRTUAL_CABLE_SERVER OFF)
endif()
####################################################################################################
# VENDORS Options
####################################################################################################
# set all vendor on by default
option(ENABLE_VENDORS_ALL "Enable all vendors support" ON)
option(ENABLE_ALTERA_SUPPORT "enable Altera FPGAs Support" ${ENABLE_VENDORS_ALL})
option(ENABLE_ANLOGIC_SUPPORT "enable Anlogic FPGAs Support" ${ENABLE_VENDORS_ALL})
option(ENABLE_COLOGNECHIP_SUPPORT "enable CologneChip FPGAs Support (requires libftdi)" ${ENABLE_VENDORS_ALL})
option(ENABLE_EFINIX_SUPPORT "enable Efinix FPGAs Support (requires libftdi)" ${ENABLE_VENDORS_ALL})
option(ENABLE_GOWIN_SUPPORT "enable Gowin FPGAs Support" ${ENABLE_VENDORS_ALL})
option(ENABLE_ICE40_SUPPORT "enable Ice40 FPGAs Support (requires libftdi)" ${ENABLE_VENDORS_ALL})
option(ENABLE_LATTICE_SUPPORT "enable Lattice FPGAs Support" ${ENABLE_VENDORS_ALL})
option(ENABLE_LATTICESSPI_SUPPORT "enable Lattice FPGAs Support (SSPI / requires libftdi)" ${ENABLE_VENDORS_ALL})
option(ENABLE_XILINX_SUPPORT "enable Xilinx FPGAs Support" ${ENABLE_VENDORS_ALL})
####################################################################################################
# Variables
####################################################################################################
# set dependencies
set(USE_FX2_LL OFF)
set(USE_LIBFTDI OFF)
set(USE_LIBUSB OFF)
set(USE_LIBUSB_LL OFF)
# Only adds libftdi as dependency when a cable
# need this library.
if (ENABLE_FTDI_BASED_CABLE OR ENABLE_USB_BLASTERI OR ENABLE_XILINX_VIRTUAL_CABLE_SERVER)
set(USE_LIBFTDI ON)
else()
message("disabled all cables based on FTDI devices")
endif(ENABLE_FTDI_BASED_CABLE OR ENABLE_USB_BLASTERI OR ENABLE_XILINX_VIRTUAL_CABLE_SERVER)
# Only adds libusb as dependency when a cable need this library
if (ENABLE_DFU OR ENABLE_ANLOGIC_CABLE OR ENABLE_CH347 OR ENABLE_DIRTYJTAG
OR ENABLE_ESP_USB OR ENABLE_JLINK OR ENABLE_GOWIN_GWU2X OR ENABLE_USB_BLASTERII OR ENABLE_USB_SCAN)
set(USE_LIBUSB ON)
endif()
if (ENABLE_USB_SCAN OR ENABLE_GOWIN_GWU2X)
set(USE_LIBUSB_LL ON)
endif()
# Only enable fx2_ll when cable using it
if (ENABLE_USB_BLASTERII)
set(USE_FX2_LL ON)
endif()
####################################################################################################
# Cross-compilation support
####################################################################################################
# Detect cross-compilation for Windows from Linux/macOS
if(WINDOWS_CROSSCOMPILE)
set(CROSS_COMPILING_WINDOWS TRUE)
message(STATUS "Cross-compiling for Windows from ${CMAKE_HOST_SYSTEM_NAME}")
# Option to automatically download and build cross-compile dependencies
option(CROSS_COMPILE_DEPS "Download and build Windows dependencies for cross-compilation" ON)
if(CROSS_COMPILE_DEPS)
# Include the cross-compilation module
list(INSERT CMAKE_MODULE_PATH 0 ${PROJECT_SOURCE_DIR}/cmake/Modules)
include(CrossCompileWindows)
# Setup the dependencies (downloads libusb, builds libftdi)
setup_windows_cross_compile_deps()
# Update pkg-config path for the dependencies
set(ENV{PKG_CONFIG_PATH} "${CROSS_DEPS_INSTALL_DIR}/lib/pkgconfig:$ENV{PKG_CONFIG_PATH}")
# Add the cross-compiled dependencies to the search path
list(APPEND CMAKE_PREFIX_PATH ${CROSS_DEPS_INSTALL_DIR})
include_directories(${CROSS_DEPS_INSTALL_DIR}/include)
link_directories(${CROSS_DEPS_INSTALL_DIR}/lib)
endif()
else()
set(CROSS_COMPILING_WINDOWS FALSE)
endif()
####################################################################################################
# Build options
####################################################################################################
## specify the C++ standard
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True)
set(CMAKE_CXX_FLAGS_DEBUG "-g -Wall -Wextra ${CMAKE_CXX_FLAGS_DEBUG}")
if(ENABLE_OPTIM AND NOT(CMAKE_BUILD_TYPE STREQUAL "Debug"))
set(CMAKE_CXX_FLAGS "-O3 ${CMAKE_CXX_FLAGS}")
endif()
if (BUILD_STATIC)
set(CMAKE_EXE_LINKER_FLAGS "-static-libstdc++ -static ${CMAKE_EXE_LINKER_FLAGS}")
set(BUILD_SHARED_LIBS OFF)
endif()
include(GNUInstallDirs)
# By default: DATA_DIR="/usr/local/share"
add_definitions(-DDATA_DIR=\"${CMAKE_INSTALL_FULL_DATAROOTDIR}\")
add_definitions(-DISE_DIR=\"${ISE_PATH}\")
####################################################################################################
# Dependencies check/search
####################################################################################################
if (USE_LIBFTDI)
# Try to find the LibFTDI1 with cmake
find_package(LibFTDI1 QUIET)
endif()
if (USE_PKGCONFIG)
find_package(PkgConfig REQUIRED)
# Backward compat when the libftdi is not found
# by using cmake
if (USE_LIBFTDI)
if (NOT LIBFTDI_FOUND)
pkg_check_modules(LIBFTDI REQUIRED libftdi1)
string(REPLACE "." ";" VERSION_LIST ${LIBFTDI_VERSION})
list(GET VERSION_LIST 0 LIBFTDI_VERSION_MAJOR)
list(GET VERSION_LIST 1 LIBFTDI_VERSION_MINOR)
endif()
else()
set(LIBFTDI_LIBRARY_DIRS "")
set(LIBFTDI_INCLUDE_DIRS "")
set(LIBFTDI_LIBRARIES "")
endif(USE_LIBFTDI)
if (USE_LIBUSB)
pkg_check_modules(LIBUSB REQUIRED libusb-1.0)
else()
set(LIBUSB_LIBRARY_DIRS "")
set(LIBUSB_INCLUDE_DIRS "")
set(LIBUSB_LIBRARIES "")
endif(USE_LIBUSB)
if(ENABLE_CMSISDAP)
pkg_check_modules(HIDAPI hidapi-libusb)
# if libusb not found try with hidraw
if (NOT HIDAPI_FOUND)
pkg_check_modules(HIDAPI hidapi-hidraw)
endif()
if (NOT HIDAPI_FOUND)
pkg_check_modules(HIDAPI hidapi)
endif()
endif()
# zlib support (gzip)
if(WINDOWS_CROSSCOMPILE)
if (WINDOWS_STATIC_ZLIB)
set(ZLIB_USE_STATIC_LIBS ON)
endif()
# Use CMake zlib finder for Windows builds to avoid host pkg-config contamination
# during cross-compilation and to allow static linking selection.
find_package(ZLIB QUIET)
if (NOT ZLIB_FOUND)
if (WINDOWS_CROSSCOMPILE)
message(FATAL_ERROR
"zlib for Windows target not found. Install MinGW zlib development files "
"(for example: libz-mingw-w64-dev on Debian/Ubuntu or mingw64-zlib on Fedora).")
else()
message(FATAL_ERROR
"zlib for Windows build not found. Install zlib development files for your "
"Windows toolchain.")
endif()
endif()
if (WINDOWS_STATIC_ZLIB AND ZLIB_LIBRARIES MATCHES "\\.dll\\.a$")
message(FATAL_ERROR
"Static zlib requested (WINDOWS_STATIC_ZLIB=ON), but CMake selected "
"'${ZLIB_LIBRARIES}'. Install static zlib (for example mingw64-zlib-static) "
"or set -DWINDOWS_STATIC_ZLIB=OFF.")
endif()
else()
pkg_check_modules(ZLIB zlib)
if (NOT ZLIB_FOUND)
# try zlib-ng
pkg_check_modules(ZLIB zlib-ng)
if (ZLIB_FOUND)
add_definitions(-DHAS_ZLIBNG)
else()
message(FATAL_ERROR "Could find ZLIB")
endif()
endif(NOT ZLIB_FOUND)
endif()
if (ENABLE_UDEV)
pkg_check_modules(LIBUDEV libudev)
if (LIBUDEV_FOUND)
add_definitions(-DUSE_UDEV)
else()
message("libudev not found, disabling udev support and -D parameter")
set(ENABLE_UDEV OFF)
endif()
endif()
if (ENABLE_LIBGPIOD)
pkg_check_modules(LIBGPIOD libgpiod)
if (NOT LIBGPIOD_FOUND)
message("libgpiod not found, disabling gpiod support")
set(ENABLE_LIBGPIOD OFF)
endif()
endif()
endif()
####################################################################################################
# FILES
####################################################################################################
# ===========================
# Core Classes
# ===========================
set(OPENFPGALOADER_SOURCE
src/common.cpp
src/configBitstreamParser.cpp
src/device.cpp
src/display.cpp
src/main.cpp
src/progressBar.cpp
)
set(OPENFPGALOADER_HEADERS
src/board.hpp
src/cable.hpp
src/common.hpp
src/configBitstreamParser.hpp
src/cxxopts.hpp
src/device.hpp
src/display.hpp
src/part.hpp
src/progressBar.hpp
)
# ===========================
# Parsers classes
# ===========================
list(APPEND OPENFPGALOADER_SOURCE src/rawParser.cpp)
list(APPEND OPENFPGALOADER_HEADERS src/rawParser.hpp)
if (${ENABLE_LATTICE_SUPPORT} OR ${ENABLE_XILINX_SUPPORT})
list(APPEND OPENFPGALOADER_SOURCE
src/jedParser.cpp
src/mcsParser.cpp
)
list(APPEND OPENFPGALOADER_HEADERS
src/jedParser.hpp
src/mcsParser.hpp
)
endif()
# ===========================
# To be sorted
# ===========================
list(APPEND OPENFPGALOADER_SOURCE
src/bpiFlash.cpp
src/spiFlash.cpp
src/flashInterface.cpp
src/jtag.cpp
)
list(APPEND OPENFPGALOADER_HEADERS
src/bpiFlash.hpp
src/jtag.hpp
src/jtagInterface.hpp
src/spiFlash.hpp
src/spiFlashdb.hpp
src/flashInterface.hpp
)
# FTDI Based cables
if (${USE_LIBFTDI})
add_definitions(-DUSE_LIBFTDI)
list(APPEND OPENFPGALOADER_SOURCE
src/ch552_jtag.cpp
src/ftdiJtagBitbang.cpp
src/ftdiJtagMPSSE.cpp
src/ftdipp_mpsse.cpp
src/ftdispi.cpp
)
list(APPEND OPENFPGALOADER_HEADERS
src/ch552_jtag.hpp
src/ftdiJtagBitbang.hpp
src/ftdiJtagMPSSE.hpp
src/ftdipp_mpsse.hpp
src/ftdispi.hpp
)
# CologneChip Drivers / Files parsers.
if (ENABLE_COLOGNECHIP_SUPPORT)
list(APPEND OPENFPGALOADER_SOURCE
src/colognechip.cpp
src/colognechipCfgParser.cpp
)
list(APPEND OPENFPGALOADER_HEADERS
src/colognechip.hpp
src/colognechipCfgParser.hpp
)
add_definitions(-DENABLE_COLOGNECHIP_SUPPORT=1)
message("CologneChip support enabled")
else()
message("CologneChip support disabled")
endif(ENABLE_COLOGNECHIP_SUPPORT)
# Efinix Drivers / Files parsers.
if (ENABLE_EFINIX_SUPPORT)
list(APPEND OPENFPGALOADER_SOURCE
src/efinix.cpp
src/efinixHexParser.cpp
)
list(APPEND OPENFPGALOADER_HEADERS
src/efinix.hpp
src/efinixHexParser.hpp
)
add_definitions(-DENABLE_EFINIX_SUPPORT=1)
message("Efinix support enabled")
else()
message("Efinix support disabled")
endif(ENABLE_EFINIX_SUPPORT)
# ICE40 Driver.
if (ENABLE_ICE40_SUPPORT)
list(APPEND OPENFPGALOADER_SOURCE src/ice40.cpp)
list(APPEND OPENFPGALOADER_HEADERS src/ice40.hpp)
add_definitions(-DENABLE_ICE40_SUPPORT=1)
message("ICE40 support enabled")
else()
message("ICE40 support disabled")
endif(ENABLE_ICE40_SUPPORT)
# Lattice SSPI Driver.
if (ENABLE_LATTICESSPI_SUPPORT)
list(APPEND OPENFPGALOADER_SOURCE src/latticeSSPI.cpp)
list(APPEND OPENFPGALOADER_HEADERS src/latticeSSPI.hpp)
add_definitions(-DENABLE_LATTICESSPI_SUPPORT=1)
message("Lattice SSPI support enabled")
else()
message("Lattice SSPI support disabled")
endif(ENABLE_LATTICESSPI_SUPPORT)
endif()
# Altera Drivers / Files parsers.
if (ENABLE_ALTERA_SUPPORT)
list(APPEND OPENFPGALOADER_SOURCE
src/altera.cpp
src/pofParser.cpp
)
list(APPEND OPENFPGALOADER_HEADERS
src/altera.hpp
src/pofParser.hpp
)
add_definitions(-DENABLE_ALTERA_SUPPORT=1)
message("Altera support enabled")
else()
message("Altera support disabled")
endif(ENABLE_ALTERA_SUPPORT)
# Anlogic Drivers / Files parsers.
if (ENABLE_ANLOGIC_SUPPORT)
list(APPEND OPENFPGALOADER_SOURCE
src/anlogic.cpp
src/anlogicBitParser.cpp
)
list(APPEND OPENFPGALOADER_HEADERS
src/anlogic.hpp
src/anlogicBitParser.hpp
)
add_definitions(-DENABLE_ANLOGIC_SUPPORT=1)
message("Anlogic support enabled")
else()
message("Anlogic support disabled")
endif(ENABLE_ANLOGIC_SUPPORT)
# Gowin Drivers / Files parsers.
if (ENABLE_GOWIN_SUPPORT)
list(APPEND OPENFPGALOADER_SOURCE
src/gowin.cpp
src/fsparser.cpp
)
list(APPEND OPENFPGALOADER_HEADERS
src/gowin.hpp
src/fsparser.hpp
)
add_definitions(-DENABLE_GOWIN_SUPPORT=1)
message("Gowin support enabled")
else()
message("Gowin support disabled")
endif(ENABLE_GOWIN_SUPPORT)
# Xilinx Drivers / Files parsers.
if (ENABLE_XILINX_SUPPORT)
list(APPEND OPENFPGALOADER_SOURCE
src/bitparser.cpp
src/xilinx.cpp
src/xilinxMapParser.cpp
)
list(APPEND OPENFPGALOADER_HEADERS
src/bitparser.hpp
src/xilinx.hpp
src/xilinxMapParser.hpp
)
add_definitions(-DENABLE_XILINX_SUPPORT=1)
message("Xilinx support enabled")
else()
message("Xilinx support disabled")
endif(ENABLE_XILINX_SUPPORT)
# Lattice Drivers / Files parsers.
if (ENABLE_LATTICE_SUPPORT)
list(APPEND OPENFPGALOADER_SOURCE
src/lattice.cpp
src/feaparser.cpp
src/latticeBitParser.cpp
)
list(APPEND OPENFPGALOADER_HEADERS
src/lattice.hpp
src/feaparser.hpp
src/latticeBitParser.hpp
)
add_definitions(-DENABLE_LATTICE_SUPPORT=1)
message("Lattice support enabled")
else()
message("Lattice support disabled")
endif(ENABLE_LATTICE_SUPPORT)
# Cables select
# DFU
if (ENABLE_DFU)
list(APPEND OPENFPGALOADER_SOURCE
src/dfu.cpp
src/dfuFileParser.cpp
)
list(APPEND OPENFPGALOADER_HEADERS
src/dfu.hpp
src/dfuFileParser.hpp
)
endif(ENABLE_DFU)
# Anlogic Cable
if (ENABLE_ANLOGIC_CABLE)
list(APPEND OPENFPGALOADER_SOURCE src/anlogicCable.cpp)
list(APPEND OPENFPGALOADER_HEADERS src/anlogicCable.hpp)
endif()
# CH347
if (ENABLE_CH347)
list(APPEND OPENFPGALOADER_SOURCE src/ch347jtag.cpp)
list(APPEND OPENFPGALOADER_HEADERS src/ch347jtag.hpp)
endif()
# dirtyJtag
if (ENABLE_DIRTYJTAG)
list(APPEND OPENFPGALOADER_SOURCE src/dirtyJtag.cpp)
list(APPEND OPENFPGALOADER_HEADERS src/dirtyJtag.hpp)
endif()
# ESP32S3
if (ENABLE_ESP_USB)
list(APPEND OPENFPGALOADER_SOURCE src/esp_usb_jtag.cpp)
list(APPEND OPENFPGALOADER_HEADERS src/esp_usb_jtag.hpp)
endif()
# Gowin GWU2X JTAG interface
if(ENABLE_GOWIN_GWU2X)
list(APPEND OPENFPGALOADER_SOURCE src/gwu2x_jtag.cpp)
list(APPEND OPENFPGALOADER_HEADERS src/gwu2x_jtag.hpp)
endif()
# Jetson Nano (libGPIO based)
if (ENABLE_JETSONNANOGPIO)
list(APPEND OPENFPGALOADER_SOURCE src/jetsonNanoJtagBitbang.cpp)
list(APPEND OPENFPGALOADER_HEADERS src/jetsonNanoJtagBitbang.hpp)
endif()
# JLINK
if (ENABLE_JLINK)
list(APPEND OPENFPGALOADER_SOURCE src/jlink.cpp)
list(APPEND OPENFPGALOADER_HEADERS src/jlink.hpp)
endif()
# libGPIOD support
if (ENABLE_LIBGPIOD)
list(APPEND OPENFPGALOADER_SOURCE src/libgpiodJtagBitbang.cpp)
list(APPEND OPENFPGALOADER_HEADERS src/libgpiodJtagBitbang.hpp)
endif()
# RemoteBitbang
if (ENABLE_REMOTEBITBANG)
list (APPEND OPENFPGALOADER_SOURCE src/remoteBitbang_client.cpp)
list (APPEND OPENFPGALOADER_HEADERS src/remoteBitbang_client.hpp)
endif()
# SVF JTAG file type support
if (ENABLE_SVF_JTAG)
list (APPEND OPENFPGALOADER_SOURCE src/svf_jtag.cpp)
list (APPEND OPENFPGALOADER_HEADERS src/svf_jtag.hpp)
add_definitions(-DENABLE_SVF_JTAG)
endif()
# Xilinx Virtual Cable
if (ENABLE_XILINX_VIRTUAL_CABLE_CLIENT)
list (APPEND OPENFPGALOADER_SOURCE src/xvc_client.cpp)
list (APPEND OPENFPGALOADER_HEADERS src/xvc_client.hpp)
endif()
if (ENABLE_XILINX_VIRTUAL_CABLE_SERVER)
list (APPEND OPENFPGALOADER_SOURCE src/xvc_server.cpp)
list (APPEND OPENFPGALOADER_HEADERS src/xvc_server.hpp)
endif()
# Altera USB Blaster (I & II).
if (ENABLE_USB_BLASTERI OR ENABLE_USB_BLASTERII)
add_definitions(-DENABLE_USBBLASTER)
if (ENABLE_USB_BLASTERI)
add_definitions(-DENABLE_USB_BLASTERI)
endif()
if (ENABLE_USB_BLASTERII)
add_definitions(-DBLASTERII_DIR=\"${BLASTERII_PATH}\")
add_definitions(-DENABLE_USB_BLASTERII)
endif (ENABLE_USB_BLASTERII)
list(APPEND OPENFPGALOADER_SOURCE src/usbBlaster.cpp)
list(APPEND OPENFPGALOADER_HEADERS src/usbBlaster.hpp)
endif(ENABLE_USB_BLASTERI OR ENABLE_USB_BLASTERII)
link_directories(
${LIBUSB_LIBRARY_DIRS}
${LIBFTDI_LIBRARY_DIRS}
)
if (ENABLE_LIBGPIOD)
link_directories(${LIBGPIOD_LIBRARY_DIRS})
endif()
if (ENABLE_CMSISDAP AND HIDAPI_FOUND)
link_directories(${HIDAPI_LIBRARY_DIRS})
endif()
if (USE_LIBUSB_LL)
list(APPEND OPENFPGALOADER_SOURCE src/libusb_ll.cpp)
list(APPEND OPENFPGALOADER_HEADERS src/libusb_ll.hpp)
endif()
if (USE_FX2_LL)
list(APPEND OPENFPGALOADER_SOURCE src/fx2_ll.cpp src/ihexParser.cpp)
list(APPEND OPENFPGALOADER_HEADERS src/fx2_ll.hpp src/ihexParser.hpp)
endif()
add_executable(openFPGALoader
${OPENFPGALOADER_SOURCE}
${OPENFPGALOADER_HEADERS}
)
include_directories(
${LIBUSB_INCLUDE_DIRS}
${LIBFTDI_INCLUDE_DIRS}
)
target_link_libraries(openFPGALoader
${LIBUSB_LIBRARIES}
${LIBFTDI_LIBRARIES}
)
if (${CMAKE_SYSTEM_NAME} MATCHES "Windows")
# winsock provides ntohs
target_link_libraries(openFPGALoader ws2_32)
target_sources(openFPGALoader PRIVATE src/pathHelper.cpp)
list(APPEND OPENFPGALOADER_HEADERS src/pathHelper.hpp)
endif()
# libusb_attach_kernel_driver is only available on Linux.
if (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
add_definitions(-DATTACH_KERNEL)
endif()
if (ENABLE_UDEV)
include_directories(${LIBUDEV_INCLUDE_DIRS})
target_link_libraries(openFPGALoader ${LIBUDEV_LIBRARIES})
endif()
if (BUILD_STATIC)
set_target_properties(openFPGALoader PROPERTIES LINK_SEARCH_END_STATIC 1)
endif()
# Anlogic Cable
if (ENABLE_ANLOGIC_CABLE)
add_definitions(-DENABLE_ANLOGIC_CABLE=1)
message("Anlogic Cable support enabled")
else()
message("Anlogic Cable support disabled")
endif()
# CH347
if (ENABLE_CH347)
add_definitions(-DENABLE_CH347=1)
message("CH347 support enabled")
else()
message("CH347 support disabled")
endif()
if (ENABLE_CMSISDAP)
if (HIDAPI_FOUND)
include_directories(${HIDAPI_INCLUDE_DIRS})
target_link_libraries(openFPGALoader ${HIDAPI_LIBRARIES})
add_definitions(-DENABLE_CMSISDAP=1)
target_sources(openFPGALoader PRIVATE src/cmsisDAP.cpp)
list (APPEND OPENFPGALOADER_HEADERS src/cmsisDAP.hpp)
message("cmsis_dap support enabled")
else()
message("hidapi-libusb not found: cmsis_dap support disabled")
endif()
endif(ENABLE_CMSISDAP)
# DFU
if (ENABLE_DFU)
add_definitions(-DENABLE_DFU=1)
message("DFU support enabled")
else()
message("DFU support disabled")
endif()
# dirtyJtag
if (ENABLE_DIRTYJTAG)
add_definitions(-DENABLE_DIRTYJTAG=1)
message("dirtyJtag support enabled")
else()
message("dirtyJtag support disabled")
endif()
# ESP32S3
if (ENABLE_ESP_USB)
add_definitions(-DENABLE_ESP_USB=1)
message("ESP32S3 support enabled")
else()
message("ESP32S3 support disabled")
endif()
# Gowin GWU2X JTAG interface
if(ENABLE_GOWIN_GWU2X)
add_definitions(-DENABLE_GOWIN_GWU2X=1)
message("Gowin GWU2X support enabled")
else()
message("Gowin GWU2X support disabled")
endif()
# Jetson Nano (libGPIO based)
if (ENABLE_JETSONNANOGPIO)
add_definitions(-DENABLE_JETSONNANOGPIO=1)
message("Jetson Nano GPIO support enabled")
endif(ENABLE_JETSONNANOGPIO)
# JLINK
if (ENABLE_JLINK)
add_definitions(-DENABLE_JLINK=1)
message("JLink support enabled")
else()
message("JLink support disabled")
endif()
# libGPIOD support
if (ENABLE_LIBGPIOD)
include_directories(${LIBGPIOD_INCLUDE_DIRS})
target_link_libraries(openFPGALoader ${LIBGPIOD_LIBRARIES})
add_definitions(-DENABLE_LIBGPIOD=1)
if (LIBGPIOD_VERSION VERSION_GREATER_EQUAL 2)
message("libgpiod v2 support enabled")
add_definitions(-DGPIOD_APIV2)
else()
message("libgpiod v1 support enabled")
endif()
endif(ENABLE_LIBGPIOD)
if (ENABLE_REMOTEBITBANG)
add_definitions(-DENABLE_REMOTEBITBANG=1)
message("Remote bitbang client support enabled")
else()
message("Remote bitbang client support disabled")
endif()
if (ENABLE_XILINX_VIRTUAL_CABLE_CLIENT)
add_definitions(-DENABLE_XVC_CLIENT=1)
set(CMAKE_EXE_LINKER_FLAGS "-pthread ${CMAKE_EXE_LINKER_FLAGS}")
message("Xilinx Virtual Client support enabled")
else()
message("Xilinx Virtual Client support disabled")
endif()
if (ENABLE_XILINX_VIRTUAL_CABLE_SERVER)
add_definitions(-DENABLE_XVC_SERVER=1)
set(CMAKE_EXE_LINKER_FLAGS "-pthread ${CMAKE_EXE_LINKER_FLAGS}")
message("Xilinx Virtual Server support enabled")
else()
message("Xilinx Virtual Server support disabled")
endif()
# USB Devices Scan
if (ENABLE_USB_SCAN)
add_definitions("-DENABLE_USB_SCAN=1")
endif()
if (ZLIB_FOUND)
include_directories(${ZLIB_INCLUDE_DIRS})
target_link_libraries(openFPGALoader ${ZLIB_LIBRARIES})
add_definitions(-DHAS_ZLIB=1)
else()
message("zlib library not found: can't flash intel/altera devices")
endif()
if (LINK_CMAKE_THREADS)
find_package(Threads REQUIRED)
target_link_libraries(openFPGALoader Threads::Threads)
endif()
if (USE_LIBFTDI)
# libftdi < 1.4 as no usb_addr
# libftdi >= 1.5 as purge_buffer obsolete
math(EXPR FTDI_VAL "${LIBFTDI_VERSION_MAJOR} * 100 + ${LIBFTDI_VERSION_MINOR}")
add_definitions(-DFTDI_VERSION=${FTDI_VAL})
endif()
install(TARGETS openFPGALoader DESTINATION bin)
####################################################################################################
# SPIOverJtag bitstreams install
####################################################################################################
file(GLOB GZ_FILES spiOverJtag/spiOverJtag_*.*.gz)
file(GLOB BPI_GZ_FILES bpiOverJtag/bpiOverJtag_*.bit.gz)
list(APPEND GZ_FILES ${BPI_GZ_FILES})
# Compress rbf and bit files present into repository
# TODO: test compat with Windows and MacOS
list(INSERT CMAKE_MODULE_PATH 0 ${PROJECT_SOURCE_DIR}/cmake/Modules)
include(FindGZIP)
if (NOT ${CMAKE_SYSTEM_NAME} MATCHES "Windows" AND GZIP_PRG)
set(SPIOVERJTAG_DIR "${CMAKE_CURRENT_SOURCE_DIR}/spiOverJtag")
file(GLOB BITS_FILES RELATIVE ${SPIOVERJTAG_DIR} spiOverJtag/spiOverJtag_*.bit)
file(GLOB RBF_FILES RELATIVE ${SPIOVERJTAG_DIR} spiOverJtag/spiOverJtag_*.rbf)
STRING(REGEX REPLACE ".bit" ".bit.gz" BIT_GZ_FILES "${BITS_FILES}")
STRING(REGEX REPLACE ".rbf" ".rbf.gz" RBF_GZ_FILES "${RBF_FILES}")
FOREACH(bit ${BITS_FILES} ${RBF_FILES})
ADD_CUSTOM_COMMAND(OUTPUT ${bit}.gz
COMMAND ${GZIP_PRG} -9 -c ${bit} > ${CMAKE_CURRENT_BINARY_DIR}/${bit}.gz
DEPENDS ${SPIOVERJTAG_DIR}/${bit}
WORKING_DIRECTORY ${SPIOVERJTAG_DIR}
COMMENT "Building ${bit}.gz")
list(APPEND GZ_FILES ${CMAKE_CURRENT_BINARY_DIR}/${bit}.gz)
ENDFOREACH(bit)
ADD_CUSTOM_TARGET(bit ALL DEPENDS ${BIT_GZ_FILES} ${RBF_GZ_FILES})
else()
file(GLOB BITS_FILES spiOverJtag/spiOverJtag_*.bit)
file(GLOB RBF_FILES spiOverJtag/spiOverJtag_*.rbf)
install(FILES
${BITS_FILES}
${RBF_FILES}
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/openFPGALoader
)
endif()
install(FILES
${GZ_FILES}
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/openFPGALoader
)