Skip to content

Commit 98728e9

Browse files
authored
Merge pull request #257 from blattms/use-hints-precedenting-cache
Pass sibling dirs HINTS to find_package calls for opm-parser.
2 parents 8502fdd + 5c731bf commit 98728e9

File tree

1 file changed

+14
-146
lines changed

1 file changed

+14
-146
lines changed

cmake/Modules/Findopm-parser.cmake

Lines changed: 14 additions & 146 deletions
Original file line numberDiff line numberDiff line change
@@ -18,31 +18,6 @@ else ()
1818
set (OPM_PARSER_QUIET "")
1919
endif ()
2020

21-
find_package(opm-parser CONFIG)
22-
if (opm-parser_FOUND)
23-
find_package(ecl REQUIRED)
24-
set(HAVE_OPM_PARSER 1)
25-
# setting HAVE_ERT is a mega hack here, but some downstreams require it.
26-
# Eventually projets should move on to properly handle dependencies and
27-
# configurations, and Findopm-parser be deprecated
28-
set(HAVE_ERT 1)
29-
set(opm-parser_CONFIG_VARS HAVE_OPM_PARSER HAVE_REGEX HAVE_ERT)
30-
set(opm-parser_LIBRARIES opmparser)
31-
32-
find_package_handle_standard_args(opm-parser
33-
DEFAULT_MSG
34-
opm-parser_LIBRARIES HAVE_OPM_PARSER HAVE_ERT
35-
)
36-
return ()
37-
endif ()
38-
39-
# use lowercase versions of the variables if those are set
40-
if (opm-parser_ROOT)
41-
set (OPM_PARSER_ROOT ${opm-parser_ROOT})
42-
endif ()
43-
if (opm_ROOT)
44-
set (OPM_ROOT ${opm_ROOT})
45-
endif ()
4621

4722
# inherit "suite" root if not specifically set for this library
4823
if ((NOT OPM_PARSER_ROOT) AND OPM_ROOT)
@@ -68,128 +43,21 @@ else ()
6843
"${PROJECT_BINARY_DIR}/../../opm-parser/${BUILD_DIR_SUFFIX}")
6944
endif ()
7045

71-
# use this header as signature
72-
find_path (OPM_PARSER_INCLUDE_DIR
73-
NAMES "opm/parser/eclipse/Parser/Parser.hpp"
74-
HINTS "${OPM_PARSER_ROOT}"
75-
PATHS ${_opm_parser_source}
76-
PATH_SUFFIXES "include"
77-
DOC "Path to OPM parser header files"
78-
${_no_default_path} )
79-
80-
find_path (OPM_PARSER_GEN_INCLUDE_DIR
81-
NAMES "opm/parser/eclipse/Parser/ParserKeywords.hpp"
82-
HINTS "${OPM_PARSER_ROOT}"
83-
PATHS ${_opm_parser_build}
84-
PATH_SUFFIXES "generated-source/include" "include"
85-
DOC "Path to OPM parser generated header files"
86-
${_no_default_path} )
87-
88-
89-
# backup: if we didn't find any headers there, but a CMakeCache.txt,
90-
# then it is probably a build directory; read the CMake cache of
91-
# opm-parser to figure out where the source directory is
92-
if ((NOT OPM_PARSER_INCLUDE_DIR) AND
93-
(OPM_PARSER_ROOT AND (EXISTS "${OPM_PARSER_ROOT}/CMakeCache.txt")))
94-
set (_regex "^OPMParser_SOURCE_DIR:STATIC=\(.*\)$")
95-
file (STRINGS
96-
"${OPM_PARSER_ROOT}/CMakeCache.txt"
97-
_cache_entry
98-
REGEX "${_regex}")
99-
string(REGEX REPLACE "${_regex}" "\\1"
100-
OPM_PARSER_INCLUDE_DIR
101-
"${_cache_entry}")
102-
if (OPM_PARSER_INCLUDE_DIR)
103-
set (OPM_PARSER_INCLUDE_DIR "${OPM_PARSER_INCLUDE_DIR}"
104-
CACHE PATH "Path to OPM parser header files" FORCE)
105-
endif ()
106-
endif ()
107-
108-
# find out the size of a pointer. this is required to only search for
109-
# libraries in the directories relevant for the architecture
110-
if (CMAKE_SIZEOF_VOID_P)
111-
math (EXPR _BITS "8 * ${CMAKE_SIZEOF_VOID_P}")
112-
endif ()
11346

