cmake-basis / BASIS

CMake BASIS makes it easy to create sharable software and libraries that work together. This is accomplished by combining and documenting some of the best practices and utilities available. This project supplies a fully integrated suite of functionality to make the whole process seamless!
https://cmake-basis.github.io
Other
48 stars 10 forks source link

Problem with .in files #638

Closed howardjp closed 2 years ago

howardjp commented 4 years ago

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?

schuhschuh commented 4 years ago

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?

schuhschuh commented 4 years ago

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().

howardjp commented 4 years ago

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