Move configuration of global headers
authorMark Abraham <mark.j.abraham@gmail.com>
Sat, 25 Apr 2020 14:11:50 +0000 (16:11 +0200)
committerMark Abraham <mark.j.abraham@gmail.com>
Sat, 25 Apr 2020 16:45:33 +0000 (18:45 +0200)
Previously it was possible to get a different result from
  cmake .. && make && make install
than one got from
  cmake .. && cmake .. && make && make install
because the lmfit detection ran after config.h was generated,
so HAVE_LMFIT changed value from one cmake to the next, triggering
a rebuild of all source files that depended on config.h. lmfit
is supposed to fall back on the internal version, but did not,
so this is buggy. It's also very inefficient with compilation
in some workflows.

src/CMakeLists.txt

index 64506cbae169c33dd1bde7d223040baa7b457127..70989f38152dd809296f51af610a2bfc3e9eb18d 100644 (file)
@@ -46,10 +46,6 @@ if(GMX_USE_CUDA)
     get_cuda_compiler_info(CUDA_COMPILER_INFO CUDA_DEVICE_COMPILER_FLAGS CUDA_HOST_COMPILER_FLAGS)
 endif()
 
-string(TOUPPER "${CMAKE_BUILD_TYPE}" CMAKE_BUILD_TYPE_UPPER)
-configure_file(config.h.cmakein config.h)
-configure_file(gmxpre-config.h.cmakein gmxpre-config.h)
-configure_file(buildinfo.h.cmakein buildinfo.h ESCAPE_QUOTES)
 # Make a file with compiler flags used for libgromacs for each
 # langauge and build configuration.  The one that corresponds to
 # CMAKE_BUILD_TYPE is #included into buildinfo.h and populates the
@@ -149,3 +145,18 @@ if (GMXAPI)
    endif()
    add_subdirectory(api)
 endif()
+
+# Configure header files with configuration-specific values. This step
+# should follow all introspection e.g. looking for headers and
+# libraries. If not, cmake will need to change the contents of the
+# file upon subsequent runs of cmake. This can mean that
+#
+#  cmake $src && make && make test
+#
+# requires building all the source files that depend on the changed
+# header file in both of the make stages. That's slow, and is useless
+# busy work for ccache, too.
+string(TOUPPER "${CMAKE_BUILD_TYPE}" CMAKE_BUILD_TYPE_UPPER)
+configure_file(config.h.cmakein config.h)
+configure_file(gmxpre-config.h.cmakein gmxpre-config.h)
+configure_file(buildinfo.h.cmakein buildinfo.h ESCAPE_QUOTES)