avrdude/src/CMakeLists.txt

307 lines
7.5 KiB
CMake
Raw Normal View History

2021-12-20 16:50:42 +00:00
#
# CMakeLists.txt - CMake project for AVRDUDE
# Copyright (C) 2021 Marius Greuel
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# =====================================
# Set up flex target
# =====================================
FLEX_TARGET(Parser "lexer.l" "${PROJECT_BINARY_DIR}/lexer.c")
if (FLEX_VERSION VERSION_GREATER_EQUAL 2.5.9)
set(HAVE_YYLEX_DESTROY 1)
endif()
2021-12-20 16:50:42 +00:00
# =====================================
# Set up yacc/bison target
2021-12-20 16:50:42 +00:00
# =====================================
if(BISON_FOUND)
BISON_TARGET(Parser config_gram.y "${PROJECT_BINARY_DIR}/config_gram.c" DEFINES_FILE "${PROJECT_BINARY_DIR}/config_gram.h")
else()
set(YACC_TARGET_outputs "${PROJECT_BINARY_DIR}/config_gram.c")
add_custom_command(OUTPUT ${YACC_TARGET_outputs}
COMMAND ${YACC_EXECUTABLE} -d -o ${YACC_TARGET_outputs} config_gram.y
VERBATIM
COMMENT "[YACC][Parser] Building parser with yacc"
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
set(BISON_Parser_OUTPUTS ${YACC_TARGET_outputs})
2021-12-28 10:26:09 +00:00
endif()
2021-12-20 16:50:42 +00:00
# =====================================
# Setup target specific options
# =====================================
include_directories(BEFORE ${CMAKE_CURRENT_BINARY_DIR})
add_compile_definitions(CONFIG_DIR=\"${CONFIG_DIR}\")
2021-12-20 16:50:42 +00:00
if(WIN32)
set(EXTRA_WINDOWS_RESOURCES "${PROJECT_BINARY_DIR}/src/windows.rc")
2021-12-20 16:50:42 +00:00
set(EXTRA_WINDOWS_LIBRARIES setupapi ws2_32)
endif()
2021-12-28 10:26:09 +00:00
if(MSVC)
enable_language(CXX)
2021-12-28 10:26:09 +00:00
add_compile_definitions(_CRT_SECURE_NO_WARNINGS=1)
add_compile_definitions(_CRT_NONSTDC_NO_WARNINGS=1)
add_compile_definitions(_WINSOCK_DEPRECATED_NO_WARNINGS=1)
add_compile_options(/W3)
add_compile_options(/wd4018) # warning C4018: signed/unsigned mismatch
add_compile_options(/wd4244) # warning C4244: conversion from '...' to '...', possible loss of data
add_compile_options(/wd4267) # warning C4267: conversion from '...' to '...', possible loss of data
2021-12-28 10:26:09 +00:00
add_compile_options(/wd5105) # warning C5105: macro expansion producing 'xxx' has undefined behavior
add_compile_options(/wd6255) # warning C6255: _alloca indicates failure by raising a stack overflow exception. Consider using _malloca instead
2021-12-28 10:26:09 +00:00
set(EXTRA_WINDOWS_SOURCES ${EXTRA_WINDOWS_SOURCES}
"msvc/getopt.c"
"msvc/gettimeofday.c"
"msvc/usleep.cpp"
2021-12-28 10:26:09 +00:00
)
set(EXTRA_WINDOWS_INCLUDES ${EXTRA_WINDOWS_INCLUDES}
"msvc"
2021-12-28 10:26:09 +00:00
)
else()
set(LIB_MATH m)
add_compile_options(-Wall) # -Wextra
2021-12-28 10:26:09 +00:00
endif()
2021-12-20 16:50:42 +00:00
# =====================================
# Setup default port names
2021-12-20 16:50:42 +00:00
# =====================================
if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
set(DEFAULT_PAR_PORT "/dev/parport0")
set(DEFAULT_SER_PORT "/dev/ttyS0")
elseif (CMAKE_SYSTEM_NAME STREQUAL "FreeBSD")
set(DEFAULT_PAR_PORT "/dev/ppi0")
set(DEFAULT_SER_PORT "/dev/cuad0")
elseif (CMAKE_SYSTEM_NAME STREQUAL "Solaris")
set(DEFAULT_PAR_PORT "/dev/printers/0")
set(DEFAULT_SER_PORT "/dev/term/a")
elseif (CMAKE_SYSTEM_NAME STREQUAL "Windows")
set(DEFAULT_PAR_PORT "lpt1")
set(DEFAULT_SER_PORT "com1")
else()
set(DEFAULT_PAR_PORT "unknown")
set(DEFAULT_SER_PORT "unknown")
endif()
# =====================================
# Configure files
# =====================================
2021-12-20 16:50:42 +00:00
configure_file(cmake_config.h.in ac_cfg.h)
configure_file(avrdude.spec.in avrdude.spec)
2021-12-20 16:51:44 +00:00
if(WIN32)
configure_file(windows.rc.in windows.rc)
endif()
2021-12-20 16:50:42 +00:00
add_custom_command(
OUTPUT avrdude.conf
COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_SOURCE_DIR}/avrdude.conf.in" avrdude.conf.in
COMMAND ${CMAKE_COMMAND}
-D HAVE_PARPORT=${HAVE_PARPORT}
-D HAVE_LINUXSPI=${HAVE_LINUXSPI}
-D HAVE_LINUXGPIO=${HAVE_LINUXGPIO}
-D DEFAULT_PAR_PORT=${DEFAULT_PAR_PORT}
-D DEFAULT_SER_PORT=${DEFAULT_SER_PORT}
-P "${CMAKE_CURRENT_SOURCE_DIR}/configure.cmake"
DEPENDS avrdude.conf.in
VERBATIM
)
add_custom_target(conf ALL DEPENDS avrdude.conf)
2021-12-20 16:50:42 +00:00
# =====================================
# Project
# =====================================
add_library(libavrdude
2021-12-20 16:50:42 +00:00
ac_cfg.h
arduino.h
arduino.c
avr.c
avr910.c
avr910.h
Provide cached byte-wise read/write API (#1106) * Provide cached byte-wise read/write API int avr_read_byte_cached(const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM *mem, unsigned long addr, unsigned char *value); int avr_write_byte_cached(const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM *mem, unsigned long addr, unsigned char data); int avr_flush_cache(const PROGRAMMER *pgm, const AVRPART *p); int avr_chip_erase_cached(const PROGRAMMER *pgm, const AVRPART *p); int avr_reset_cache(const PROGRAMMER *pgm, const AVRPART *p); avr_read_byte_cached() and avr_write_byte_cached() use a cache if paged routines are available and if the device memory is EEPROM or flash, otherwise they fall back to pgm->read_byte() and pgm->write_byte(), respectively. Byte-wise cached read always gets its data from the cache, possibly after reading a page from the device memory. Byte-wise cached write with an address in memory range only ever modifies the cache. Any modifications are written to the device after calling avr_flush_cache() or when attempting to read or write from a location outside the address range of the device memory. avr_flush_cache() synchronises pending writes to EEPROM and flash with the device. With some programmer and part combinations, flash (and sometimes EEPROM, too) looks like a NOR memory, ie, one can only write 0 bits, not 1 bits. When this is detected, either page erase is deployed (eg, with parts that have PDI/UPDI interfaces), or if that is not available, both EEPROM and flash caches are fully read in, a pgm->chip_erase() command is issued and both EEPROM and flash are written back to the device. Hence, it can take minutes to ensure that a single previously cleared bit is set and, therefore, this routine should be called sparingly. avr_chip_erase_cached() erases the chip and discards pending writes() to flash or EEPROM. It presets the flash cache to all 0xff alleviating the need to read from the device flash. However, if the programmer serves bootloaders (pgm->prog_modes & PM_SPM) then the flash cache is reset instead, necessitating flash memory be fetched from the device on first read; the reason for this is that bootloaders emulate chip erase and they won't overwrite themselves (some bootloaders, eg, optiboot ignore chip erase commands altogether) making it truly unknowable what the flash contents on device is after a chip erase. For EEPROM avr_chip_erase_cached() concludes that it has been deleted if a previously cached EEPROM page that contained cleared bits now no longer has these clear bits on the device. Only with this evidence is the EEPROM cache preset to all 0xff otherwise the cache discards all pending writes to EEPROM and is left unchanged otherwise. Finally, avr_reset_cache() resets the cache without synchronising pending writes() to the device.
2022-10-05 21:16:15 +00:00
avrcache.c
2021-12-20 16:50:42 +00:00
avrdude.h
avrftdi.c
avrftdi.h
avrftdi_private.h
avrftdi_tpi.c
avrftdi_tpi.h
avrpart.c
bitbang.c
bitbang.h
buspirate.c
buspirate.h
butterfly.c
butterfly.h
config.c
config.h
confwin.c
crc16.c
crc16.h
dfu.c
dfu.h
fileio.c
flip1.c
flip1.h
flip2.c
flip2.h
freebsd_ppi.h
ft245r.c
ft245r.h
jtagmkI.c
jtagmkI.h
jtagmkI_private.h
jtagmkII.c
jtagmkII.h
jtagmkII_private.h
jtag3.c
jtag3.h
jtag3_private.h
libavrdude.h
linuxgpio.c
linuxgpio.h
linuxspi.c
linuxspi.h
linux_ppdev.h
lists.c
micronucleus.c
micronucleus.h
2021-12-20 16:50:42 +00:00
par.c
par.h
pgm.c
pgm_type.c
pickit2.c
pickit2.h
pindefs.c
ppi.c
ppi.h
ppiwin.c
serbb.h
serbb_posix.c
serbb_win32.c
ser_avrdoper.c
ser_posix.c
ser_win32.c
2021-12-22 21:40:21 +00:00
serialupdi.c
serialupdi.h
2021-12-20 16:50:42 +00:00
solaris_ecpp.h
stk500.c
stk500.h
stk500_private.h
stk500v2.c
stk500v2.h
stk500v2_private.h
stk500generic.c
stk500generic.h
2021-12-28 16:57:14 +00:00
teensy.c
teensy.h
2021-12-20 16:50:42 +00:00
tpi.h
2021-12-22 21:40:21 +00:00
updi_constants.h
updi_link.c
updi_link.h
updi_nvm.c
updi_nvm.h
updi_readwrite.c
updi_readwrite.h
updi_state.c
updi_state.h
2022-11-06 01:29:07 +00:00
urclock.c
urclock.h
urclock_private.h
2021-12-20 16:50:42 +00:00
usbasp.c
usbasp.h
usbdevs.h
usb_hidapi.c
usb_libusb.c
usbtiny.h
usbtiny.c
update.c
wiring.h
wiring.c
xbee.h
xbee.c
${FLEX_Parser_OUTPUTS}
${BISON_Parser_OUTPUTS}
"${EXTRA_WINDOWS_SOURCES}"
2021-12-20 16:50:42 +00:00
)
2021-12-22 21:40:21 +00:00
set_target_properties(libavrdude PROPERTIES
PREFIX ""
PUBLIC_HEADER "libavrdude.h"
VERSION 1.0.0
SOVERSION 1
)
2021-12-20 16:50:42 +00:00
target_include_directories(libavrdude
PUBLIC
"${PROJECT_SOURCE_DIR}"
"${PROJECT_BINARY_DIR}"
"${LIBUSB_COMPAT_DIR}"
"${EXTRA_WINDOWS_INCLUDES}"
)
target_link_libraries(libavrdude
PUBLIC
${LIB_MATH}
${LIB_LIBELF}
${LIB_LIBUSB}
${LIB_LIBUSB_1_0}
${LIB_LIBHID}
2021-12-20 16:50:42 +00:00
${LIB_LIBHIDAPI}
${LIB_LIBFTDI}
${LIB_LIBFTDI1}
${LIB_LIBREADLINE}
${EXTRA_WINDOWS_LIBRARIES}
)
add_executable(avrdude
main.c
term.c
term.h
avrintel.c
avrintel.h
developer_opts.c
developer_opts.h
developer_opts_private.h
whereami.c
whereami.h
"${EXTRA_WINDOWS_RESOURCES}"
2021-12-20 16:50:42 +00:00
)
target_link_libraries(avrdude PUBLIC libavrdude)
# =====================================
# Install
# =====================================
install(TARGETS avrdude DESTINATION bin)
install(TARGETS libavrdude
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION include COMPONENT dev
)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/avrdude.conf" TYPE SYSCONF)
install(FILES "avrdude.1"
DESTINATION "${CMAKE_INSTALL_MANDIR}/man1"
)