65 lines
2.6 KiB
CMake
65 lines
2.6 KiB
CMake
find_package(GSL REQUIRED)
|
|
find_package(MSCG QUIET)
|
|
if(MSGC_FOUND)
|
|
set(DOWNLOAD_MSCG_DEFAULT OFF)
|
|
else()
|
|
set(DOWNLOAD_MSCG_DEFAULT ON)
|
|
endif()
|
|
option(DOWNLOAD_MSCG "Download MSCG library instead of using an already installed one)" ${DOWNLOAD_MSCG_DEFAULT})
|
|
if(DOWNLOAD_MSCG)
|
|
set(MSCG_URL "https://github.com/uchicago-voth/MSCG-release/archive/1.7.3.1.tar.gz" CACHE STRING "URL for MSCG tarball")
|
|
set(MSCG_MD5 "8c45e269ee13f60b303edd7823866a91" CACHE STRING "MD5 checksum of MSCG tarball")
|
|
mark_as_advanced(MSCG_URL)
|
|
mark_as_advanced(MSCG_MD5)
|
|
|
|
# always compile a static lib but with position independent code
|
|
# make a copy of current settings for later use
|
|
set(OLD_SHARED_LIBS ${BUILD_SHARED_LIBS})
|
|
set(OLD_POSITION_INDEPENDENT_CODE ${CMAKE_POSITION_INDEPENDENT_CODE})
|
|
set(BUILD_SHARED_LIBS OFF)
|
|
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
|
|
|
|
if(CMAKE_VERSION VERSION_LESS 3.14)
|
|
file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/_deps)
|
|
file(DOWNLOAD ${MSCG_URL} ${CMAKE_BINARY_DIR}/_deps/mscg.tar.gz EXPECTED_HASH MD5=${MSCG_MD5})
|
|
execute_process(COMMAND ${CMAKE_COMMAND} -E tar xzf ${CMAKE_BINARY_DIR}/_deps/mscg.tar.gz
|
|
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/_deps)
|
|
|
|
file(GLOB MSCG_SOURCE "${CMAKE_BINARY_DIR}/_deps/MSCG-release-*")
|
|
# sanity check. do not allow to have multiple downloaded and extracted versions of the source
|
|
list(LENGTH MSCG_SOURCE _num)
|
|
if(_num GREATER 1)
|
|
message(FATAL_ERROR "Inconsistent MSCG library sources. Please delete ${CMAKE_BINARY_DIR}/_deps and re-run cmake")
|
|
endif()
|
|
add_subdirectory(${MSCG_SOURCE}/src/CMake ${CMAKE_BINARY_DIR}/_deps/mscg-build)
|
|
else()
|
|
include(FetchContent)
|
|
FetchContent_Declare(mscg URL ${MSCG_URL} URL_HASH MD5=${MSCG_MD5} SOURCE_SUBDIR src/CMake)
|
|
FetchContent_MakeAvailable(mscg)
|
|
set(MSCG_SOURCE ${CMAKE_BINARY_DIR}/_deps/mscg-src)
|
|
endif()
|
|
|
|
# restore previous settings
|
|
if(OLD_POSITION_INDEPENDENT_CODE)
|
|
set(CMAKE_POSITON_INDEPENDENT_CODE ${OLD_POSITION_INDEPENDENT_CODE})
|
|
else()
|
|
unset(CMAKE_POSITION_INDEPENDENT_CODE)
|
|
endif()
|
|
if (OLD_SHARED_LIBS)
|
|
set(BUILD_SHARED_LIBS ${OLD_SHARED_LIBS})
|
|
else()
|
|
unset(BUILD_SHARED_LIBS)
|
|
endif()
|
|
|
|
# set include and link library
|
|
target_include_directories(lammps PRIVATE "${MSCG_SOURCE}/src")
|
|
target_link_libraries(lammps PRIVATE mscg)
|
|
else()
|
|
find_package(MSCG)
|
|
if(NOT MSCG_FOUND)
|
|
message(FATAL_ERROR "MSCG not found, help CMake to find it by setting MSCG_LIBRARY and MSCG_INCLUDE_DIR, or set DOWNLOAD_MSCG=ON to download it")
|
|
endif()
|
|
target_link_libraries(lammps PRIVATE MSCG::MSCG)
|
|
endif()
|
|
target_link_libraries(lammps PRIVATE GSL::gsl ${LAPACK_LIBRARIES})
|