Merge pull request #418 from joakim-hove/cmake-find-opm-parser
Add cmake capabailities to locate opm-parser and cJSON
This commit is contained in:
89
cmake/Modules/Findcjson.cmake
Normal file
89
cmake/Modules/Findcjson.cmake
Normal file
@@ -0,0 +1,89 @@
|
||||
# Look for the cjson library; will probably newer be found.
|
||||
# If found, it sets these variables:
|
||||
#
|
||||
# CJSON_INCLUDE_DIRS Header file directories
|
||||
# CJSON_LIBRARIES Archive/shared objects
|
||||
|
||||
include (FindPackageHandleStandardArgs)
|
||||
|
||||
if ((NOT CJSON_ROOT) AND OPM_PARSER_ROOT)
|
||||
set( CJSON_ROOT ${OPM_PARSER_ROOT})
|
||||
endif()
|
||||
|
||||
if (CJSON_ROOT)
|
||||
set (_no_default_path "NO_DEFAULT_PATH")
|
||||
else (CJSON_ROOT)
|
||||
set (_no_default_path "")
|
||||
endif (CJSON_ROOT)
|
||||
|
||||
|
||||
find_path (CJSON_INCLUDE_DIR
|
||||
NAMES "cjson/cJSON.h"
|
||||
HINTS "${CJSON_ROOT}"
|
||||
PATHS "${PROJECT_SOURCE_DIR}" "${PROJECT_SOURCE_DIR}/../opm-parser"
|
||||
PATH_SUFFIXES "include" "opm/json"
|
||||
DOC "Path to cjson library header files"
|
||||
${_no_default_path} )
|
||||
|
||||
# find out the size of a pointer. this is required to only search for
|
||||
# libraries in the directories relevant for the architecture
|
||||
if (CMAKE_SIZEOF_VOID_P)
|
||||
math (EXPR _BITS "8 * ${CMAKE_SIZEOF_VOID_P}")
|
||||
endif (CMAKE_SIZEOF_VOID_P)
|
||||
|
||||
find_library (CJSON_LIBRARY
|
||||
NAMES "cjson"
|
||||
HINTS "${CJSON_ROOT}"
|
||||
PATHS "${PROJECT_BINARY_DIR}/../opm-parser"
|
||||
"${PROJECT_BINARY_DIR}/../opm-parser-build"
|
||||
"${PROJECT_BINARY_DIR}/../../opm-parser/build"
|
||||
"${PROJECT_BINARY_DIR}/../../opm-parser/cmake-build"
|
||||
PATH_SUFFIXES "lib" "lib${_BITS}" "lib/${CMAKE_LIBRARY_ARCHITECTURE}"
|
||||
"opm/json"
|
||||
DOC "Path to cjson library archive/shared object files"
|
||||
${_no_default_path} )
|
||||
|
||||
# setup list of all required libraries to link with cjson
|
||||
set (CJSON_INCLUDE_DIRS ${CJSON_INCLUDE_DIR})
|
||||
set (CJSON_LIBRARIES ${CJSON_LIBRARY})
|
||||
|
||||
# math library (should exist on all unices; automatically linked on Windows)
|
||||
if (UNIX)
|
||||
find_library (MATH_LIBRARY NAMES "m")
|
||||
list (APPEND CJSON_LIBRARIES ${MATH_LIBRARY})
|
||||
endif (UNIX)
|
||||
|
||||
# see if we can compile a minimum example
|
||||
# CMake logical test doesn't handle lists (sic)
|
||||
if (NOT (CJSON_INCLUDE_DIRS MATCHES "-NOTFOUND" OR CJSON_LIBRARIES MATCHES "-NOTFOUND"))
|
||||
include (CMakePushCheckState)
|
||||
include (CheckCSourceCompiles)
|
||||
cmake_push_check_state ()
|
||||
set (CMAKE_REQUIRED_INCLUDES ${CJSON_INCLUDE_DIRS})
|
||||
set (CMAKE_REQUIRED_LIBRARIES ${CJSON_LIBRARIES})
|
||||
|
||||
check_c_source_compiles (
|
||||
"#include <stdlib.h>
|
||||
#include <cjson/cJSON.h>
|
||||
int main (void) {
|
||||
cJSON root;
|
||||
return 0;
|
||||
}" HAVE_CJSON)
|
||||
cmake_pop_check_state ()
|
||||
else ()
|
||||
# clear the cache so the find probe is attempted again if files becomes
|
||||
# available (only upon a unsuccessful *compile* should we disable further
|
||||
# probing)
|
||||
set (HAVE_CJSON)
|
||||
unset (HAVE_CJSON CACHE)
|
||||
endif ()
|
||||
|
||||
# if the test program didn't compile, but was required to do so, bail
|
||||
# out now and display an error; otherwise limp on
|
||||
set (CJSON_FIND_REQUIRED ${cjson_FIND_REQUIRED})
|
||||
set (CJSON_FIND_QUIETLY ${cjson_FIND_QUIETLY})
|
||||
find_package_handle_standard_args (CJSON
|
||||
DEFAULT_MSG
|
||||
CJSON_INCLUDE_DIRS CJSON_LIBRARIES HAVE_CJSON
|
||||
)
|
||||
set (cjson_FOUND ${CJSON_FOUND})
|
||||
160
cmake/Modules/Findopm-parser.cmake
Normal file
160
cmake/Modules/Findopm-parser.cmake
Normal file
@@ -0,0 +1,160 @@
|
||||
# Find the OPM Eclipse input parser.
|
||||
#
|
||||
# Set the cache variable OPM_PARSER_ROOT to the install location of the
|
||||
# library, or OPM_ROOT to the parent directory of the build tree.
|
||||
#
|
||||
# If found, it sets these variables:
|
||||
#
|
||||
# HAVE_OPM_PARSER Defined if a test program compiled
|
||||
# OPM_PARSER_INCLUDE_DIRS Header file directories
|
||||
# OPM_PARSER_LIBRARIES Archives and shared objects
|
||||
|
||||
include (FindPackageHandleStandardArgs)
|
||||
|
||||
# variables to pass on to other packages
|
||||
if (FIND_QUIETLY)
|
||||
set (OPM_PARSER_QUIET "QUIET")
|
||||
else ()
|
||||
set (OPM_PARSER_QUIET "")
|
||||
endif ()
|
||||
|
||||
# use lowercase versions of the variables if those are set
|
||||
if (opm-parser_ROOT)
|
||||
set (OPM_PARSER_ROOT ${opm-parser_ROOT})
|
||||
endif ()
|
||||
if (opm_ROOT)
|
||||
set (OPM_ROOT ${opm_ROOT})
|
||||
endif ()
|
||||
|
||||
# inherit "suite" root if not specifically set for this library
|
||||
if ((NOT OPM_PARSER_ROOT) AND OPM_ROOT)
|
||||
set (OPM_PARSER_ROOT "${OPM_ROOT}/opm-parser")
|
||||
endif ()
|
||||
|
||||
# if a root is specified, then don't search in system directories
|
||||
# or in relative directories to this one
|
||||
if (OPM_PARSER_ROOT)
|
||||
set (_no_default_path "NO_DEFAULT_PATH")
|
||||
set (_opm_parser_source "")
|
||||
set (_opm_parser_build "")
|
||||
else ()
|
||||
set (_no_default_path "")
|
||||
set (_opm_parser_source
|
||||
"${PROJECT_SOURCE_DIR}/../opm-parser")
|
||||
set (_opm_parser_build
|
||||
"${PROJECT_BINARY_DIR}/../opm-parser"
|
||||
"${PROJECT_BINARY_DIR}/../opm-parser-build"
|
||||
"${PROJECT_BINARY_DIR}/../../opm-parser/build"
|
||||
"${PROJECT_BINARY_DIR}/../../opm-parser/cmake-build")
|
||||
endif ()
|
||||
|
||||
# use this header as signature
|
||||
find_path (OPM_PARSER_INCLUDE_DIR
|
||||
NAMES "opm/parser/eclipse/Parser/Parser.hpp"
|
||||
HINTS "${OPM_PARSER_ROOT}"
|
||||
PATHS ${_opm_parser_source}
|
||||
PATH_SUFFIXES "include"
|
||||
DOC "Path to OPM parser header files"
|
||||
${_no_default_path} )
|
||||
|
||||
# backup: if we didn't find any headers there, but a CMakeCache.txt,
|
||||
# then it is probably a build directory; read the CMake cache of
|
||||
# opm-parser to figure out where the source directory is
|
||||
if ((NOT OPM_PARSER_INCLUDE_DIR) AND
|
||||
(OPM_PARSER_ROOT AND (EXISTS "${OPM_PARSER_ROOT}/CMakeCache.txt")))
|
||||
set (_regex "^OPMParser_SOURCE_DIR:STATIC=\(.*\)$")
|
||||
file (STRINGS
|
||||
"${OPM_PARSER_ROOT}/CMakeCache.txt"
|
||||
_cache_entry
|
||||
REGEX "${_regex}")
|
||||
string(REGEX REPLACE "${_regex}" "\\1"
|
||||
OPM_PARSER_INCLUDE_DIR
|
||||
"${_cache_entry}")
|
||||
if (OPM_PARSER_INCLUDE_DIR)
|
||||
set (OPM_PARSER_INCLUDE_DIR "${OPM_PARSER_INCLUDE_DIR}"
|
||||
CACHE PATH "Path to OPM parser header files" FORCE)
|
||||
endif ()
|
||||
endif ()
|
||||
|
||||
# find out the size of a pointer. this is required to only search for
|
||||
# libraries in the directories relevant for the architecture
|
||||
if (CMAKE_SIZEOF_VOID_P)
|
||||
math (EXPR _BITS "8 * ${CMAKE_SIZEOF_VOID_P}")
|
||||
endif (CMAKE_SIZEOF_VOID_P)
|
||||
|
||||
# these libraries constitute the parser core
|
||||
find_library (OPM_PARSER_LIBRARY
|
||||
NAMES "Parser"
|
||||
HINTS "${OPM_PARSER_ROOT}"
|
||||
PATHS ${_opm_parser_build}
|
||||
PATH_SUFFIXES "lib" "lib${_BITS}" "lib/${CMAKE_LIBRARY_ARCHITECTURE}"
|
||||
"opm/parser/eclipse"
|
||||
DOC "Path to OPM parser library archive/shared object files"
|
||||
${_no_default_path} )
|
||||
|
||||
find_library (OPM_JSON_LIBRARY
|
||||
NAMES "opm-json"
|
||||
HINTS "${OPM_PARSER_ROOT}"
|
||||
PATHS ${_opm_parser_build}
|
||||
PATH_SUFFIXES "lib" "lib${_BITS}" "lib/${CMAKE_LIBRARY_ARCHITECTURE}"
|
||||
"opm/json"
|
||||
DOC "Path to OPM JSON library archive/shared object files"
|
||||
${_no_default_path} )
|
||||
|
||||
# get the prerequisite CJSON library
|
||||
if (NOT CJSON_FOUND)
|
||||
find_package (cjson REQUIRED ${OPM_PARSER_QUIET})
|
||||
endif ()
|
||||
|
||||
# get the prerequisite Boost libraries
|
||||
if (NOT Boost_FOUND)
|
||||
find_package(Boost 1.44.0
|
||||
COMPONENTS filesystem date_time system unit_test_framework REQUIRED ${OPM_PARSER_QUIET})
|
||||
endif ()
|
||||
|
||||
# setup list of all required libraries to link with opm-parser. notice that
|
||||
# we use the plural form to get *all* the libraries needed by cjson
|
||||
set (OPM_PARSER_INCLUDE_DIRS
|
||||
${OPM_PARSER_INCLUDE_DIR}
|
||||
${Boost_INCLUDE_DIRS})
|
||||
set (OPM_PARSER_LIBRARIES
|
||||
${OPM_PARSER_LIBRARY}
|
||||
${OPM_JSON_LIBRARY}
|
||||
${CJSON_LIBRARIES}
|
||||
${Boost_LIBRARIES})
|
||||
|
||||
# see if we can compile a minimum example
|
||||
# CMake logical test doesn't handle lists (sic)
|
||||
if (NOT (OPM_PARSER_INCLUDE_DIR MATCHES "-NOTFOUND"
|
||||
OR OPM_PARSER_LIBRARIES MATCHES "-NOTFOUND"))
|
||||
include (CMakePushCheckState)
|
||||
include (CheckCSourceCompiles)
|
||||
cmake_push_check_state ()
|
||||
set (CMAKE_REQUIRED_INCLUDES ${OPM_PARSER_INCLUDE_DIRS})
|
||||
set (CMAKE_REQUIRED_LIBRARIES ${OPM_PARSER_LIBRARIES})
|
||||
|
||||
check_cxx_source_compiles (
|
||||
"#include <cstdlib>
|
||||
#include <opm/parser/eclipse/Parser/Parser.hpp>
|
||||
|
||||
int main (void) {
|
||||
return EXIT_SUCCESS;
|
||||
}" HAVE_OPM_PARSER)
|
||||
cmake_pop_check_state ()
|
||||
else ()
|
||||
# clear the cache so the find probe is attempted again if files becomes
|
||||
# available (only upon a unsuccessful *compile* should we disable further
|
||||
# probing)
|
||||
set (HAVE_OPM_PARSER)
|
||||
unset (HAVE_OPM_PARSER CACHE)
|
||||
endif ()
|
||||
|
||||
# if the test program didn't compile, but was required to do so, bail
|
||||
# out now and display an error; otherwise limp on
|
||||
set (OPM_PARSER_FIND_REQUIRED ${opm-parser_FIND_REQUIRED})
|
||||
set (OPM_PARSER_FIND_QUIETLY ${opm-parser_FIND_QUIETLY})
|
||||
find_package_handle_standard_args (OPM_PARSER
|
||||
DEFAULT_MSG
|
||||
OPM_PARSER_INCLUDE_DIRS OPM_PARSER_LIBRARIES HAVE_OPM_PARSER
|
||||
)
|
||||
set (opm-parser_FOUND ${OPM_PARSER_FOUND})
|
||||
18
cmake/Modules/opm-parser-prereqs.cmake
Normal file
18
cmake/Modules/opm-parser-prereqs.cmake
Normal file
@@ -0,0 +1,18 @@
|
||||
# -*- mode: cmake; tab-width: 2; indent-tabs-mode: t; truncate-lines: t; compile-command: "cmake -Wdev" -*-
|
||||
# vim: set filetype=cmake autoindent tabstop=2 shiftwidth=2 noexpandtab softtabstop=2 nowrap:
|
||||
|
||||
# defines that must be present in config.h for our headers
|
||||
set (opm-parser_CONFIG_VAR
|
||||
HAVE_ERT
|
||||
)
|
||||
|
||||
# dependencies
|
||||
set (opm-parser_DEPS
|
||||
# compile with C99 support if available
|
||||
"C99"
|
||||
# compile with C++0x/11 support if available
|
||||
"CXX11Features REQUIRED"
|
||||
# various runtime library enhancements
|
||||
"Boost 1.39.0
|
||||
COMPONENTS date_time filesystem system unit_test_framework REQUIRED"
|
||||
)
|
||||
Reference in New Issue
Block a user