114-
# these libraries constitute the parser core
115-
find_library (OPM_PARSER_LIBRARY
116-
NAMES "opmparser"
117-
HINTS "${OPM_PARSER_ROOT}"
118-
PATHS ${_opm_parser_build}
119-
PATH_SUFFIXES "lib" "lib${_BITS}" "lib/${CMAKE_LIBRARY_ARCHITECTURE}"
120-
"opm/parser/eclipse"
121-
DOC "Path to OPM parser library archive/shared object files"
122-
${_no_default_path} )
123-
124-
# find the OPM-parser wrapper library around cJSON
125-
find_library (OPM_JSON_LIBRARY
126-
NAMES "opmjson"
127-
HINTS "${OPM_PARSER_ROOT}"
128-
PATHS ${_opm_parser_build}
129-
PATH_SUFFIXES "lib" "lib${_BITS}" "lib/${CMAKE_LIBRARY_ARCHITECTURE}"
130-
"opm/json"
131-
DOC "Path to OPM JSON library archive/shared object files"
132-
${_no_default_path} )
133-
134-
# get the prerequisite Boost libraries
135-
find_package(Boost 1.44.0 COMPONENTS filesystem date_time system unit_test_framework regex ${OPM_PARSER_QUIET})
136-
137-
if (Boost_FOUND AND
138-
OPM_PARSER_LIBRARY AND OPM_JSON_LIBRARY AND OPM_PARSER_INCLUDE_DIR)
139-
# setup list of all required libraries to link with opm-parser. notice that
140-
# we use the plural form to get *all* the libraries needed by cjson
141-
set (opm-parser_INCLUDE_DIRS
142-
${OPM_PARSER_INCLUDE_DIR}
143-
${OPM_PARSER_GEN_INCLUDE_DIR}
144-
${Boost_INCLUDE_DIRS})
145-
146-
set (opm-parser_LIBRARIES
147-
${OPM_PARSER_LIBRARY}
148-
${OPM_JSON_LIBRARY}
149-
${Boost_LIBRARIES})
150-
151-
# We might be using an external cJSON library
152-
# but we have to unset the OPM_PARSER_ROOT stuff to find it
153-
# (other NO_DEFAULT_PATH will be set).
154-
set(_OPM_PARSER_ROOT_bak ${OPM_PARSER_ROOT})
155-
set(OPM_PARSER_ROOT "")
156-
find_package(cjson)
157-
set(OPM_PARSER_ROOT ${OPM_PARSER_ROOT_bak})
158-
159-
if (CJSON_FOUND)
160-
# If we do we need to add it to the libs.
161-
set (opm-parser_LIBRARIES
162-
${opm-parser_LIBRARIES}
163-
${CJSON_LIBRARY})
164-
endif (CJSON_FOUND)
165-
166-
# see if we can compile a minimum example
167-
# CMake logical test doesn't handle lists (sic)
168-
include (CMakePushCheckState)
169-
include (CheckCSourceCompiles)
170-
cmake_push_check_state ()
171-
set (CMAKE_REQUIRED_INCLUDES ${opm-parser_INCLUDE_DIRS})
172-
set (CMAKE_REQUIRED_LIBRARIES ${opm-parser_LIBRARIES})
173-
174-
check_cxx_source_compiles (
175-
"#include <cstdlib>
176-
#include <opm/parser/eclipse/Deck/Deck.hpp>
177-
178-
int main (void) {
179-
return EXIT_SUCCESS;
180-
}" HAVE_OPM_PARSER)
181-
cmake_pop_check_state ()
182-
endif()
47+
find_package(opm-parser CONFIG HINTS ${_opm_parser_build})
48+
if (opm-parser_FOUND)
49+
find_package(ecl REQUIRED)
50+
set(HAVE_OPM_PARSER 1)
51+
# setting HAVE_ERT is a mega hack here, but some downstreams require it.
52+
# Eventually projets should move on to properly handle dependencies and
53+
# configurations, and Findopm-parser be deprecated
54+
set(HAVE_ERT 1)
55+
set(opm-parser_CONFIG_VARS HAVE_OPM_PARSER HAVE_REGEX HAVE_ERT)
56+
set(opm-parser_LIBRARIES opmparser)
18357

184-
# if the test program didn't compile, but was required to do so, bail
185-
# out now and display an error; otherwise limp on
186-
set (OPM_PARSER_FIND_REQUIRED ${opm-parser_FIND_REQUIRED})
187-
find_package_handle_standard_args (opm-parser
188-
DEFAULT_MSG
189-
opm-parser_INCLUDE_DIRS opm-parser_LIBRARIES HAVE_OPM_PARSER
58+
find_package_handle_standard_args(opm-parser
59+
DEFAULT_MSG
60+
opm-parser_LIBRARIES HAVE_OPM_PARSER HAVE_ERT
19061
)
62+
endif ()
19163

192-
set (opm-parser_CONFIG_VARS "HAVE_OPM_PARSER;HAVE_REGEX")
193-
set (opm-parser_FOUND ${OPM-PARSER_FOUND})
194-
195-
mark_as_advanced(opm-parser_LIBRARIES opm-parser_INCLUDE_DIRS OPM-PARSER_FOUND)

0 commit comments

Comments
 (0)