cmake-basis/BASIS

Problem with .in files

howardjp opened this issue · 3 comments

I have a file in my include directory called "config.hpp.in" which should grab the variables from cmake and create a config.hpp. It seems like include files are skipped over for this in BASIS. Is this correct? Is there some switch in I need to hit somewhere to make it work?

CMake function basis_configure_sources() is called with a list of all source files that you specify with basis_add_executable() or basis_add_library() respectively. This function processes every source file with .in suffix (cf. this regex). CMake variables using the @ notation are substituted using CMake's configure_file() function as called here. This suggests it should do what you want. One question that comes to mind is, at which location are you expecting/looking for the configured config.hpp file? Generated files are written to the build directory. Have you checked there already?

Looking at how CONFIGURED_SOURCE path is set, I find this if condition suspicious:

"^${SOURCE}$" STREQUAL "^${PROJECT_SOURCE_DIR}$"

You could add a message("basis_configure_source(): CONFIGURED_SOURCE=${CONFIGURED_SOURCE}") just before the call to configure_file() in above linked function to see where it is currently written to (if at all).

But it seems even if aforementioned if condition is wrong (I guess it will never be fulfilled?), the else branch sets:

get_filename_component (SOURCE_NAME "${SOURCE}" NAME)
if (NOT ARGN_KEEP_DOT_IN_SUFFIX)
  string (REGEX REPLACE "\\.in$" "" SOURCE_NAME "${SOURCE_NAME}")
endif ()
set (CONFIGURED_SOURCE "${CMAKE_CURRENT_BINARY_DIR}/${SOURCE_NAME}")

Which means the generated file should be in the build directory corresponding to the current source directory containing the CMakeLists.txt file in which you call basis_add_executable() or basis_add_library().

Thank you for the ideas here. I will say I never got around to trying them as I moved away from using BASIS.