diff --git a/cmake/Modules/YAML.cmake b/cmake/Modules/YAML.cmake new file mode 100644 index 0000000000..a080b566be --- /dev/null +++ b/cmake/Modules/YAML.cmake @@ -0,0 +1,32 @@ +message(STATUS "Downloading and building YAML library") + +include(ExternalProject) +set(YAML_URL "https://pyyaml.org/download/libyaml/yaml-0.2.5.tar.gz" CACHE STRING "URL for libyaml tarball") +mark_as_advanced(YAML_URL) +ExternalProject_Add(libyaml + URL ${YAML_URL} + URL_MD5 bb15429d8fb787e7d3f1c83ae129a999 + SOURCE_DIR "${CMAKE_BINARY_DIR}/yaml-src" + BINARY_DIR "${CMAKE_BINARY_DIR}/yaml-build" + CONFIGURE_COMMAND /configure ${CONFIGURE_REQUEST_PIC} + CXX=${CMAKE_CXX_COMPILER} + CC=${CMAKE_C_COMPILER} + --prefix= --disable-shared + BUILD_BYPRODUCTS /lib/${CMAKE_FIND_LIBRARY_PREFIXES}yaml.a + TEST_COMMAND "") + +ExternalProject_Get_Property(libyaml INSTALL_DIR) +set(YAML_INCLUDE_DIR ${INSTALL_DIR}/include) +set(YAML_LIBRARY_DIR ${INSTALL_DIR}/lib) + +# workaround for CMake 3.10 on ubuntu 18.04 +file(MAKE_DIRECTORY ${YAML_INCLUDE_DIR}) +file(MAKE_DIRECTORY ${YAML_LIBRARY_DIR}) + +set(YAML_LIBRARY_PATH ${INSTALL_DIR}/lib/${CMAKE_FIND_LIBRARY_PREFIXES}yaml.a) + +add_library(Yaml::Yaml UNKNOWN IMPORTED) +set_target_properties(Yaml::Yaml PROPERTIES + IMPORTED_LOCATION ${YAML_LIBRARY_PATH} + INTERFACE_INCLUDE_DIRECTORIES ${YAML_INCLUDE_DIR}) +add_dependencies(Yaml::Yaml libyaml) diff --git a/doc/src/Build_development.rst b/doc/src/Build_development.rst index cf3e2fb750..1b076caac0 100644 --- a/doc/src/Build_development.rst +++ b/doc/src/Build_development.rst @@ -111,8 +111,10 @@ error margin). The status of this automated testing can be viewed on The unit testing facility is integrated into the CMake build process of the LAMMPS source code distribution itself. It can be enabled by setting ``-D ENABLE_TESTING=on`` during the CMake configuration step. -It requires the `PyYAML `_ library and development -headers to compile and will download and compile a recent version of the +It requires the `YAML `_ library and development +headers (if not found locally a recent version will be downloaded +and compiled transparently) to compile and will download and compile +a specific recent version of the `Googletest `_ C++ test framework for implementing the tests. diff --git a/unittest/force-styles/CMakeLists.txt b/unittest/force-styles/CMakeLists.txt index 128dc62cff..1d7dc937eb 100644 --- a/unittest/force-styles/CMakeLists.txt +++ b/unittest/force-styles/CMakeLists.txt @@ -1,8 +1,8 @@ find_package(YAML) if(NOT YAML_FOUND) - message(STATUS "Skipping tests because libyaml is not found") - return() + # download and build a local copy of libyaml + include(YAML) endif() if(CMAKE_VERSION VERSION_LESS 3.12)