Skip to content

Commit

Permalink
Additional fixes to V1 cmake macro generation
Browse files Browse the repository at this point in the history
  • Loading branch information
jgfouca committed Aug 30, 2017
1 parent 3646998 commit 35077ea
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions scripts/lib/CIME/BuildTools/macrowriterbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import os
from abc import ABCMeta, abstractmethod
from CIME.XML.standard_module_setup import *
from CIME.utils import get_cime_root
logger = logging.getLogger(__name__)

def _get_components(value):
Expand Down Expand Up @@ -234,14 +235,15 @@ def write_macros_file_v1(macros, compiler, os_, machine, macros_file="Macros", o
'''#
# cmake Macros generated from $compiler_file
#
set(CMAKE_MODULE_PATH %s)
include(Compilers)
set(CMAKE_C_FLAGS_RELEASE "" CACHE STRING "Flags used by c compiler." FORCE)
set(CMAKE_C_FLAGS_DEBUG "" CACHE STRING "Flags used by c compiler." FORCE)
set(CMAKE_Fortran_FLAGS_RELEASE "" CACHE STRING "Flags used by Fortran compiler." FORCE)
set(CMAKE_Fortran_FLAGS_DEBUG "" CACHE STRING "Flags used by Fortran compiler." FORCE)
set(all_build_types "None Debug Release RelWithDebInfo MinSizeRel")
set(CMAKE_BUILD_TYPE "${CMAKE_BUILD_TYPE}" CACHE STRING "Choose the type of build, options are: ${all_build_types}." FORCE)
''')
''' % os.path.join(get_cime_root(), "src", "CMake"))

# print the settings out to the Macros file, do it in
# two passes so that path values appear first in the
Expand All @@ -254,7 +256,10 @@ def write_macros_file_v1(macros, compiler, os_, machine, macros_file="Macros", o
if key.endswith("_PATH"):
if value.startswith("$"):
value = "$ENV{}".format(value[1:])
fd.write("set({} {})\n".format(key, value))


cmake_var = key.replace("NETCDF_PATH", "NetCDF_PATH").replace("PNETCDF_PATH", "Pnetcdf_PATH")
fd.write("set({} {})\n".format(cmake_var, value))
fd.write("list(APPEND CMAKE_PREFIX_PATH {})\n\n".format(value))

for key, value in sorted(macros.iteritems()):
Expand All @@ -268,6 +273,7 @@ def write_macros_file_v1(macros, compiler, os_, machine, macros_file="Macros", o

idx = 0
for is_shell, component in components:
component = component.replace("NETCDF", "NetCDF").replace("PNETCDF_PATH", "Pnetcdf_PATH")
if is_shell:
fd.write('execute_process(COMMAND {} OUTPUT_VARIABLE TEMP{:d})\n'.format(component, idx))
fd.write('string(REGEX REPLACE "\\n$" "" TEMP{:d} "${{TEMP{:d}}}")\n'.format(idx, idx))
Expand All @@ -281,13 +287,13 @@ def write_macros_file_v1(macros, compiler, os_, machine, macros_file="Macros", o
fd.write('set(TEMP "{}")\n'.format(value))

if "CFLAGS" in key:
fd.write("add_flags(CMAKE_C_FLAGS ${TEMP})\n\n")
fd.write("add_flags(CFLAGS ${TEMP})\n\n")
elif "FFLAGS" in key:
fd.write("add_flags(CMAKE_Fortran_FLAGS ${TEMP})\n\n")
fd.write("add_flags(FFLAGS ${TEMP})\n\n")
elif "CPPDEFS" in key:
fd.write("list(APPEND COMPILE_DEFINITIONS ${TEMP})\n\n")
fd.write("list(APPEND CPPDEFS ${TEMP})\n\n")
elif "SLIBS" in key or "LDFLAGS" in key:
fd.write("add_flags(CMAKE_EXE_LINKER_FLAGS ${TEMP})\n\n")
fd.write("add_flags(LDFLAGS ${TEMP})\n\n")

# Recursively print the conditionals, combining tests to avoid repetition
_parse_hash(macros["_COND_"], fd, 0, output_format)
Expand Down

0 comments on commit 35077ea

Please sign in to comment.