Merge branch 'origin/release-2020' into master
[alexxy/gromacs.git] / src / CMakeLists.txt
index 820e83c108255f1aa002ddb45bca9b0940c2d069..4d75aabea445d73d8c4af593adbd60761d3ffe73 100644 (file)
@@ -48,10 +48,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
@@ -155,3 +151,21 @@ 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)
+
+set(CMAKE_BUILD_CONFIGURATION_C_FLAGS   ${CMAKE_C_FLAGS_${CMAKE_BUILD_TYPE_UPPER}})
+set(CMAKE_BUILD_CONFIGURATION_CXX_FLAGS ${CMAKE_CXX_FLAGS_${CMAKE_BUILD_TYPE_UPPER}})
+configure_file(buildinfo.h.cmakein buildinfo.h ESCAPE_QUOTES)