Skip to content

Instantly share code, notes, and snippets.

@ahundt
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ahundt/8994671 to your computer and use it in GitHub Desktop.
Save ahundt/8994671 to your computer and use it in GitHub Desktop.
diff --git a/src/cmake/ProjectTools.cmake b/src/cmake/ProjectTools.cmake
index 718174a..cc93775 100644
--- a/src/cmake/ProjectTools.cmake
+++ b/src/cmake/ProjectTools.cmake
@@ -803,7 +803,15 @@ function (basis_configure_public_headers)
# considered include directories
basis_get_relative_path (INCLUDE_DIR "${PROJECT_SOURCE_DIR}" "${PROJECT_INCLUDE_DIR}")
set (INCLUDE_DIRS "${PROJECT_SOURCE_DIR}/${INCLUDE_DIR}")
-
+
+ get_cmake_property(_variableNames VARIABLES)
+ foreach (_variableName ${_variableNames})
+ if(NOT ${_variablename} STREQUAL BASIS_PROPERTIES_ON_TESTS_RE)
+ set(ALL_VARIABLES_COMMAND_LINE "${ALL_VARIABLES_COMMAND_LINE} -D ${_variableName}=\"${${_variableName}}\"\n")
+ endif()
+ endforeach()
+ message(STATUS "COMMON_ARGS:${COMMON_ARGS} ALL_VARIABLES_COMMAND_LINE:${ALL_VARIABLES_COMMAND_LINE}")
+
# --------------------------------------------------------------------------
# clean up last run before the error because a file was added/removed
file (REMOVE "${CMAKE_FILE}.tmp")
@@ -822,7 +830,7 @@ function (basis_configure_public_headers)
-D "PROJECT_INCLUDE_DIRS=${INCLUDE_DIRS}"
-D "BINARY_INCLUDE_DIR=${BINARY_INCLUDE_DIR}"
-D "EXTENSIONS=${EXTENSIONS}"
- -D "CACHE_FILE=${PROJECT_BINARY_DIR}/BasisCache.txt"
+ ${ALL_VARIABLES_COMMAND_LINE}
-D "CMAKE_FILE=${CMAKE_FILE}"
-P "${BASIS_MODULE_PATH}/ConfigureIncludeFiles.cmake"
RESULT_VARIABLE RT
@@ -946,7 +954,7 @@ function (basis_configure_public_headers)
-D "PROJECT_INCLUDE_DIRS=${INCLUDE_DIRS}"
-D "BINARY_INCLUDE_DIR=${BINARY_INCLUDE_DIR}"
-D "EXTENSIONS=${EXTENSIONS}"
- -D "CACHE_FILE=${PROJECT_BINARY_DIR}/BasisCache.txt"
+ ${ALL_VARIABLES_COMMAND_LINE}
-P "${BASIS_MODULE_PATH}/ConfigureIncludeFiles.cmake"
COMMAND "${CMAKE_COMMAND}" -E touch "${CMAKE_FILE}.updated"
DEPENDS ${PUBLIC_HEADERS}
@@ -1782,7 +1790,7 @@ macro (basis_project_impl)
# dump currently defined CMake variables such that these can be used to
# configure the .in public header and module files during the build step
- basis_dump_variables ("${PROJECT_BINARY_DIR}/BasisCache.txt")
+ #basis_dump_variables ("${PROJECT_BINARY_DIR}/BasisCache.txt")
basis_include_directories (BEFORE "${BINARY_INCLUDE_DIR}"
"${PROJECT_INCLUDE_DIR}"
"${PROJECT_CODE_DIRS}")
diff --git a/src/cmake/ProjectTools.cmake b/src/cmake/ProjectTools.cmake
index 718174a..ebb1ec5 100644
--- a/src/cmake/ProjectTools.cmake
+++ b/src/cmake/ProjectTools.cmake
@@ -1782,11 +1782,54 @@ macro (basis_project_impl)
# dump currently defined CMake variables such that these can be used to
# configure the .in public header and module files during the build step
- basis_dump_variables ("${PROJECT_BINARY_DIR}/BasisCache.txt")
+ #basis_dump_variables ("${PROJECT_BINARY_DIR}/BasisCache.txt")
basis_include_directories (BEFORE "${BINARY_INCLUDE_DIR}"
"${PROJECT_INCLUDE_DIR}"
"${PROJECT_CODE_DIRS}")
- basis_configure_public_headers ()
+
+
+ # ----------------------------------------------------------------------------
+ # configure header files
+ set (
+ EXTENSIONS
+ ".h"
+ ".hh"
+ ".hpp"
+ ".hxx"
+ ".inl"
+ ".txx"
+ ".inc"
+ )
+
+ # configure all .in files with substitution
+ set (CONFIGURED_HEADERS)
+ foreach (INCLUDE_DIR IN LISTS PROJECT_INCLUDE_DIRS)
+ set (PATTERN)
+ foreach (E IN LISTS EXTENSIONS)
+ list (APPEND PATTERN "${INCLUDE_DIR}/*${E}.in")
+ endforeach ()
+ file (GLOB_RECURSE FILES RELATIVE "${INCLUDE_DIR}" PROJECT_HEADER_EXTENSIONS)
+ foreach (HEADER IN LISTS FILES)
+ get_filename_component (SOURCE "${INCLUDE_DIR}/${HEADER}" ABSOLUTE)
+ configure_file ("${SOURCE}" "${BINARY_INCLUDE_DIR}/${HEADER}" @ONLY)
+ list (APPEND CONFIGURED_HEADERS "${SOURCE}")
+ endforeach ()
+
+ # configure all other files without substitution
+ set (PATTERN)
+ foreach (E IN LISTS EXTENSIONS)
+ list (APPEND PATTERN "${INCLUDE_DIR}/*${E}")
+ endforeach ()
+
+ file (GLOB_RECURSE FILES RELATIVE "${INCLUDE_DIR}" PROJECT_HEADER_EXTENSIONS)
+ foreach (HEADER IN LISTS FILES)
+ get_filename_component (SOURCE "${INCLUDE_DIR}/${HEADER}" ABSOLUTE)
+ configure_file ("${SOURCE}" "${BINARY_INCLUDE_DIR}/${HEADER}" COPYONLY)
+ list (APPEND CONFIGURED_HEADERS "${SOURCE}")
+ endforeach ()
+ endforeach ()
+
+ #basis_configure_public_headers ()
basis_configure_script_libraries ()
# --------------------------------------------------------------------------
@schuhschuh
Copy link

