Add -DCOLVARS_LEPTON, track user's choice via DISABLE_CXX11_REQUIREMENT

This commit is contained in:
Giacomo Fiorin 2019-10-16 08:35:37 -04:00
parent b6af3c7ad0
commit 2c9ae7ab4b
1 changed files with 23 additions and 9 deletions

View File

@ -4,22 +4,36 @@ if(PKG_USER-COLVARS)
file(GLOB COLVARS_SOURCES ${COLVARS_SOURCE_DIR}/[^.]*.cpp)
if(DEFINED CMAKE_CXX_STANDARD)
# The condition below should match most modern C++ standards
if((${CMAKE_CXX_STANDARD} GREATER 0) AND (${CMAKE_CXX_STANDARD} LESS 70))
set(ENABLE_LEPTON ON)
set(LEPTON_DIR ${LAMMPS_LIB_SOURCE_DIR}/colvars/lepton)
file(GLOB LEPTON_SOURCES ${LEPTON_DIR}/src/[^.]*.cpp)
add_library(lepton STATIC ${LEPTON_SOURCES})
target_include_directories(lepton PRIVATE ${LEPTON_DIR}/include)
# Build Lepton by default
set(COLVARS_LEPTON_DEFAULT ON)
# but not if C++11 is disabled per user request
if(DEFINED DISABLE_CXX11_REQUIREMENT)
if(DISABLE_CXX11_REQUIREMENT)
set(COLVARS_LEPTON_DEFAULT OFF)
endif()
endif()
option(COLVARS_LEPTON "Build and link the Lepton library" ${COLVARS_LEPTON_DEFAULT})
# Verify that the user's choice is consistent
if(DEFINED DISABLE_CXX11_REQUIREMENT)
if((DISABLE_CXX11_REQUIREMENT) AND (COLVARS_LEPTON))
message(FATAL_ERROR "Building the Lepton library requires C++11 or later.")
endif()
endif()
if(COLVARS_LEPTON)
set(LEPTON_DIR ${LAMMPS_LIB_SOURCE_DIR}/colvars/lepton)
file(GLOB LEPTON_SOURCES ${LEPTON_DIR}/src/[^.]*.cpp)
add_library(lepton STATIC ${LEPTON_SOURCES})
target_include_directories(lepton PRIVATE ${LEPTON_DIR}/include)
endif()
add_library(colvars STATIC ${COLVARS_SOURCES})
target_include_directories(colvars PUBLIC ${LAMMPS_LIB_SOURCE_DIR}/colvars)
list(APPEND LAMMPS_LINK_LIBS colvars)
if(ENABLE_LEPTON)
if(COLVARS_LEPTON)
list(APPEND LAMMPS_LINK_LIBS lepton)
target_compile_options(colvars PRIVATE -DLEPTON)
target_include_directories(colvars PUBLIC ${LEPTON_DIR}/include)