More robust handling for installed headers
[alexxy/gromacs.git] / src / gromacs / CMakeLists.txt
index 0da72898c9dc76348c36e61d3ff7f5f96c1d28bc..deeca78c5816181aba81cf9c30fc280c904dbd0a 100644 (file)
 
 set(LIBGROMACS_SOURCES)
 
-function (gmx_install_headers DESTINATION)
+set_property(GLOBAL PROPERTY GMX_INSTALLED_HEADERS)
+
+function (gmx_install_headers)
     if (NOT GMX_BUILD_MDRUN_ONLY)
-        if (DESTINATION)
-            set(DESTINATION ${INCL_INSTALL_DIR}/gromacs/${DESTINATION})
+        file(RELATIVE_PATH _dest ${PROJECT_SOURCE_DIR}/src ${CMAKE_CURRENT_LIST_DIR})
+        install(FILES       ${ARGN}
+                DESTINATION "${INCL_INSTALL_DIR}/${_dest}"
+                COMPONENT   development)
+    endif()
+    foreach (_file ${ARGN})
+        if (IS_ABSOLUTE "${_file}")
+            set_property(GLOBAL APPEND PROPERTY GMX_INSTALLED_HEADERS ${_file})
         else()
-            set(DESTINATION ${INCL_INSTALL_DIR}/gromacs)
+            set_property(GLOBAL APPEND PROPERTY GMX_INSTALLED_HEADERS
+                         ${CMAKE_CURRENT_LIST_DIR}/${_file})
         endif()
-        install(FILES ${ARGN} DESTINATION ${DESTINATION} COMPONENT development)
-    endif()
+    endforeach()
 endfunction ()
 
+function (gmx_write_installed_header_list)
+    get_property(_list GLOBAL PROPERTY GMX_INSTALLED_HEADERS)
+    string(REPLACE ";" "\n" _list "${_list}")
+    # TODO: Make this only update the file timestamp if the contents actually change.
+    file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/installed-headers.txt "${_list}")
+endfunction()
+
 if(GMX_USE_TNG)
     option(GMX_EXTERNAL_TNG "Use external TNG instead of compiling the version shipped with GROMACS."
            OFF)
@@ -59,11 +74,6 @@ if(GMX_USE_TNG)
         include_directories(${TNG_IO_INCLUDE_DIRS})
     endif()
     if(NOT GMX_EXTERNAL_TNG)
-        # TNG wants zlib if it is available
-        find_package(ZLIB QUIET)
-        include(gmxTestZLib)
-        gmx_test_zlib(HAVE_ZLIB)
-
         include(${CMAKE_SOURCE_DIR}/src/external/tng_io/BuildTNG.cmake)
         tng_get_source_list(TNG_SOURCES TNG_IO_DEFINITIONS)
         list(APPEND LIBGROMACS_SOURCES ${TNG_SOURCES})
@@ -71,6 +81,7 @@ if(GMX_USE_TNG)
 
         if (HAVE_ZLIB)
             list(APPEND GMX_EXTRA_LIBRARIES ${ZLIB_LIBRARIES})
+            include_directories(${ZLIB_INCLUDE_DIRS})
         endif()
     endif()
 else()
@@ -81,6 +92,7 @@ endif()
 add_subdirectory(gmxlib)
 add_subdirectory(mdlib)
 add_subdirectory(gmxpreprocess)
+add_subdirectory(listed-forces)
 add_subdirectory(commandline)
 add_subdirectory(fft)
 add_subdirectory(linearalgebra)
@@ -120,16 +132,16 @@ list(APPEND LIBGROMACS_SOURCES ${GMXLIB_SOURCES} ${MDLIB_SOURCES})
 tmpi_get_source_list(THREAD_MPI_SOURCES ${CMAKE_SOURCE_DIR}/src/external/thread_mpi/src)
 list(APPEND LIBGROMACS_SOURCES ${THREAD_MPI_SOURCES})
 
-set(LIBGROMACS_HEADERS
+configure_file(version.h.cmakein version.h)
+gmx_install_headers(
     analysisdata.h
     commandline.h
     options.h
     selection.h
     trajectoryanalysis.h
-    utility.h)
-configure_file(version.h.cmakein version.h)
-gmx_install_headers("" ${LIBGROMACS_HEADERS})
-gmx_install_headers("" ${CMAKE_CURRENT_BINARY_DIR}/version.h)
+    utility.h
+    ${CMAKE_CURRENT_BINARY_DIR}/version.h
+    )
 
 # This code is here instead of utility/CMakeLists.txt, because CMake
 # custom commands and source file properties can only be set in the directory
@@ -145,7 +157,7 @@ list(APPEND LIBGROMACS_SOURCES ${GENERATED_VERSION_FILE})
 # apply gcc 4.4.x bug workaround
 if(GMX_USE_GCC44_BUG_WORKAROUND)
    include(gmxGCC44O3BugWorkaround)
-   gmx_apply_gcc44_bug_workaround("gmxlib/bondfree.c")
+   gmx_apply_gcc44_bug_workaround("listed-forces/bonded.cpp")
    gmx_apply_gcc44_bug_workaround("mdlib/force.c")
    gmx_apply_gcc44_bug_workaround("mdlib/constr.c")
 endif()
@@ -194,12 +206,16 @@ set_target_properties(libgromacs PROPERTIES
                       VERSION ${LIBRARY_VERSION}
                       COMPILE_FLAGS "${OpenMP_C_FLAGS}")
 
+gmx_write_installed_header_list()
+
 # Only install the library in mdrun-only mode if it is actually necessary
 # for the binary
 if (NOT GMX_BUILD_MDRUN_ONLY OR BUILD_SHARED_LIBS)
     install(TARGETS libgromacs
             EXPORT libgromacs
-            DESTINATION ${LIB_INSTALL_DIR}
+            LIBRARY DESTINATION ${LIB_INSTALL_DIR}
+            RUNTIME DESTINATION ${BIN_INSTALL_DIR}
+            ARCHIVE DESTINATION ${LIB_INSTALL_DIR}
             COMPONENT libraries)
 endif()