Skip to content

CMake guild for QMCPACK developers

Ye Luo edited this page Jun 6, 2020 · 5 revisions

Refactor goal

Transit to modern CMake with clean organization.

knowledge base

Compiler

For a command line, gcc -g -O3 -o abc.x -DENABLE_ABC -DNX=1 -I/libhdf5/include a.cpp b.cpp c.cpp -L/libhdf5 -lhdf5

segments attribute
-g -O3 -o abc.x COMPILE_OPTIONS
-DENABLE_ABC -DNX=1 COMPILE_DEFINITIONS
-I/libhdf5/include INCLUDE_DIRECTORIES
a.cpp b.cpp c.cpp target source files
-L/libhdf5 -lhdf5 libraies. should be defined as targets.

target properties

private/interface/public property attibute

private: used for compiling this target only

interface: used for compiling other targets depend on this target but not used inside this target.

public = private + public

Folders

src/Platforms
    Message
    Utilities
    Containters
    Particles
    QMCWavefunctions
    QMCHamiltonians
    QMCDrivers
    QMCApp

each top level folder is a target as self contained as possible to reduce entanglements. This is beneficial for unit testing as well.

SET(DEVICE_SRCS
    accelerators.cpp
)
ADD_LIBRARY(platform_device ${DEVICE_SRCS})
TARGET_INCLUDE_DIRECTORIES(platform_device INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}")
#provide -I src/Platforms to consumer outside Platforms

SUBDIRS(OpenMP)
TARGET_LINK_LIBRARIES(platform_device PRIVATE platform_omp)
#provide only -lplatform_omp but no INCLUDE_DIRECTORIES and COMPILE_DEFINITIONS propagation.

How to include a header file from a "src/folder" which is not an ancestor of the current folder?

We should avoid reference files based on src. For example, NonLocalECPComponent.h under QMCHamiltonians includes TrialWaveFunction.h from the QMCWaveFunctions folder. The old way writes <QMCWaveFunctions/TrialWaveFunction.h> which bypasses the dependency.

Instead, QMCHamiltonians folder is represented by the qmcham target and QMCWaveFunctions folder is represented by the qmcwfs target. The qmcham target dependency on qmcwfs has been expressed in CMake. In the new way, we should only do #include <TrialWaveFunction.h> instead of <QMCWaveFunctions/TrialWaveFunction.h>. The dependency and include link path are fully handled by CMake. Consider each target is a library. When including a header file from a target different from what the current file belongs to use <> instead of ""