Have you checked the value of BASIS_PROPERTIES_ON_TESTS_RE ? As it is a regular expression, it may contain some escape sequences which may cause troubles on the command line.

I am not sure if it is a good idea to pass all those CMake variables as command arguments. That will be a pretty long command...

@ahundt
Copy link
Author

ahundt commented Feb 14, 2014

Yeah, I haven't checked but I expect that is the source of the problem.

Any alternative ideas are welcome, but going to disk is super slow at 1/2 second per module. We need to remove that step because we are creating a project that will currently have 130 modules and grow from there. ~1 full minute of config time would be far too much.

I also added a super simple version that just cuts all of this functionality out BASIS-trivialConfigPublicHeaderFiles.diff. There would still need to be some code cleanup before I commit, but it seems to work in the basic case. It would be a shame to still have all of the problems with deleted headers causing inconsistencies though.

@schuhschuh
Copy link

I think the second solution is the one we should prefer then. It's ok to leave the feature of configuring the header files during build time. It is anyway better practice to really just have a single config.h.in which then defines macros/constants with the configured values that can be used in all other source code.

Remove lines 44-55 from your second snippet. That was only needed to copy all header files, not just those with .in suffix. You really don't want to do that again. It will cause quite some troubles and frustration with the BASIS users.

It would be a shame to still have all of the problems with deleted headers causing inconsistencies though.

This was more of a problem while BASIS was yet copying just all header files. But you can still have the check run during build time. No need to configure the files during build time. Only for that step you need to know what the values of all the CMake variables was during configuration. You just need to add a custom command similar to CheckPublicHeaders.cmake and provide it with a list of header files that were configured/copied to the build tree. It's only purpose will be to check whether the corresponding input .h.in file still exists in the source tree. If not, it will remove the copy from the build tree. As you expect only a few number of .h.in files, you can pass the relative paths of these files easily via -D option to cmake.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment