Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor CMake configuration #1502

Merged
merged 14 commits into from Jun 11, 2019

Conversation

Projects
None yet
3 participants
@rbberger
Copy link
Member

commented Jun 9, 2019

Summary

This is an effort to refactor the CMake configuration by moving code from the main configuration file into utility functions and include files.

Over time this main file has grown to almost 2000 lines, up to the point where it is hard to see what it is actually doing, even for people who originally worked on it. This brings it back down to about 720 lines.
A large chunk of package configurations is now placed in cmake/Modules/Packages/*.cmake files.

Not perfect, it's still a beast, but hopefully a step in the right direction.

Author(s)

@rbberger (Temple U)

Licensing

By submitting this pull request, I agree, that my contribution will be included in LAMMPS and redistributed under either the GNU General Public License version 2 (GPL v2) or the GNU Lesser General Public License version 2.1 (LGPL v2.1).

Backward Compatibility

Yes

Post Submission Checklist

Please check the fields below as they are completed after the pull request has been submitted. Delete lines that don't apply

  • The feature or features in this pull request is complete
  • Licensing information is complete
  • Corresponding author information is complete
  • The source code follows the LAMMPS formatting guidelines
  • Suitable new documentation files and/or updates to the existing docs are included
  • The added/updated documentation is integrated and tested with the documentation build system
  • The feature has been verified to work with the conventional build system
  • The feature has been verified to work with the CMake based build system
  • A package specific README file has been included or updated
  • One or more example input decks are included

Further Information, Files, and Links

Put any additional information here, attach relevant text or image files, and URLs to external sites (e.g. DOIs or webpages)

rbberger added some commits Jun 7, 2019

Create CMake files for several packages
This remove the CMake configuration of several larger packages and places
it into their own files in the Modules/Packages folder.
 - COMPRESS
 - KIM
 - LATTE
 - MESSAGE
 - MSCG
 - USER-MOLFILE
 - USER-NETCDF
 - USER-PLUMED
 - USER-QMMM
 - USER-QUIP
 - USER-SCAFACOS
 - USER-SMD
 - USER-VTK
@junghans

This comment has been minimized.

Copy link
Member

commented Jun 9, 2019

Is there a reason you didn't move

lammps/cmake/CMakeLists.txt

Lines 230 to 287 in e788d32

if(PKG_KSPACE)
option(FFT_SINGLE "Use single precision FFT instead of double" OFF)
set(FFTW "FFTW3")
if(FFT_SINGLE)
set(FFTW "FFTW3F")
add_definitions(-DFFT_SINGLE)
endif()
find_package(${FFTW} QUIET)
if(${FFTW}_FOUND)
set(FFT "${FFTW}" CACHE STRING "FFT library for KSPACE package")
else()
set(FFT "KISS" CACHE STRING "FFT library for KSPACE package")
endif()
set(FFT_VALUES KISS ${FFTW} MKL)
set_property(CACHE FFT PROPERTY STRINGS ${FFT_VALUES})
validate_option(FFT FFT_VALUES)
string(TOUPPER ${FFT} FFT)
if(NOT FFT STREQUAL "KISS")
find_package(${FFT} REQUIRED)
if(NOT FFT STREQUAL "FFTW3F")
add_definitions(-DFFT_FFTW)
else()
add_definitions(-DFFT_${FFT})
endif()
include_directories(${${FFT}_INCLUDE_DIRS})
list(APPEND LAMMPS_LINK_LIBS ${${FFT}_LIBRARIES})
else()
add_definitions(-DFFT_KISS)
endif()
set(FFT_PACK "array" CACHE STRING "Optimization for FFT")
set(FFT_PACK_VALUES array pointer memcpy)
set_property(CACHE FFT_PACK PROPERTY STRINGS ${FFT_PACK_VALUES})
validate_option(FFT_PACK FFT_PACK_VALUES)
if(NOT FFT_PACK STREQUAL "array")
string(TOUPPER ${FFT_PACK} FFT_PACK)
add_definitions(-DFFT_PACK_${FFT_PACK})
endif()
endif()
if(PKG_MSCG OR PKG_USER-ATC OR PKG_USER-AWPMD OR PKG_USER-PLUMED OR PKG_USER-QUIP OR PKG_LATTE)
find_package(LAPACK)
find_package(BLAS)
if(NOT LAPACK_FOUND OR NOT BLAS_FOUND)
enable_language(Fortran)
file(GLOB LAPACK_SOURCES ${LAMMPS_LIB_SOURCE_DIR}/linalg/[^.]*.[fF])
add_library(linalg STATIC ${LAPACK_SOURCES})
set(LAPACK_LIBRARIES linalg)
else()
list(APPEND LAPACK_LIBRARIES ${BLAS_LIBRARIES})
endif()
endif()
if(PKG_PYTHON)
find_package(PythonLibs REQUIRED)
add_definitions(-DLMP_PYTHON)
include_directories(${PYTHON_INCLUDE_DIR})
list(APPEND LAMMPS_LINK_LIBS ${PYTHON_LIBRARY})
endif()

and

lammps/cmake/CMakeLists.txt

Lines 464 to 480 in e788d32

if(PKG_USER-AWPMD)
target_link_libraries(awpmd ${LAPACK_LIBRARIES})
endif()
if(PKG_USER-ATC)
if(LAMMPS_SIZES STREQUAL BIGBIG)
message(FATAL_ERROR "The USER-ATC Package is not compatible with -DLAMMPS_BIGBIG")
endif()
target_link_libraries(atc ${LAPACK_LIBRARIES})
endif()
if(PKG_USER-H5MD)
find_package(HDF5 REQUIRED)
target_link_libraries(h5md ${HDF5_LIBRARIES})
target_include_directories(h5md PRIVATE ${HDF5_INCLUDE_DIRS})
include_directories(${HDF5_INCLUDE_DIRS})
endif()

to separate files?

However if we are going to create one file per package, it might be better to just put a CMakeLists.txt in each package directory, which is more the CMake standard.

@rbberger

This comment has been minimized.

Copy link
Member Author

commented Jun 9, 2019

@junghans no reason, just didn't get to it yet. I wanted to get some feedback.

I'll experiment with your suggestion of moving the CMakeLists.txt to each package folder. The primary reason I did it this way is to preserve the variable scopes and keep stuff in the cmake folder. I'll need to see the pro and cons.

@akohlmey

This comment has been minimized.

Copy link
Member

commented Jun 9, 2019

I'll experiment with your suggestion of moving the CMakeLists.txt to each package folder. The primary reason I did it this way is to preserve the variable scopes and keep stuff in the cmake folder. I'll need to see the pro and cons.

don't think it is such a good idea to move cmake files into package folders. it will just needlessly scatter them. it is not like we have a hierarchical build where the build is recursing through folders to do independent builds in each of them. instead we have one "flat" build for the LAMMPS executable. it seems much more logical to me to keep all files for that in the cmake folder or a subfolder.

@junghans

This comment has been minimized.

Copy link
Member

commented Jun 9, 2019

I'll experiment with your suggestion of moving the CMakeLists.txt to each package folder. The primary reason I did it this way is to preserve the variable scopes and keep stuff in the cmake folder. I'll need to see the pro and cons.

don't think it is such a good idea to move cmake files into package folders. it will just needlessly scatter them. it is not like we have a hierarchical build where the build is recursing through folders to do independent builds in each of them. instead we have one "flat" build for the LAMMPS executable. it seems much more logical to me to keep all files for that in the cmake folder or a subfolder.

If we don't have a fully all-in-one CMakeLists.txt anyhow, I honestly think more naturally to have the CMakeLists.txt next to the Makefile, instead of hidden away in the cmake/ folder, so that changes can be directly compared.

In retrospective we should create the lammps target first and just add packages to it with target_sources and target_link_libraries would be rid of a lot of issues, however that would need at least cmake-3.

@akohlmey

This comment has been minimized.

Copy link
Member

commented Jun 9, 2019

If we don't have a fully all-in-one CMakeLists.txt anyhow, I honestly think more naturally to have the CMakeLists.txt next to the Makefile, instead of hidden away in the cmake/ folder, so that changes can be directly compared.

this goes contrary to my experience with the various Install.py files in the lib tree. it has become a bit of a nightmare to keep them all consistent and avoid duplicated or non uniform code, especially when other developers, that maintain packages and their libraries, make changes to them, that are not consistent, since they only look at the folder that they consider themselves responsible for.

need to use C++ compiler when checking for includes
this is the same bugfix as in PR #1504

@akohlmey akohlmey self-assigned this Jun 11, 2019

@akohlmey akohlmey merged commit 42b0cb5 into lammps:master Jun 11, 2019

6 checks passed

lammps/pull-requests/build-docs-pr head run ended
Details
lammps/pull-requests/cmake/cmake-serial-pr head run ended
Details
lammps/pull-requests/kokkos-omp-pr head run ended
Details
lammps/pull-requests/openmpi-pr head run ended
Details
lammps/pull-requests/serial-pr head run ended
Details
lammps/pull-requests/shlib-pr head run ended
Details

@rbberger rbberger deleted the rbberger:cmake_cleanup branch Jun 27, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.