CMake: Fix dependency chain between avrdude.conf.in and avrdude.conf

This commit is contained in:
Marius Greuel
2022-09-04 16:19:01 +02:00
parent dab99c0823
commit 07ed4746be
3 changed files with 72 additions and 36 deletions

View File

@@ -81,31 +81,53 @@ else()
add_compile_options(-Wall) # -Wextra
endif()
# =====================================
# Setup default port names
# =====================================
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
# =====================================
macro(configure_option option)
if(${${option}})
string(REGEX REPLACE "(.*)@${option}_BEGIN@(.*)@${option}_END@(.*)" "\\1\\2\\3" conf_file "${conf_file}")
else()
string(REGEX REPLACE "(.*)@${option}_BEGIN@(.*)@${option}_END@(.*)" "\\1\\3" conf_file "${conf_file}")
endif()
endmacro()
file(READ avrdude.conf.in conf_file)
configure_option(HAVE_PARPORT)
configure_option(HAVE_LINUXGPIO)
configure_option(HAVE_LINUXSPI)
file(WRITE "${PROJECT_BINARY_DIR}/avrdude.conf.in" "${conf_file}")
configure_file(cmake_config.h.in ac_cfg.h)
configure_file("${PROJECT_BINARY_DIR}/avrdude.conf.in" avrdude.conf)
configure_file(avrdude.spec.in avrdude.spec)
if(WIN32)
configure_file(windows.rc.in windows.rc)
endif()
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)
# =====================================
# Project
# =====================================