From 2f3cbfed1304d9c263ed52698fa2ea263f776a40 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 10 Nov 2020 17:58:26 -0500 Subject: [PATCH 1/3] add CMake code to download and compile libyaml if not found locally --- cmake/Modules/YAML.cmake | 32 ++++++++++++++++++++++++++++ unittest/force-styles/CMakeLists.txt | 4 ++-- 2 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 cmake/Modules/YAML.cmake diff --git a/cmake/Modules/YAML.cmake b/cmake/Modules/YAML.cmake new file mode 100644 index 0000000000..05163675df --- /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/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) From 2c6ccf0d0f0da1b63221dc34f34457c3480c8223 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 10 Nov 2020 18:04:00 -0500 Subject: [PATCH 2/3] update docs for download and compilation of yaml sources --- doc/src/Build_development.rst | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) 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. From 552dc7fba90af230c811abaedd96f180e95a2f02 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 10 Nov 2020 18:05:06 -0500 Subject: [PATCH 3/3] whitespace --- cmake/Modules/YAML.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/Modules/YAML.cmake b/cmake/Modules/YAML.cmake index 05163675df..a080b566be 100644 --- a/cmake/Modules/YAML.cmake +++ b/cmake/Modules/YAML.cmake @@ -5,7 +5,7 @@ set(YAML_URL "https://pyyaml.org/download/libyaml/yaml-0.2.5.tar.gz" CACHE STRIN mark_as_advanced(YAML_URL) ExternalProject_Add(libyaml URL ${YAML_URL} - URL_MD5 bb15429d8fb787e7d3f1c83ae129a999 + URL_MD5 bb15429d8fb787e7d3f1c83ae129a999 SOURCE_DIR "${CMAKE_BINARY_DIR}/yaml-src" BINARY_DIR "${CMAKE_BINARY_DIR}/yaml-build" CONFIGURE_COMMAND /configure ${CONFIGURE_REQUEST_PIC}