configure_file not creating file prior to build after a build clean
I am currently using cmake version 3.23.1. I am using the Eclipse environment with esp-idf plugin for ESP32 development.
I am using configure_file
to generate a simple header file containing the current project name and version for my project. This file is included in two of my source files.
If I start with a new build without an existing build directory, this works fine. configure_file
generates the include file before the build process tries to compile the source files and the build is successful.
If I then just do a "build clean" in Eclipse, the build directory isn't completely erased but some select files are removed. In particular, the generated header file is removed. If I attempt to do a build after the "build clean" it results in an error trying to compile the source since it now cannot find the header file since it hasn't been generated prior to the compilation step.
Any ideas on why this is occurring? I've read several descriptions online and a detailed section in a cmake book on how configure_file
works, and looked at countless examples. They're all basically the same and mine follows that pattern. So I'm not sure what I'm doing wrong.
cmake_minimum_required(VERSION 3.16.0)
cmake_policy(SET CMP0076 NEW)
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include ${CMAKE_CURRENT_BINARY_DIR})
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
project(BD-OTB)
set(PROJECT_VERSION "1.0.1")
set(PROJECT_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include)
set(GENERATED_INCLUDE_DIR ${CMAKE_CURRENT_BINARY_DIR})
configure_file(
${PROJECT_INCLUDE_DIR}/Application.hpp.in
${GENERATED_INCLUDE_DIR}/Application.hpp)
add_custom_target(gen_h DEPENDS
${GENERATED_INCLUDE_DIR}/Application.hpp
${PROJECT_INCLUDE_DIR}/Application.hpp.in)
set_property(TARGET ${PROJECT_NAME}.elf APPEND
PROPERTY ADDITIONAL_CLEAN_FILES ${GENERATED_INCLUDE_DIR}/Application.hpp)
add_dependencies(${PROJECT_NAME}.elf gen_h)