diff --git a/.gitmodules b/.gitmodules index e95352252a2..9b6b544e317 100644 --- a/.gitmodules +++ b/.gitmodules @@ -7,6 +7,3 @@ [submodule "ThirdParty/bilke/cmake-modules"] path = ThirdParty/bilke/cmake-modules url = https://github.com/bilke/cmake-modules.git -[submodule "ThirdParty/collection"] - path = ThirdParty/collection - url = https://gitlab.opengeosys.org/ogs/libs/collection.git diff --git a/.guix/modules/ogs-package.scm b/.guix/modules/ogs-package.scm index 301be17a508..d26ba243da1 100644 --- a/.guix/modules/ogs-package.scm +++ b/.guix/modules/ogs-package.scm @@ -19,6 +19,7 @@ #:use-module (guix) #:use-module (guix packages) #:use-module (guix build-system cmake) + #:use-module (guix build-system copy) #:use-module (guix download) #:use-module (guix git-download) #:use-module ((guix licenses) #:prefix license:) @@ -44,7 +45,7 @@ (define vcs-file? ;; Return true if the given file is under version control. (or (git-predicate "../..") ; (current-source-directory) - (const #t))) ;not in a Git checkout + (const #t))) ; not in a Git checkout (define-public ogs (package @@ -70,8 +71,9 @@ #:cmake ,cmake)) ;for newer CMake version (inputs (list boost eigen - googletest + exprtk hdf5 + iphreeqc json-modern-cxx libxml2 metis @@ -79,9 +81,12 @@ python range-v3 spdlog + tclap + tetgen zlib - vtk)) - (native-inputs (list git ninja googletest nss-certs)) ; TODO: cpm + vtk + xmlpatch)) + (native-inputs (list git ninja nss-certs)) ; TODO: cpm (synopsis "OpenGeoSys") (description "Simulation of thermo-hydro-mechanical-chemical (THMC) processes in porous and fractured media") @@ -192,6 +197,113 @@ (sha256 (base32 "0rbcfvl7y472sykzdq3vrkw83kar0lpzhk3wq9yj9cdydl8cpfcz")))))) + +(define tetgen + (package + (name "tetgen") + (synopsis "A Quality Tetrahedral Mesh Generator and a 3D Delaunay Triangulator") + (license license:agpl3) + (description "TetGen is a program to generate tetrahedral meshes of any 3D polyhedral domains. TetGen generates exact constrained Delaunay tetrahedralizations, boundary conforming Delaunay meshes, and Voronoi partitions.") + (home-page "http://www.tetgen.org/") + (version "1.5.1-1") + (source (origin + (method git-fetch) + (uri (git-reference + (url "https://github.com/ufz/tetgen") + (commit version))) + (sha256 + (base32 + "1xp1qibm0q4z5qx0h178qpas3n7pqbladkxdalq9j4l98hdws46j")))) + (build-system cmake-build-system) + (arguments + `(#:tests? #f) + ))) + +(define tclap + (package + (name "tclap") + (synopsis "Templatized Command Line Argument Parser") + (license license:expat) + (description "This is a simple C++ library that facilitates parsing command line arguments in a type independent manner.") + (home-page "https://sourceforge.net/p/tclap/discussion/") + (version "1.2.4-1") + (source (origin + (method git-fetch) + (uri (git-reference + (url "https://github.com/ufz/tclap") + (commit version))) + (sha256 + (base32 + "0bijzfc9c8zny3m74y53i8m3f41kd8klcnmr9chy536syr9vdr5p")))) + (build-system cmake-build-system) + (arguments + `(#:tests? #f) + ))) + +(define iphreeqc + (package + (name "iphreeqc") + (synopsis "Modules Based on the Geochemical Model PHREEQC for use in scripting and programming languages") + (license license:public-domain) + (description "") + (home-page "https://www.usgs.gov/software/phreeqc-version-3") + (version "3.5.0-1") + (source (origin + (method git-fetch) + (uri (git-reference + (url "https://github.com/ufz/iphreeqc") + (commit version))) + (sha256 + (base32 + "1liwp6hkl2dbrl8bki9gzsw77s3prv12sdikmwz5h8ffxwdrnwli")))) + (build-system cmake-build-system) + (arguments + `(#:tests? #f) + ))) + +(define xmlpatch + (package + (name "xmlpatch") + (synopsis "An XML Patch library") + (license license:lgpl2.1) + (description "") + (home-page "https://xmlpatch.sourceforge.net") + (version "0.4.3") + (source (origin + (method git-fetch) + (uri (git-reference + (url "https://gitlab.opengeosys.org/ogs/libs/xmlpatch") + (commit (string-append "v" version)))) + (sha256 + (base32 + "0872g9w1jd5r4c5a1s8ga4x1plg608b7rxyqjs6zv8ghjq9qlkvg")))) + (build-system cmake-build-system) + (inputs (list libxml2)) + (arguments + `(#:tests? #f) + ))) + +(define exprtk + (package + (name "exprtk") + (home-page "https://www.partow.net/programming/exprtk/index.html") + (synopsis "C++ Mathematical Expression Parsing And Evaluation Library") + (description "") + (license license:expat) + (version "0.0.2") + (source (origin + (method git-fetch) + (uri (git-reference + (url "https://github.com/ArashPartow/exprtk.git") + (commit version))) + (sha256 + (base32 + "1w92qlfjpcan38d88fak3avq81lkcpai5mqpbvrsfv04mi5nfpk5")))) + (build-system copy-build-system) + (arguments + '(#:install-plan '(("exprtk.hpp" "include/"))) + ))) + ;; return package ogs diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index f26f2fd7eeb..a50eea6c086 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -42,10 +42,10 @@ repos: - id: cmake-format additional_dependencies: ["cmakelang[YAML]"] args: [--config=.cmake-format.yaml] - exclude: "scripts/cmake/jedbrown/.*|PackagingMacros.cmake|conan.cmake|CPM.cmake|FindFilesystem.cmake|ConanSetup.cmake|Tests.cmake" + exclude: "scripts/cmake/jedbrown/.*|conan.cmake|CPM.cmake|FindFilesystem.cmake|FindMKL.cmake|JSONParser.cmake|ConanSetup.cmake|Tests.cmake" - id: cmake-lint additional_dependencies: ["cmakelang[YAML]"] - exclude: "scripts/cmake/jedbrown/.*|PackagingMacros.cmake|conan.cmake|CPM.cmake|FindFilesystem.cmake|ConanSetup.cmake|BuildExternalProject.cmake" + exclude: "scripts/cmake/jedbrown/.*|conan.cmake|CPM.cmake|FindFilesystem.cmake|FindMKL.cmake|JSONParser.cmake|ConanSetup.cmake|BuildExternalProject.cmake" - repo: https://github.com/igorshubovych/markdownlint-cli rev: v0.33.0 hooks: diff --git a/CMakeLists.txt b/CMakeLists.txt index 2b85cfcc8e9..c359bdd7c58 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -226,6 +226,8 @@ if(OGS_BUILD_CLI OR OGS_BUILD_UTILS OR OGS_BUILD_TESTING) add_subdirectory(ParameterLib) add_subdirectory(MaterialLib) add_subdirectory(ProcessLib) +endif() +if(TARGET OgsXdmf) add_subdirectory(Tests/xdmfdiff) endif() if(OGS_BUILD_TESTING AND PROJECT_IS_TOP_LEVEL) diff --git a/ChemistryLib/CMakeLists.txt b/ChemistryLib/CMakeLists.txt index deed7d137ce..6ebade14950 100644 --- a/ChemistryLib/CMakeLists.txt +++ b/ChemistryLib/CMakeLists.txt @@ -9,7 +9,7 @@ append_source_files(SOURCES Common) ogs_add_library(ChemistryLib ${SOURCES}) target_link_libraries( - ChemistryLib PUBLIC Eigen3::Eigen iphreeqc PRIVATE BaseLib MaterialLib + ChemistryLib PUBLIC Eigen3::Eigen IPhreeqc PRIVATE BaseLib MaterialLib MathLib MeshLib NumLib ) diff --git a/ThirdParty/collection b/ThirdParty/collection deleted file mode 160000 index b2463383eb2..00000000000 --- a/ThirdParty/collection +++ /dev/null @@ -1 +0,0 @@ -Subproject commit b2463383eb2925131842c02cb78c6b1afd6f52a3 diff --git a/scripts/cmake/CMakeSetup.cmake b/scripts/cmake/CMakeSetup.cmake index 733d133d0ea..474d03a3947 100644 --- a/scripts/cmake/CMakeSetup.cmake +++ b/scripts/cmake/CMakeSetup.cmake @@ -16,27 +16,11 @@ if(WIN32 AND (NOT "${CMAKE_GENERATOR}" MATCHES "Visual Studio") message(FATAL_ERROR "Wheels only build in Visual Studio!") endif() -set(_collection ${PROJECT_SOURCE_DIR}/ThirdParty/collection) -# If submodules in ThirdParty/collection are initialized and this is a Guix -# build use submodule as CPM sources. -if(EXISTS ${_collection}/ufz/vtkdiff/CMakeLists.txt AND GUIX_BUILD) - include(${_collection}/Setup.cmake) -endif() - -# Set additional CMake modules path To be replaced later. See -# https://gitlab.kitware.com/cmake/cmake/-/issues/22831 -CPMAddPackage( - NAME findmkl_cmake - GITHUB_REPOSITORY bilke/findmkl_cmake - GIT_TAG ee49c4f973f66bb7bfd644658d14e43459f557fa - DOWNLOAD_ONLY YES -) +# Set additional CMake modules path set(CMAKE_MODULE_PATH - ${CMAKE_MODULE_PATH} - "${PROJECT_SOURCE_DIR}/scripts/cmake" + ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/scripts/cmake" "${PROJECT_SOURCE_DIR}/scripts/cmake/jedbrown" "${PROJECT_SOURCE_DIR}/scripts/cmake/vector-of-bool" - "${findmkl_cmake_SOURCE_DIR}/cmake" ) list( diff --git a/scripts/cmake/Dependencies.cmake b/scripts/cmake/Dependencies.cmake index 8cff8653fa0..678c2d09984 100644 --- a/scripts/cmake/Dependencies.cmake +++ b/scripts/cmake/Dependencies.cmake @@ -42,27 +42,37 @@ else() ) endif() -CPMFindPackage( - NAME tclap - GITHUB_REPOSITORY ufz/tclap - VERSION 1.2.4 - GIT_TAG 098dd0fe07a31618f3c2a9f8727bb01c8c5d61e2 - DOWNLOAD_ONLY YES -) -if(tclap_ADDED) - add_library(tclap INTERFACE IMPORTED) - target_include_directories( - tclap SYSTEM INTERFACE ${tclap_SOURCE_DIR}/include +if(GUIX_BUILD) + add_library(tclap INTERFACE IMPORTED) # header-only, nothing else to do +else() + CPMFindPackage( + NAME tclap + GITHUB_REPOSITORY ufz/tclap + VERSION 1.2.4 + GIT_TAG 098dd0fe07a31618f3c2a9f8727bb01c8c5d61e2 + DOWNLOAD_ONLY YES ) + if(tclap_ADDED) + add_library(tclap INTERFACE IMPORTED) + target_include_directories( + tclap SYSTEM INTERFACE ${tclap_SOURCE_DIR}/include + ) + endif() endif() -CPMAddPackage( - NAME tetgen GITHUB_REPOSITORY ufz/tetgen - GIT_TAG 603ba181ebfaed38eec88532720e282606009b73 -) -if(tetgen_ADDED) - install(PROGRAMS $ DESTINATION bin) - list(APPEND DISABLE_WARNINGS_TARGETS tet tetgen) +if(GUIX_BUILD) + find_library(tet tet REQUIRED) + find_program(TETGEN_EXECUTABLE tetgen REQUIRED) + install(PROGRAMS ${TETGEN_EXECUTABLE} DESTINATION bin) +else() + CPMAddPackage( + NAME tetgen GITHUB_REPOSITORY ufz/tetgen + GIT_TAG 603ba181ebfaed38eec88532720e282606009b73 + ) + if(tetgen_ADDED) + install(PROGRAMS $ DESTINATION bin) + list(APPEND DISABLE_WARNINGS_TARGETS tet tetgen) + endif() endif() CPMFindPackage( @@ -71,15 +81,22 @@ CPMFindPackage( ) if(_build_chemistry_lib) - CPMAddPackage( - NAME iphreeqc - GITHUB_REPOSITORY ufz/iphreeqc - GIT_TAG b1047d3eb03e7ef1b850231be35acb9c6a2cf345 - DOWNLOAD_ONLY YES - ) - if(iphreeqc_ADDED) - include(scripts/cmake/iphreeqc.cmake) - list(APPEND DISABLE_WARNINGS_TARGETS iphreeqc) + if(BUILD_GUIX) + find_library(IPhreeqc iphreeqc REQUIRED) + else() + CPMAddPackage( + NAME iphreeqc GITHUB_REPOSITORY ufz/iphreeqc GIT_TAG 3.5.0-1 + ) + if(iphreeqc_ADDED) + target_include_directories( + IPhreeqc + PUBLIC ${iphreeqc_SOURCE_DIR}/src + INTERFACE ${iphreeqc_SOURCE_DIR}/src/phreeqcpp/common + ${iphreeqc_SOURCE_DIR}/src/phreeqcpp/PhreeqcKeywords + ${iphreeqc_SOURCE_DIR}/src/phreeqcpp + ) + list(APPEND DISABLE_WARNINGS_TARGETS IPhreeqc) + endif() endif() endif() @@ -158,12 +175,19 @@ if(LibXml2_ADDED) list(APPEND DISABLE_WARNINGS_TARGETS LibXml2) endif() -CPMAddPackage( - NAME xmlpatch - VERSION 0.4.2 - GIT_REPOSITORY https://gitlab.opengeosys.org/ogs/libs/xmlpatch.git - OPTIONS "BUILD_SHARED_LIBS OFF" -) +if(GUIX_BUILD) + find_library(XMLPATCH_LIB xmlpatch REQUIRED) + add_library(xmlpatch INTERFACE) + find_package(LibXml2 REQUIRED) + target_link_libraries(xmlpatch INTERFACE ${XMLPATCH_LIB} LibXml2::LibXml2) +else() + CPMAddPackage( + NAME xmlpatch + VERSION 0.4.2 + GIT_REPOSITORY https://gitlab.opengeosys.org/ogs/libs/xmlpatch.git + OPTIONS "BUILD_SHARED_LIBS OFF" + ) +endif() if(OGS_BUILD_SWMM) CPMAddPackage( @@ -258,15 +282,19 @@ endif() # find_package(ParaView REQUIRED) # endif() # ~~~ -CPMAddPackage( - NAME exprtk - GIT_REPOSITORY https://gitlab.opengeosys.org/ogs/libs/exprtk.git - GIT_TAG 2a5c62b93c9661470e69be572f22d821308b6f61 - DOWNLOAD_ONLY YES -) -if(exprtk_ADDED) +if(GUIX_BUILD) add_library(exprtk INTERFACE IMPORTED) - target_include_directories(exprtk SYSTEM INTERFACE ${exprtk_SOURCE_DIR}) +else() + CPMAddPackage( + NAME exprtk + GIT_REPOSITORY https://gitlab.opengeosys.org/ogs/libs/exprtk.git + GIT_TAG 2a5c62b93c9661470e69be572f22d821308b6f61 + DOWNLOAD_ONLY YES + ) + if(exprtk_ADDED) + add_library(exprtk INTERFACE IMPORTED) + target_include_directories(exprtk SYSTEM INTERFACE ${exprtk_SOURCE_DIR}) + endif() endif() if(GUIX_BUILD) @@ -281,7 +309,7 @@ else() ) endif() -if(OGS_BUILD_TESTING OR OGS_BUILD_UTILS) +if((OGS_BUILD_TESTING OR OGS_BUILD_UTILS) AND NOT GUIX_BUILD) CPMAddPackage( NAME vtkdiff GITHUB_REPOSITORY ufz/vtkdiff GIT_TAG 9754b4da43c6adfb65d201ed920b5f6ea27b38b9 @@ -304,7 +332,7 @@ if(OGS_USE_PETSC) endif() endif() -if(OGS_BUILD_TESTING OR OGS_BUILD_CLI OR OGS_BUILD_UTILS) +if((OGS_BUILD_TESTING OR OGS_BUILD_UTILS) AND NOT GUIX_BUILD) set(XDMF_LIBNAME OgsXdmf CACHE STRING "") CPMAddPackage( NAME xdmf @@ -347,10 +375,12 @@ if(OGS_BUILD_TESTING OR OGS_BUILD_CLI OR OGS_BUILD_UTILS) endif() endif() -CPMAddPackage( - NAME GroupSourcesByFolder.cmake - GITHUB_REPOSITORY TheLartians/GroupSourcesByFolder.cmake VERSION 1.0 -) +if(MSVC) + CPMAddPackage( + NAME GroupSourcesByFolder.cmake + GITHUB_REPOSITORY TheLartians/GroupSourcesByFolder.cmake VERSION 1.0 + ) +endif() if(OGS_BUILD_UTILS) if(NOT GUIX_BUILD) diff --git a/scripts/cmake/FindMKL.cmake b/scripts/cmake/FindMKL.cmake new file mode 100644 index 00000000000..edc70d7f3ac --- /dev/null +++ b/scripts/cmake/FindMKL.cmake @@ -0,0 +1,354 @@ +# ------------------------------------------------------------------- +# Originally obtained from https://github.com/openmeeg/findmkl_cmake. +# Modified for OpenGeoSys in https://github.com/bilke/findmkl_cmake. +# ------------------------------------------------------------------- + +# Distributed under the OSI-approved BSD 3-Clause License. See accompanying +# file Copyright.txt or https://cmake.org/licensing for details. + +# .rst: FindMKL +# ------- +# +# Find a Intel® Math Kernel Library (Intel® MKL) installation and provide all +# necessary variables and macros to compile software for it. +# +# MKLROOT is required in your system +# +# we use mkl_link_tool to get the library needed depending on variables There +# are few sets of libraries: +# +# Array indexes modes: +# +# :: +# +# LP - 32 bit indexes of arrays ILP - 64 bit indexes of arrays +# +# Threading: +# +# :: +# +# SEQUENTIAL - no threading INTEL - Intel threading library GNU - GNU threading +# library MPI support NOMPI - no MPI support INTEL - Intel MPI library OPEN - +# Open MPI library SGI - SGI MPT Library +# +# The following are set after the configuration is done: +# +# :: +# +# MKL_FOUND - system has MKL MKL_ROOT_DIR - path to the MKL base +# directory MKL_INCLUDE_DIR - the MKL include directory MKL_LIBRARIES - MKL +# libraries MKL_LIBRARY_DIR - MKL library dir (for dlls!) +# +# Sample usage: +# +# If MKL is required (i.e., not an optional part): +# +# :: +# +# find_package(MKL REQUIRED) if (MKL_FOUND) +# include_directories(${MKL_INCLUDE_DIR}) # and for each of your dependent +# executable/library targets: target_link_libraries( +# ${MKL_LIBRARIES}) endif() + +# NOTES +# +# If you want to use the module and your build type is not supported +# out-of-the-box, please contact me to exchange information on how your system +# is setup and I'll try to add support for it. +# +# AUTHOR +# +# Joan MASSICH (joan.massich-vall.AT.inria.fr). Alexandre GRAMFORT +# (Alexandre.Gramfort.AT.inria.fr) Théodore PAPADOPOULO (papadop.AT.inria.fr) + +set(FINDMKL_DEBUG_MODE 1) + +# unset this variable defined in matio +unset(MSVC) + +# Find MKL ROOT +find_path(MKL_ROOT_DIR NAMES include/mkl_cblas.h PATHS $ENV{MKLROOT} ${MKLROOT} + $ENV{MKL_DIR} ${MKL_DIR} +) + +# Convert symlinks to real paths + +get_filename_component(MKL_ROOT_DIR ${MKL_ROOT_DIR} REALPATH) + +if(NOT MKL_ROOT_DIR) + if(MKL_FIND_REQUIRED) + message( + FATAL_ERROR + "Could not find MKL: please set environment or CMake variable MKLROOT or MKL_DIR!" + ) + else() + unset(MKL_ROOT_DIR CACHE) + endif() +else() + # set arguments to call the MKL-provided tool for linking + set(MKL_INCLUDE_DIR ${MKL_ROOT_DIR}/include) + + # determine the name of the MKL-provided tool for linking + if(WIN32) + set(MKL_LINK_TOOL_BINARY mkl_link_tool.exe) + else() + set(MKL_LINK_TOOL_BINARY mkl_link_tool) + endif() + + # determine the path of the MKL-provided tool for linking + if(EXISTS "${MKL_ROOT_DIR}/bin/intel64/${MKL_LINK_TOOL_BINARY}") + # this path is used by MKL 2021.1.1 and newer + set(MKL_LINK_TOOL "${MKL_ROOT_DIR}/bin/intel64/${MKL_LINK_TOOL_BINARY}") + elseif(EXISTS "${MKL_ROOT_DIR}/bin/${MKL_LINK_TOOL_BINARY}") + # this path is used by MKL 2020.1.217 and newer + set(MKL_LINK_TOOL "${MKL_ROOT_DIR}/bin/${MKL_LINK_TOOL_BINARY}") + elseif(EXISTS "${MKL_ROOT_DIR}/tools/${MKL_LINK_TOOL_BINARY}") + set(MKL_LINK_TOOL "${MKL_ROOT_DIR}/tools/${MKL_LINK_TOOL_BINARY}") + else() + message( + FATAL_ERROR + "cannot find MKL link tool in any of the searched locations" + ) + endif() + + # now the libs + set(MKL_LINK_TOOL_COMMAND ${MKL_LINK_TOOL} "-libs") + + # possible versions + # <11.3|11.2|11.1|11.0|10.3|10.2|10.1|10.0|ParallelStudioXE2016|ParallelStudioXE2015|ComposerXE2013SP1|ComposerXE2013|ComposerXE2011|CompilerPro> + + # not older than MKL 10 (2011) + if(MKL_INCLUDE_DIR MATCHES "Composer.*2013") + list(APPEND MKL_LINK_TOOL_COMMAND "--mkl=ComposerXE2013") + elseif(MKL_INCLUDE_DIR MATCHES "Composer.*2011") + list(APPEND MKL_LINK_TOOL_COMMAND "--mkl=ComposerXE2011") + elseif(MKL_INCLUDE_DIR MATCHES "10.3") + list(APPEND MKL_LINK_TOOL_COMMAND "--mkl=10.3") + elseif(MKL_INCLUDE_DIR MATCHES "2013") # version 11 ... + list(APPEND MKL_LINK_TOOL_COMMAND "--mkl=11.1") + elseif(MKL_INCLUDE_DIR MATCHES "2015") + list(APPEND MKL_LINK_TOOL_COMMAND "--mkl=11.2") + elseif(MKL_INCLUDE_DIR MATCHES "2016") + list(APPEND MKL_LINK_TOOL_COMMAND "--mkl=11.3") + elseif(MKL_INCLUDE_DIR MATCHES "2017") + list(APPEND MKL_LINK_TOOL_COMMAND "--mkl=11.3") + elseif(MKL_INCLUDE_DIR MATCHES "2018") + list(APPEND MKL_LINK_TOOL_COMMAND "--mkl=11.3") + elseif(MKL_INCLUDE_DIR MATCHES "10") + list(APPEND MKL_LINK_TOOL_COMMAND "--mkl=10.2") + else() + list(APPEND MKL_LINK_TOOL_COMMAND "--mkl=11.3") + endif() + + if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") + list(APPEND MKL_LINK_TOOL_COMMAND "--compiler=clang") + elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Intel") + list(APPEND MKL_LINK_TOOL_COMMAND "--compiler=intel_c") + elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") + list(APPEND MKL_LINK_TOOL_COMMAND "--compiler=ms_c") + else() + list(APPEND MKL_LINK_TOOL_COMMAND "--compiler=gnu_c") + endif() + + if(APPLE) + list(APPEND MKL_LINK_TOOL_COMMAND "--os=mac") + elseif(WIN32) + list(APPEND MKL_LINK_TOOL_COMMAND "--os=win") + else() + list(APPEND MKL_LINK_TOOL_COMMAND "--os=lnx") + endif() + + set(MKL_LIB_DIR) + if(${CMAKE_SIZEOF_VOID_P} EQUAL 8) + list(APPEND MKL_LINK_TOOL_COMMAND "--arch=intel64") + set(MKL_LIB_DIR "intel64") + else() + list(APPEND MKL_LINK_TOOL_COMMAND "--arch=ia32") + set(MKL_LIB_DIR "ia32") + endif() + + if(MKL_USE_sdl) + list(APPEND MKL_LINK_TOOL_COMMAND "--linking=sdl") + else() + if(BLA_STATIC) + list(APPEND MKL_LINK_TOOL_COMMAND "--linking=static") + else() + list(APPEND MKL_LINK_TOOL_COMMAND "--linking=dynamic") + endif() + endif() + + if(MKL_USE_parallel) + list(APPEND MKL_LINK_TOOL_COMMAND "--parallel=yes") + else() + list(APPEND MKL_LINK_TOOL_COMMAND "--parallel=no") + endif() + + if(FORCE_BUILD_32BITS) + list(APPEND MKL_LINK_TOOL_COMMAND "--interface=cdecl") + set(MKL_USE_interface "cdecl" + CACHE STRING "disabled by FORCE_BUILD_32BITS" FORCE + ) + else() + list(APPEND MKL_LINK_TOOL_COMMAND "--interface=${MKL_USE_interface}") + endif() + + if(MKL_USE_parallel) + # With icc on linux, supported values by mkl_link_tool for threading + # library are: iomp5|tbb + if(WIN32) + list(APPEND MKL_LINK_TOOL_COMMAND "--threading-library=tbb") + else() + list(APPEND MKL_LINK_TOOL_COMMAND "--threading-library=iomp5") + list(APPEND MKL_LINK_TOOL_COMMAND "--openmp=iomp5") + endif() + endif() + + execute_process( + COMMAND ${MKL_LINK_TOOL_COMMAND} + OUTPUT_VARIABLE MKL_LIBS + RESULT_VARIABLE COMMAND_WORKED + TIMEOUT 2 + ERROR_QUIET + ) + + set(MKL_LIBRARIES) + set(MKL_LINK_FLAGS "") + + if(NOT ${COMMAND_WORKED} EQUAL 0) + message( + FATAL_ERROR + "Cannot find the MKL libraries correctly. Please check your MKL input variables and mkl_link_tool. The command executed was:\n ${MKL_LINK_TOOL_COMMAND}." + ) + endif() + + set(MKL_LIBRARY_DIR) + + if(WIN32) + set(MKL_LIBRARY_DIR + "${MKL_ROOT_DIR}/lib/${MKL_LIB_DIR}/" + "${MKL_ROOT_DIR}/../../tbb/latest/lib/intel64/vc_mt" + ) + + # remove unwanted break + string(REGEX REPLACE "\n" "" MKL_LIBS ${MKL_LIBS}) + + # get the list of libs + separate_arguments(MKL_LIBS) + foreach(i ${MKL_LIBS}) + find_library(FULLPATH_LIB ${i} PATHS "${MKL_LIBRARY_DIR}") + + if(FULLPATH_LIB) + list(APPEND MKL_LIBRARIES ${FULLPATH_LIB}) + elseif(i) + list(APPEND MKL_LIBRARIES ${i}) + endif() + unset(FULLPATH_LIB CACHE) + endforeach() + + else() # UNIX and macOS + # remove unwanted break + string(REGEX REPLACE "\n" "" MKL_LIBS ${MKL_LIBS}) + if(MKL_LINK_TOOL_COMMAND MATCHES "static") + string(REPLACE "$(MKLROOT)" "${MKL_ROOT_DIR}" MKL_LIBRARIES + ${MKL_LIBS} + ) + # hack for lin with libiomp5.a + if(APPLE) + string(REPLACE "-liomp5" + "${MKL_ROOT_DIR}/../compiler/lib/libiomp5.a" + MKL_LIBRARIES ${MKL_LIBRARIES} + ) + else() + string( + REPLACE + "-liomp5" + "${MKL_ROOT_DIR}/../compiler/lib/${MKL_LIB_DIR}/libiomp5.a" + MKL_LIBRARIES + ${MKL_LIBRARIES} + ) + endif() + separate_arguments(MKL_LIBRARIES) + else() # dynamic or sdl + # get the lib dirs + string(REGEX REPLACE "^.*-L[^/]+([^\ ]+).*" "${MKL_ROOT_DIR}\\1" + INTEL_LIB_DIR ${MKL_LIBS} + ) + if(NOT EXISTS ${INTEL_LIB_DIR}) + # Work around a bug in mkl 2018 + set(INTEL_LIB_DIR1 "${INTEL_LIB_DIR}_lin") + if(NOT EXISTS ${INTEL_LIB_DIR1}) + message( + FATAL_ERROR + "MKL installation broken. Directory ${INTEL_LIB_DIR} does not exist." + ) + endif() + set(INTEL_LIB_DIR ${INTEL_LIB_DIR1}) + endif() + set(MKL_LIBRARY_DIR ${INTEL_LIB_DIR}) + if(EXISTS + ${MKL_ROOT_DIR}/../../compiler/latest/linux/compiler/lib/${MKL_LIB_DIR} + ) + list( + APPEND + MKL_LIBRARY_DIR + ${MKL_ROOT_DIR}/../../compiler/latest/linux/compiler/lib/${MKL_LIB_DIR} + ) + endif() + + # get the list of libs + separate_arguments(MKL_LIBS) + + # set full path to libs + foreach(i ${MKL_LIBS}) + string(REGEX REPLACE " -" "-" i_mod ${i}) + string(REGEX REPLACE "-l([^\ ]+)" "\\1" i_mod ${i_mod}) + string(REGEX REPLACE "-L.*" "" i_mod ${i_mod}) + + find_library(FULLPATH_LIB ${i_mod} PATHS "${MKL_LIBRARY_DIR}") + + if(FULLPATH_LIB) + list(APPEND MKL_LIBRARIES ${FULLPATH_LIB}) + elseif(i) + if("${i}" MATCHES "^-[l|L].*") + string(REPLACE "$(MKLROOT)" "$ENV{MKLROOT}" i ${i}) + list(APPEND MKL_LIBRARIES ${i}) + else() + list(APPEND MKL_LINK_FLAGS ${i}) + endif() + endif() + unset(FULLPATH_LIB CACHE) + endforeach() + endif() + endif() + + # now definitions + string(REPLACE "-libs" "-opts" MKL_LINK_TOOL_COMMAND + "${MKL_LINK_TOOL_COMMAND}" + ) + execute_process( + COMMAND ${MKL_LINK_TOOL_COMMAND} + OUTPUT_VARIABLE RESULT_OPTS + TIMEOUT 2 + ERROR_QUIET + ) + string(REGEX MATCHALL "[-/]D[^\ ]*" MKL_DEFINITIONS ${RESULT_OPTS}) + + if(FINDMKL_DEBUG_MODE) + message(STATUS "Executed command: \n${MKL_LINK_TOOL_COMMAND}") + message(STATUS "Found MKL_LIBRARIES:\n${MKL_LIBRARIES} ") + message(STATUS "Found MKL_DEFINITIONS:\n${MKL_DEFINITIONS} ") + message(STATUS "Found MKL_LIBRARY_DIR:\n${MKL_LIBRARY_DIR} ") + message(STATUS "Found MKL_INCLUDE_DIR:\n${MKL_INCLUDE_DIR} ") + message(STATUS "Found MKL_LINK_FLAGS:\n${MKL_LINK_FLAGS} ") + endif() + + include(FindPackageHandleStandardArgs) + find_package_handle_standard_args( + MKL DEFAULT_MSG MKL_INCLUDE_DIR MKL_LIBRARIES + ) + + mark_as_advanced( + MKL_INCLUDE_DIR MKL_LIBRARIES MKL_DEFINITIONS MKL_ROOT_DIR + MKL_LINK_FLAGS + ) +endif() diff --git a/scripts/cmake/Functions.cmake b/scripts/cmake/Functions.cmake index 89a253e0bf7..8e17e1c035d 100644 --- a/scripts/cmake/Functions.cmake +++ b/scripts/cmake/Functions.cmake @@ -113,7 +113,9 @@ function(ogs_add_library targetName) endif() endif() - GroupSourcesByFolder(${targetName}) + if(MSVC) + GroupSourcesByFolder(${targetName}) + endif() endfunction() # Replacement for ogs_add_executable() for ogs executables diff --git a/scripts/cmake/Versions.cmake b/scripts/cmake/Versions.cmake index 11856b59002..56da8cea7da 100644 --- a/scripts/cmake/Versions.cmake +++ b/scripts/cmake/Versions.cmake @@ -1,10 +1,4 @@ -CPMAddPackage( - NAME json-cmake - GITHUB_REPOSITORY ufz/json-cmake - GIT_TAG 9708cb091f6b89b94d71ae98f8b9e68ea04c47dd - DOWNLOAD_ONLY YES -) -include("${json-cmake_SOURCE_DIR}/JSONParser.cmake") +include(${PROJECT_SOURCE_DIR}/scripts/cmake/json-cmake/JSONParser.cmake) file(READ ${PROJECT_SOURCE_DIR}/web/data/versions.json jsonFileString) set_property( DIRECTORY . APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS diff --git a/scripts/cmake/iphreeqc.cmake b/scripts/cmake/iphreeqc.cmake deleted file mode 100644 index 4995e45c63a..00000000000 --- a/scripts/cmake/iphreeqc.cmake +++ /dev/null @@ -1,102 +0,0 @@ -set(SOURCES - ${iphreeqc_SOURCE_DIR}/src/CSelectedOutput.cpp - ${iphreeqc_SOURCE_DIR}/src/fwrap.cpp - ${iphreeqc_SOURCE_DIR}/src/IPhreeqc.cpp - ${iphreeqc_SOURCE_DIR}/src/IPhreeqc_interface_F.cpp - ${iphreeqc_SOURCE_DIR}/src/IPhreeqcLib.cpp - ${iphreeqc_SOURCE_DIR}/src/Var.c - ${iphreeqc_SOURCE_DIR}/src/phreeqcpp/advection.cpp - ${iphreeqc_SOURCE_DIR}/src/phreeqcpp/basicsubs.cpp - ${iphreeqc_SOURCE_DIR}/src/phreeqcpp/cl1.cpp - ${iphreeqc_SOURCE_DIR}/src/phreeqcpp/cvdense.cpp - ${iphreeqc_SOURCE_DIR}/src/phreeqcpp/cvode.cpp - ${iphreeqc_SOURCE_DIR}/src/phreeqcpp/cxxKinetics.cxx - ${iphreeqc_SOURCE_DIR}/src/phreeqcpp/cxxMix.cxx - ${iphreeqc_SOURCE_DIR}/src/phreeqcpp/dense.cpp - ${iphreeqc_SOURCE_DIR}/src/phreeqcpp/Dictionary.cpp - ${iphreeqc_SOURCE_DIR}/src/phreeqcpp/dumper.cpp - ${iphreeqc_SOURCE_DIR}/src/phreeqcpp/Exchange.cxx - ${iphreeqc_SOURCE_DIR}/src/phreeqcpp/ExchComp.cxx - ${iphreeqc_SOURCE_DIR}/src/phreeqcpp/GasComp.cxx - ${iphreeqc_SOURCE_DIR}/src/phreeqcpp/gases.cpp - ${iphreeqc_SOURCE_DIR}/src/phreeqcpp/GasPhase.cxx - ${iphreeqc_SOURCE_DIR}/src/phreeqcpp/input.cpp - ${iphreeqc_SOURCE_DIR}/src/phreeqcpp/integrate.cpp - ${iphreeqc_SOURCE_DIR}/src/phreeqcpp/inverse.cpp - ${iphreeqc_SOURCE_DIR}/src/phreeqcpp/ISolution.cxx - ${iphreeqc_SOURCE_DIR}/src/phreeqcpp/ISolutionComp.cxx - ${iphreeqc_SOURCE_DIR}/src/phreeqcpp/isotopes.cpp - ${iphreeqc_SOURCE_DIR}/src/phreeqcpp/kinetics.cpp - ${iphreeqc_SOURCE_DIR}/src/phreeqcpp/KineticsComp.cxx - ${iphreeqc_SOURCE_DIR}/src/phreeqcpp/mainsubs.cpp - ${iphreeqc_SOURCE_DIR}/src/phreeqcpp/model.cpp - ${iphreeqc_SOURCE_DIR}/src/phreeqcpp/NameDouble.cxx - ${iphreeqc_SOURCE_DIR}/src/phreeqcpp/NumKeyword.cxx - ${iphreeqc_SOURCE_DIR}/src/phreeqcpp/nvector.cpp - ${iphreeqc_SOURCE_DIR}/src/phreeqcpp/nvector_serial.cpp - ${iphreeqc_SOURCE_DIR}/src/phreeqcpp/parse.cpp - ${iphreeqc_SOURCE_DIR}/src/phreeqcpp/PBasic.cpp - ${iphreeqc_SOURCE_DIR}/src/phreeqcpp/phqalloc.cpp - ${iphreeqc_SOURCE_DIR}/src/phreeqcpp/Phreeqc.cpp - ${iphreeqc_SOURCE_DIR}/src/phreeqcpp/PHRQ_io_output.cpp - ${iphreeqc_SOURCE_DIR}/src/phreeqcpp/pitzer.cpp - ${iphreeqc_SOURCE_DIR}/src/phreeqcpp/pitzer_structures.cpp - ${iphreeqc_SOURCE_DIR}/src/phreeqcpp/PPassemblage.cxx - ${iphreeqc_SOURCE_DIR}/src/phreeqcpp/PPassemblageComp.cxx - ${iphreeqc_SOURCE_DIR}/src/phreeqcpp/prep.cpp - ${iphreeqc_SOURCE_DIR}/src/phreeqcpp/Pressure.cxx - ${iphreeqc_SOURCE_DIR}/src/phreeqcpp/print.cpp - ${iphreeqc_SOURCE_DIR}/src/phreeqcpp/Reaction.cxx - ${iphreeqc_SOURCE_DIR}/src/phreeqcpp/read.cpp - ${iphreeqc_SOURCE_DIR}/src/phreeqcpp/ReadClass.cxx - ${iphreeqc_SOURCE_DIR}/src/phreeqcpp/readtr.cpp - ${iphreeqc_SOURCE_DIR}/src/phreeqcpp/runner.cpp - ${iphreeqc_SOURCE_DIR}/src/phreeqcpp/SelectedOutput.cpp - ${iphreeqc_SOURCE_DIR}/src/phreeqcpp/Serializer.cxx - ${iphreeqc_SOURCE_DIR}/src/phreeqcpp/sit.cpp - ${iphreeqc_SOURCE_DIR}/src/phreeqcpp/smalldense.cpp - ${iphreeqc_SOURCE_DIR}/src/phreeqcpp/Solution.cxx - ${iphreeqc_SOURCE_DIR}/src/phreeqcpp/SolutionIsotope.cxx - ${iphreeqc_SOURCE_DIR}/src/phreeqcpp/spread.cpp - ${iphreeqc_SOURCE_DIR}/src/phreeqcpp/SS.cxx - ${iphreeqc_SOURCE_DIR}/src/phreeqcpp/SSassemblage.cxx - ${iphreeqc_SOURCE_DIR}/src/phreeqcpp/SScomp.cxx - ${iphreeqc_SOURCE_DIR}/src/phreeqcpp/step.cpp - ${iphreeqc_SOURCE_DIR}/src/phreeqcpp/StorageBin.cxx - ${iphreeqc_SOURCE_DIR}/src/phreeqcpp/StorageBinList.cpp - ${iphreeqc_SOURCE_DIR}/src/phreeqcpp/structures.cpp - ${iphreeqc_SOURCE_DIR}/src/phreeqcpp/sundialsmath.cpp - ${iphreeqc_SOURCE_DIR}/src/phreeqcpp/Surface.cxx - ${iphreeqc_SOURCE_DIR}/src/phreeqcpp/SurfaceCharge.cxx - ${iphreeqc_SOURCE_DIR}/src/phreeqcpp/SurfaceComp.cxx - ${iphreeqc_SOURCE_DIR}/src/phreeqcpp/System.cxx - ${iphreeqc_SOURCE_DIR}/src/phreeqcpp/tally.cpp - ${iphreeqc_SOURCE_DIR}/src/phreeqcpp/Temperature.cxx - ${iphreeqc_SOURCE_DIR}/src/phreeqcpp/tidy.cpp - ${iphreeqc_SOURCE_DIR}/src/phreeqcpp/transport.cpp - ${iphreeqc_SOURCE_DIR}/src/phreeqcpp/Use.cpp - ${iphreeqc_SOURCE_DIR}/src/phreeqcpp/UserPunch.cpp - ${iphreeqc_SOURCE_DIR}/src/phreeqcpp/utilities.cpp - ${iphreeqc_SOURCE_DIR}/src/phreeqcpp/common/Parser.cxx - ${iphreeqc_SOURCE_DIR}/src/phreeqcpp/common/PHRQ_base.cxx - ${iphreeqc_SOURCE_DIR}/src/phreeqcpp/common/PHRQ_io.cpp - ${iphreeqc_SOURCE_DIR}/src/phreeqcpp/common/Utils.cxx - ${iphreeqc_SOURCE_DIR}/src/phreeqcpp/PhreeqcKeywords/Keywords.cpp -) - -# compile Var.c as c++ -SET_SOURCE_FILES_PROPERTIES( - ${iphreeqc_SOURCE_DIR}/src/Var.c PROPERTIES LANGUAGE CXX -) - -add_library(iphreeqc STATIC ${SOURCES}) -target_include_directories( - iphreeqc - PUBLIC ${iphreeqc_SOURCE_DIR}/src/phreeqcpp/common - ${iphreeqc_SOURCE_DIR}/src/phreeqcpp/PhreeqcKeywords - ${iphreeqc_SOURCE_DIR}/src/phreeqcpp ${iphreeqc_SOURCE_DIR}/src -) -target_compile_definitions(iphreeqc PUBLIC LDBLE=double) -# Exclude iphreeqc target from clang-tidy tests because it handles the above -# mentioned 'src/src/Var.c' file as c, not c++. -set_target_properties(iphreeqc PROPERTIES CXX_CLANG_TIDY "") diff --git a/scripts/cmake/json-cmake/JSONParser.cmake b/scripts/cmake/json-cmake/JSONParser.cmake new file mode 100644 index 00000000000..f5752a853e6 --- /dev/null +++ b/scripts/cmake/json-cmake/JSONParser.cmake @@ -0,0 +1,298 @@ +cmake_minimum_required(VERSION 3.1) + +if (DEFINED JSonParserGuard) + return() +endif() + +set(JSonParserGuard yes) + +macro(sbeParseJson prefix jsonString) + cmake_policy(PUSH) + + set(json_string "${${jsonString}}") + string(LENGTH "${json_string}" json_jsonLen) + set(json_index 0) + set(json_AllVariables ${prefix}) + set(json_ArrayNestingLevel 0) + set(json_MaxArrayNestingLevel 0) + + _sbeParse(${prefix}) + + unset(json_index) + unset(json_AllVariables) + unset(json_jsonLen) + unset(json_string) + unset(json_value) + unset(json_inValue) + unset(json_name) + unset(json_inName) + unset(json_newPrefix) + unset(json_reservedWord) + unset(json_arrayIndex) + unset(json_char) + unset(json_end) + unset(json_ArrayNestingLevel) + foreach(json_nestingLevel RANGE ${json_MaxArrayNestingLevel}) + unset(json_${json_nestingLevel}_arrayIndex) + endforeach() + unset(json_nestingLevel) + unset(json_MaxArrayNestingLevel) + + cmake_policy(POP) +endmacro() + +macro(sbeClearJson prefix) + foreach(json_var ${${prefix}}) + unset(${json_var}) + endforeach() + + unset(${prefix}) + unset(json_var) +endmacro() + +macro(sbePrintJson prefix) + foreach(json_var ${${prefix}}) + message("${json_var} = ${${json_var}}") + endforeach() +endmacro() + +macro(_sbeParse prefix) + + while(${json_index} LESS ${json_jsonLen}) + string(SUBSTRING "${json_string}" ${json_index} 1 json_char) + + if("\"" STREQUAL "${json_char}") + _sbeParseNameValue(${prefix}) + elseif("{" STREQUAL "${json_char}") + _sbeMoveToNextNonEmptyCharacter() + _sbeParseObject(${prefix}) + elseif("[" STREQUAL "${json_char}") + _sbeMoveToNextNonEmptyCharacter() + _sbeParseArray(${prefix}) + endif() + + if(${json_index} LESS ${json_jsonLen}) + string(SUBSTRING "${json_string}" ${json_index} 1 json_char) + else() + break() + endif() + + if ("}" STREQUAL "${json_char}" OR "]" STREQUAL "${json_char}") + break() + endif() + + _sbeMoveToNextNonEmptyCharacter() + endwhile() +endmacro() + +macro(_sbeParseNameValue prefix) + set(json_name "") + set(json_inName no) + + while(${json_index} LESS ${json_jsonLen}) + string(SUBSTRING "${json_string}" ${json_index} 1 json_char) + + # check if name ends + if("\"" STREQUAL "${json_char}" AND json_inName) + set(json_inName no) + _sbeMoveToNextNonEmptyCharacter() + if(NOT ${json_index} LESS ${json_jsonLen}) + break() + endif() + string(SUBSTRING "${json_string}" ${json_index} 1 json_char) + set(json_newPrefix ${prefix}.${json_name}) + set(json_name "") + + if(":" STREQUAL "${json_char}") + _sbeMoveToNextNonEmptyCharacter() + if(NOT ${json_index} LESS ${json_jsonLen}) + break() + endif() + string(SUBSTRING "${json_string}" ${json_index} 1 json_char) + + if("\"" STREQUAL "${json_char}") + _sbeParseValue(${json_newPrefix}) + break() + elseif("{" STREQUAL "${json_char}") + _sbeMoveToNextNonEmptyCharacter() + _sbeParseObject(${json_newPrefix}) + break() + elseif("[" STREQUAL "${json_char}") + _sbeMoveToNextNonEmptyCharacter() + _sbeParseArray(${json_newPrefix}) + break() + else() + # reserved word starts + _sbeParseReservedWord(${json_newPrefix}) + break() + endif() + else() + # name without value + list(APPEND ${json_AllVariables} ${json_newPrefix}) + set(${json_newPrefix} "") + break() + endif() + endif() + + if(json_inName) + # remove escapes + if("\\" STREQUAL "${json_char}") + math(EXPR json_index "${json_index} + 1") + if(NOT ${json_index} LESS ${json_jsonLen}) + break() + endif() + string(SUBSTRING "${json_string}" ${json_index} 1 json_char) + endif() + + set(json_name "${json_name}${json_char}") + endif() + + # check if name starts + if("\"" STREQUAL "${json_char}" AND NOT json_inName) + set(json_inName yes) + endif() + + _sbeMoveToNextNonEmptyCharacter() + endwhile() +endmacro() + +macro(_sbeParseReservedWord prefix) + set(json_reservedWord "") + set(json_end no) + while(${json_index} LESS ${json_jsonLen} AND NOT json_end) + string(SUBSTRING "${json_string}" ${json_index} 1 json_char) + + if("," STREQUAL "${json_char}" OR "}" STREQUAL "${json_char}" OR "]" STREQUAL "${json_char}") + set(json_end yes) + else() + set(json_reservedWord "${json_reservedWord}${json_char}") + math(EXPR json_index "${json_index} + 1") + endif() + endwhile() + + list(APPEND ${json_AllVariables} ${prefix}) + string(STRIP "${json_reservedWord}" json_reservedWord) + set(${prefix} ${json_reservedWord}) +endmacro() + +macro(_sbeParseValue prefix) + cmake_policy(SET CMP0054 NEW) # turn off implicit expansions in if statement + + set(json_value "") + set(json_inValue no) + + while(${json_index} LESS ${json_jsonLen}) + # fast path for copying strings + if (json_inValue) + # attempt to gobble up to 128 bytes of string + string(SUBSTRING "${json_string}" ${json_index} 128 try_gobble) + # consume a piece of string we can just straight copy before encountering \ or " + string(REGEX MATCH "^[^\"\\\\]+" simple_copy "${try_gobble}") + string(CONCAT json_value "${json_value}" "${simple_copy}") + string(LENGTH "${simple_copy}" copy_length) + math(EXPR json_index "${json_index} + ${copy_length}") + endif() + + string(SUBSTRING "${json_string}" ${json_index} 1 json_char) + + # check if json_value ends, it is ended by " + if("\"" STREQUAL "${json_char}" AND json_inValue) + set(json_inValue no) + + set(${prefix} ${json_value}) + list(APPEND ${json_AllVariables} ${prefix}) + _sbeMoveToNextNonEmptyCharacter() + break() + endif() + + if(json_inValue) + # if " is escaped consume + if("\\" STREQUAL "${json_char}") + math(EXPR json_index "${json_index} + 1") + if(NOT ${json_index} LESS ${json_jsonLen}) + break() + endif() + string(SUBSTRING "${json_string}" ${json_index} 1 json_char) + if(NOT "\"" STREQUAL "${json_char}") + # if it is not " then copy also escape character + set(json_char "\\${json_char}") + endif() + endif() + + _sbeAddEscapedCharacter("${json_char}") + endif() + + # check if value starts + if("\"" STREQUAL "${json_char}" AND NOT json_inValue) + set(json_inValue yes) + endif() + + math(EXPR json_index "${json_index} + 1") + endwhile() +endmacro() + +macro(_sbeAddEscapedCharacter char) + string(CONCAT json_value "${json_value}" "${char}") +endmacro() + +macro(_sbeParseObject prefix) + _sbeParse(${prefix}) + _sbeMoveToNextNonEmptyCharacter() +endmacro() + +macro(_sbeParseArray prefix) + math(EXPR json_ArrayNestingLevel "${json_ArrayNestingLevel} + 1") + set(json_${json_ArrayNestingLevel}_arrayIndex 0) + + set(${prefix} "") + list(APPEND ${json_AllVariables} ${prefix}) + + while(${json_index} LESS ${json_jsonLen}) + string(SUBSTRING "${json_string}" ${json_index} 1 json_char) + + if("\"" STREQUAL "${json_char}") + # simple value + list(APPEND ${prefix} ${json_${json_ArrayNestingLevel}_arrayIndex}) + _sbeParseValue(${prefix}_${json_${json_ArrayNestingLevel}_arrayIndex}) + elseif("{" STREQUAL "${json_char}") + # object + _sbeMoveToNextNonEmptyCharacter() + list(APPEND ${prefix} ${json_${json_ArrayNestingLevel}_arrayIndex}) + _sbeParseObject(${prefix}_${json_${json_ArrayNestingLevel}_arrayIndex}) + else() + list(APPEND ${prefix} ${json_${json_ArrayNestingLevel}_arrayIndex}) + _sbeParseReservedWord(${prefix}_${json_${json_ArrayNestingLevel}_arrayIndex}) + endif() + + if(NOT ${json_index} LESS ${json_jsonLen}) + break() + endif() + + string(SUBSTRING "${json_string}" ${json_index} 1 json_char) + + if("]" STREQUAL "${json_char}") + _sbeMoveToNextNonEmptyCharacter() + break() + elseif("," STREQUAL "${json_char}") + math(EXPR json_${json_ArrayNestingLevel}_arrayIndex "${json_${json_ArrayNestingLevel}_arrayIndex} + 1") + endif() + + _sbeMoveToNextNonEmptyCharacter() + endwhile() + + if(${json_MaxArrayNestingLevel} LESS ${json_ArrayNestingLevel}) + set(json_MaxArrayNestingLevel ${json_ArrayNestingLevel}) + endif() + math(EXPR json_ArrayNestingLevel "${json_ArrayNestingLevel} - 1") +endmacro() + +macro(_sbeMoveToNextNonEmptyCharacter) + math(EXPR json_index "${json_index} + 1") + if(${json_index} LESS ${json_jsonLen}) + string(SUBSTRING "${json_string}" ${json_index} 1 json_char) + while(${json_char} MATCHES "[ \t\n\r]" AND ${json_index} LESS ${json_jsonLen}) + math(EXPR json_index "${json_index} + 1") + string(SUBSTRING "${json_string}" ${json_index} 1 json_char) + endwhile() + endif() +endmacro() diff --git a/scripts/cmake/json-cmake/LICENSE b/scripts/cmake/json-cmake/LICENSE new file mode 100644 index 00000000000..18037896e4d --- /dev/null +++ b/scripts/cmake/json-cmake/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2015 Stefan Bellus + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE.