Skip to content

Commit 82ba326

Browse files
authored
Fix esmx module paths and package linking (#283)
* fix bug in variable name for ESMX_LINK_MODULE_PATHS * add capability to find packages before expanding variables * add capability to provide a full path to link library * fix documentation for link_packages
1 parent bfe22b5 commit 82ba326

File tree

3 files changed

+63
-35
lines changed

3 files changed

+63
-35
lines changed

src/addon/ESMX/Driver/CMakeLists.txt

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,19 @@ execute_process(COMMAND ${Python_EXECUTABLE}
3232
${CMAKE_CURRENT_LIST_DIR}/esmx_app_config.py --ifile ${ESMX_BUILD_FILE} --odir ${CMAKE_CURRENT_BINARY_DIR}
3333
RESULT_VARIABLE ret)
3434
esmx_check_ret(${ret} "esmx_app_config.py failed processing ${ESMX_BUILD_FILE}")
35+
36+
include(${CMAKE_CURRENT_BINARY_DIR}/modConf.txt)
37+
38+
# add module paths
39+
foreach(ESMX_CMAKE_MODULE_PATH IN ITEMS ${ESMX_LINK_MODULE_PATHS})
40+
list(APPEND CMAKE_MODULE_PATH ${ESMX_CMAKE_MODULE_PATH})
41+
endforeach()
42+
43+
# link packages
44+
foreach(ESMX_LINK_PACKAGE IN ITEMS ${ESMX_LINK_PACKAGES})
45+
find_package(${ESMX_LINK_PACKAGE} REQUIRED)
46+
endforeach()
47+
3548
include(${CMAKE_CURRENT_BINARY_DIR}/appConf.txt)
3649

3750
# disabled components
@@ -121,24 +134,16 @@ add_library(esmx_driver ESMX_Driver.F90)
121134
target_include_directories(esmx_driver PUBLIC ${CMAKE_CURRENT_BINARY_DIR})
122135
target_link_libraries(esmx_driver PUBLIC ESMF)
123136

124-
# add module paths
125-
foreach(ESMX_CMAKE_MODULE_PATH IN ITEMS ${ESMX_CMAKE_MODULE_PATHS})
126-
list(APPEND CMAKE_MODULE_PATH ${ESMX_CMAKE_MODULE_PATH})
127-
endforeach()
128-
129-
# link packages
130-
foreach(ESMX_LINK_PACKAGE IN ITEMS ${ESMX_LINK_PACKAGES})
131-
find_package(${ESMX_LINK_PACKAGE} REQUIRED)
132-
endforeach()
133-
134137
# link external libraries
135138
foreach(ESMX_LINK_LIBRARY IN ITEMS ${ESMX_LINK_LIBRARIES})
136139
if(TARGET ${ESMX_LINK_LIBRARY})
137140
target_link_libraries(esmx_driver PUBLIC ${ESMX_LINK_LIBRARY})
138141
else()
142+
get_filename_component(FND_LIB_PATH ${ESMX_LINK_LIBRARY} DIRECTORY)
143+
get_filename_component(FND_LIB_NAME ${ESMX_LINK_LIBRARY} NAME)
139144
find_library(FND_LINK_LIBRARY
140-
NAMES ${ESMX_LINK_LIBRARY}
141-
HINTS ${ESMX_LINK_PATHS}
145+
NAMES ${FND_LIB_NAME}
146+
HINTS ${ESMX_LINK_PATHS} ${FND_LIB_PATH}
142147
PATH_SUFFIXES "." "lib" "lib64"
143148
NO_CACHE
144149
)
@@ -147,6 +152,8 @@ foreach(ESMX_LINK_LIBRARY IN ITEMS ${ESMX_LINK_LIBRARIES})
147152
endif()
148153
target_link_libraries(esmx_driver PUBLIC ${FND_LINK_LIBRARY})
149154
unset(FND_LINK_LIBRARY)
155+
unset(FND_LIB_PATH)
156+
unset(FND_LIB_NAME)
150157
endif()
151158
endforeach()
152159

src/addon/ESMX/Driver/esmx_app_config.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,31 @@
33
import argparse
44
from esmx_tools import *
55

6+
def create_modConf(appCfg: ESMXAppCfg, odir):
7+
options = [ESMXOpt('link_module_paths', None, dir),
8+
ESMXOpt('link_packages', None, str)]
9+
# open file
10+
with open(os.path.join(odir, 'modConf.txt'), 'w') as f:
11+
for opt in options:
12+
val = appCfg.get(opt.option, opt.default)
13+
if (val):
14+
val = str(val)
15+
val = val.replace(" ", ";")
16+
val = val.replace(",", ";")
17+
if (opt.ctype == dir):
18+
dirs = list(val.split(";"))
19+
for i in range(len(dirs)):
20+
dirs[i] = dirs[i].strip()
21+
if not dirs[i].startswith('$'):
22+
dirs[i] = os.path.abspath(dirs[i])
23+
val = ';'.join(dirs)
24+
f.write('set(ESMX_{} {})\n'.format(opt.upper(), val))
25+
626
def create_appConf(appCfg: ESMXAppCfg, odir):
727
options = [ESMXOpt('exe_name', None, str),
828
ESMXOpt('disable_comps', None, str),
9-
ESMXOpt('link_module_paths', None, dir),
1029
ESMXOpt('link_paths', None, dir),
1130
ESMXOpt('link_libraries', None, str),
12-
ESMXOpt('link_packages', None, str),
1331
ESMXOpt('build_args', None, str),
1432
ESMXOpt('build_jobs', None, str),
1533
ESMXOpt('build_verbose', None, str),
@@ -59,6 +77,9 @@ def main(argv):
5977
# read app configuration yaml file
6078
appCfg = ESMXAppCfg(ifile)
6179

80+
# create modConf.txt for CMake
81+
create_modConf(appCfg, odir)
82+
6283
# create appConf.txt for CMake
6384
create_appConf(appCfg, odir)
6485

src/addon/ESMX/README.md

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -121,27 +121,27 @@ There are *three* top level sections recognized in the ESMX build file. Each is
121121

122122
These options affect the ESMX application layer. If no key/value pair is provided then the default will be used.
123123

124-
| Option key | Description / Value options | Default |
125-
| --------------------- | ----------------------------------------------------- | ---------------------- |
126-
| `exe_name` | executable name for application | `esmx_app` |
127-
| `disable_comps` | scalar or list of components to disable | *None* |
128-
| `link_module_paths` | scalar or list of search paths for CMake modules | *None* |
129-
| `link_packages` | scalar or list of cmake packages, linked to esmx | *None* |
130-
| `link_paths` | scalar or list of search path for external libraries | *None* |
131-
| `link_libraries` | scalar or list of external libraries, linked to esmx | *None* |
132-
| `build_args` | scalar or list of arguments passed to all build_types | *None* |
133-
| `build_jobs` | job number used for all build_types | *None* |
134-
| `build_verbose` | verbosity setting used for all build_types | *None* |
135-
| `cmake_build_args` | scalar or list of argumens passed to all cmake builds | *None* |
136-
| `cmake_build_jobs` | job number used for all cmake builds | *None* |
137-
| `cmake_build_verbose` | verbosity setting used for all cmake builds | *None* |
138-
| `make_build_args` | scalar or list of argumens passed to all make builds | *None* |
139-
| `make_build_jobs` | job number used for all make builds | *None* |
140-
| `script_build_args` | scalar or list of argumens passed to all script builds| *None* |
141-
| `test` | (beta) add test cases: `on` or `off` | `off` |
142-
| `test_exe` | (beta) executable used to launch test cases | ESMF_INTERNAL_MPIRUN |
143-
| `test_dir` | (beta) output directory for test cases | CMAKE_BINARY_DIR-tests |
144-
| `test_tasks` | (beta) number of tasks used to run test cases | `4` |
124+
| Option key | Description / Value options | Default |
125+
| --------------------- | -------------------------------------------------------------------- | ---------------------- |
126+
| `exe_name` | executable name for application | `esmx_app` |
127+
| `disable_comps` | scalar or list of components to disable | *None* |
128+
| `link_module_paths` | scalar or list of search paths for CMake modules | *None* |
129+
| `link_packages` | scalar or list of cmake packages, use link_libraries to link to esmx | *None* |
130+
| `link_paths` | scalar or list of search path for external libraries | *None* |
131+
| `link_libraries` | scalar or list of external libraries, linked to esmx | *None* |
132+
| `build_args` | scalar or list of arguments passed to all build_types | *None* |
133+
| `build_jobs` | job number used for all build_types | *None* |
134+
| `build_verbose` | verbosity setting used for all build_types | *None* |
135+
| `cmake_build_args` | scalar or list of argumens passed to all cmake builds | *None* |
136+
| `cmake_build_jobs` | job number used for all cmake builds | *None* |
137+
| `cmake_build_verbose` | verbosity setting used for all cmake builds | *None* |
138+
| `make_build_args` | scalar or list of argumens passed to all make builds | *None* |
139+
| `make_build_jobs` | job number used for all make builds | *None* |
140+
| `script_build_args` | scalar or list of argumens passed to all script builds | *None* |
141+
| `test` | (beta) add test cases: `on` or `off` | `off` |
142+
| `test_exe` | (beta) executable used to launch test cases | ESMF_INTERNAL_MPIRUN |
143+
| `test_dir` | (beta) output directory for test cases | CMAKE_BINARY_DIR-tests |
144+
| `test_tasks` | (beta) number of tasks used to run test cases | `4` |
145145

146146
#### Component Options (`components` key)
147147

0 commit comments

Comments
 (0)