@@ -6,7 +6,7 @@ create the cam library
66# pylint: disable=multiple-imports, wrong-import-position, wildcard-import
77# pylint: disable=unused-wildcard-import, bad-whitespace, too-many-locals
88# pylint: disable=invalid-name
9- import sys , os , filecmp , shutil
9+ import sys , os , filecmp , shutil , re
1010from glob import glob
1111
1212_CIMEROOT = os .environ .get ("CIMEROOT" )
@@ -232,60 +232,76 @@ def _build_tuvx(caseroot, libroot, bldroot):
232232# Builds the TUV-x library and updates the case variables used to set the
233233# include paths and linked libraries
234234
235- with Case (caseroot ) as case :
236- bldpath = os .path .join (bldroot , "tuv-x" )
237- if not os .path .exists (bldpath ):
238- os .makedirs (bldpath )
239- srcpath = os .path .abspath (os .path .join (case .get_value ("SRCROOT" ), \
240- "libraries" , "tuv-x" , "" ))
241- logger .info ("Building TUV-x in {} from source in {}\n " .format (bldpath , srcpath ))
242-
243- arg_dict = _cmake_default_args (caseroot )
244- cmake_args = "-DCMAKE_VERBOSE_MAKEFILE=ON "
245- if case .get_value ("MPILIB" ) != "mpi-serial" :
246- cmake_args += "-DTUVX_ENABLE_MPI:BOOL=TRUE "
247- cmake_args += "-DCMAKE_BUILD_TYPE=Debug "
248- cmake_args += "-DCMAKE_Fortran_COMPILER=mpif90 "
249- cmake_args += "-DCMAKE_C_COMPILER=mpicc "
250- cmake_args += "-DCMAKE_CXX_COMPILER=mpicxx "
251- cmake_args += "-DCMAKE_Fortran_COMPILER_WORKS=1 "
252- cmake_args += "-DCMAKE_C_COMPILER_WORKS=1 "
253- cmake_args += "-DCMAKE_CXX_COMPILER_WORKS=1 "
254- if (case .get_value ("MACH" ) == "izumi" ) :
255- cmake_args += f"-DCMAKE_PREFIX_PATH={ arg_dict ['NETCDF_PATH' ]} "
256- cmake_args += f"-DCMAKE_IGNORE_PATH={ os .environ .get ('PYTHONHOME' )} "
257- if (case .get_value ("MACH" ) == "izumi" ) and (case .get_value ('COMPILER' ) == "nag" ) :
258- cmake_args += "-DCMAKE_Fortran_FLAGS='-C=all -g ' "
259- else :
260- cmake_args += f"-DCMAKE_Fortran_FLAGS='{ arg_dict ['FFLAGS' ]} ' "
261- cmake_args += f"-DCMAKE_INSTALL_PREFIX='{ libroot } ' "
262- cmake_args += "-DTUVX_ENABLE_TESTS=OFF "
263- cmake_args += "-DTUVX_ENABLE_COVERAGE=OFF "
264- cmake_args += "-DTUVX_BUILD_CLI=OFF "
265- cmake_args += f"-DTUVX_INSTALL_INCLUDE_DIR='{ _tuvx_include_dir (libroot )} ' "
266- cmake_args += f"-DTUVX_INSTALL_MOD_DIR='{ _tuvx_include_dir (libroot )} ' "
267- cmake_args += srcpath
268-
269- _run_cmd (f"cmake { cmake_args } " , bldpath )
270- _run_cmd (case .get_value ('GMAKE' ), bldpath )
271- _run_cmd (f"{ case .get_value ('GMAKE' )} install" , bldpath )
272-
273- # add TUV-x to include paths
274- incldir = os .environ .get ('USER_INCLDIR' )
275- if incldir is None :
276- incldir = ''
277- os .environ ['USER_INCLDIR' ] = incldir + \
278- f" -I{ _tuvx_include_dir (libroot )} "
279-
280- # create symlink to library in folder CIME expects libraries to be in
281- dst = os .path .join (libroot , "libtuvx.a" )
282- if os .path .isfile (dst ):
283- os .remove (dst )
284- os .symlink (_tuvx_lib_path (libroot ), dst )
285- dst = os .path .join (libroot , "libyaml-cpp.a" )
286- if os .path .isfile (dst ):
287- os .remove (dst )
288- os .symlink (_yaml_cpp_lib_path (libroot ), dst )
235+ with Case (caseroot , read_only = False ) as case :
236+ config_opts = case .get_value ("CAM_CONFIG_OPTS" )
237+
238+ # Remove any TUV-x link options set by a previous build, so that
239+ # re-building the case does not accumulate duplicate or stale
240+ # options in CAM_LINKED_LIBS:
241+ linked_libs = case .get_value ("CAM_LINKED_LIBS" ,
242+ subgroup = "build_component_cam" )
243+ tuvx_link_opts = " -ltuvx -lyaml-cpp"
244+ new_linked_libs = re .sub (r"\s*-ltuvx -lyaml-cpp" , "" , linked_libs )
245+ if "-tuvx" in config_opts :
246+ bldpath = os .path .join (bldroot , "tuv-x" )
247+ if not os .path .exists (bldpath ):
248+ os .makedirs (bldpath )
249+ srcpath = os .path .abspath (os .path .join (case .get_value ("SRCROOT" ), \
250+ "libraries" , "tuv-x" , "" ))
251+ logger .info ("Building TUV-x in {} from source in {}\n " .format (bldpath , srcpath ))
252+
253+ arg_dict = _cmake_default_args (caseroot )
254+ cmake_args = "-DCMAKE_VERBOSE_MAKEFILE=ON "
255+ if case .get_value ("MPILIB" ) != "mpi-serial" :
256+ cmake_args += "-DTUVX_ENABLE_MPI:BOOL=TRUE "
257+ cmake_args += "-DCMAKE_BUILD_TYPE=Debug "
258+ cmake_args += "-DCMAKE_Fortran_COMPILER=mpif90 "
259+ cmake_args += "-DCMAKE_C_COMPILER=mpicc "
260+ cmake_args += "-DCMAKE_CXX_COMPILER=mpicxx "
261+ cmake_args += "-DCMAKE_Fortran_COMPILER_WORKS=1 "
262+ cmake_args += "-DCMAKE_C_COMPILER_WORKS=1 "
263+ cmake_args += "-DCMAKE_CXX_COMPILER_WORKS=1 "
264+ cmake_args += "-DCMAKE_DISABLE_FIND_PACKAGE_yaml-cpp=1 "
265+ if (case .get_value ("MACH" ) == "izumi" ) :
266+ cmake_args += f"-DCMAKE_PREFIX_PATH={ arg_dict ['NETCDF_PATH' ]} "
267+ if (case .get_value ("MACH" ) == "izumi" ) and (case .get_value ('COMPILER' ) == "nag" ) :
268+ cmake_args += "-DCMAKE_Fortran_FLAGS='-C=all -g ' "
269+ else :
270+ cmake_args += f"-DCMAKE_Fortran_FLAGS='{ arg_dict ['FFLAGS' ]} ' "
271+ cmake_args += f"-DCMAKE_INSTALL_PREFIX='{ libroot } ' "
272+ cmake_args += "-DTUVX_ENABLE_TESTS=OFF "
273+ cmake_args += "-DTUVX_ENABLE_COVERAGE=OFF "
274+ cmake_args += "-DTUVX_BUILD_CLI=OFF "
275+ cmake_args += f"-DTUVX_INSTALL_INCLUDE_DIR='{ _tuvx_include_dir (libroot )} ' "
276+ cmake_args += f"-DTUVX_INSTALL_MOD_DIR='{ _tuvx_include_dir (libroot )} ' "
277+ cmake_args += srcpath
278+
279+ _run_cmd (f"cmake { cmake_args } " , bldpath )
280+ _run_cmd (case .get_value ('GMAKE' ), bldpath )
281+ _run_cmd (f"{ case .get_value ('GMAKE' )} install" , bldpath )
282+
283+ # add TUV-x to include paths
284+ incldir = os .environ .get ('USER_INCLDIR' )
285+ if incldir is None :
286+ incldir = ''
287+ os .environ ['USER_INCLDIR' ] = incldir + \
288+ f" -I{ _tuvx_include_dir (libroot )} "
289+
290+ # create symlink to library in folder CIME expects libraries to be in
291+ dst = os .path .join (libroot , "libtuvx.a" )
292+ if os .path .isfile (dst ):
293+ os .remove (dst )
294+ os .symlink (_tuvx_lib_path (libroot ), dst )
295+ dst = os .path .join (libroot , "libyaml-cpp.a" )
296+ if os .path .isfile (dst ):
297+ os .remove (dst )
298+ os .symlink (_yaml_cpp_lib_path (libroot ), dst )
299+
300+ # Add TUVX to CAM linked library list:
301+ new_linked_libs = tuvx_link_opts .strip () + " " + new_linked_libs
302+
303+ if new_linked_libs != linked_libs :
304+ case .set_value ("CAM_LINKED_LIBS" , new_linked_libs )
289305
290306###############################################################################
291307def _tuvx_include_dir (libroot ):
0 commit comments