Commit a17f3cbb authored by GILLES Sebastien's avatar GILLES Sebastien

#1382 Fix the build script: make it more robust and fix the mode that was not properly read.

parent 7998ecd4
......@@ -19,7 +19,7 @@ class configure_cmake(object):
\n\
There are two reasons to use this script instead of the direct cmake invocation:\n\n\
- There are some options that are often changed (type of library, compiler, whether there is one or more libraries for MoReFEM) and this script allows to limit the number of PreCache files to maintain (one for macOS and one for Linux is enough).\n\
- Keeping the PreCache file with the options actually used is very handfy for external models: we may use it directly when creating the cmake build.\n\
- Keeping the PreCache file with the options actually used is very handy for external models: we may use it directly when creating the cmake build.\n\
\n\
If you need to change a value which is not provided in this script input, you may either introduce it in cmake_args with the -D syntax or just use the --no-run-command flag and edit the generated PreCacheFile.cmake before running the command.',
formatter_class=argparse.RawDescriptionHelpFormatter)
......@@ -28,7 +28,6 @@ If you need to change a value which is not provided in this script input, you ma
self._parse_pre_cache_file()
self._generate_cache_file()
self._cmake_command()
def _interpret_command_line(self, parser):
......@@ -40,6 +39,7 @@ If you need to change a value which is not provided in this script input, you ma
"""
parser.add_argument(
'--cache_file',
required=True,
help=
'The pre-cache file which contains default values for few build options. This argument is the only one that is mandatory; the other ones are optional but may supersede the values written in pre-cache file.'
)
......@@ -57,13 +57,19 @@ If you need to change a value which is not provided in this script input, you ma
help=
"If you want to supersede pre-cache_file cache value, the path of the directory in which all third libraries are installed."
)
def check_mode(value):
if value not in('debug', 'release'):
raise argparse.ArgumentTypeError("Mode should be either 'debug' or 'release'; you chose \'{}\'.".format(value))
return value.title() # Uppercase the first letter.
parser.add_argument(
'--mode',
help=
"Either 'Debug' or 'Release'; if not specified debug mode is chosen."
)
'--mode',
type=check_mode,
help=
"Either 'debug' or 'release'; if not specified debug mode is chosen."
)
parser.add_argument(
'--install_directory',
......@@ -71,20 +77,35 @@ If you need to change a value which is not provided in this script input, you ma
"If you want to supersede pre-cache_file cache value, the directory into which executables and libraries will be installed (in subdirectories)"
)
parser.add_argument(
'--use_sanitizer',
help=
"If you want to supersede pre-cache_file cache value, specify 'True' or 'False' here."
)
# parser.add_argument(
# '--use_sanitizer',
# help=
# "If you want to supersede pre-cache_file cache value, specify 'True' or 'False' here."
# )
def check_library_type(value):
if value not in('shared', 'static'):
raise argparse.ArgumentTypeError("Library type should be either 'shared' or 'static'; you chose \'{}\'.".format(value))
return value.upper()
parser.add_argument(
'--library_type',
type=check_library_type,
help=
"If you want to supersede pre-cache_file cache value, specify 'shared' or 'static' here."
)
def check_boolean(value):
value = value.lower()
if value not in('true', 'false'):
raise argparse.ArgumentTypeError("Value should be 'true' or 'false'")
return value == 'true' and True or False
parser.add_argument(
'--morefem_as_single_library',
type=check_boolean,
help=
"If you want to supersede pre-cache_file cache value, specify 'True' if MoReFEM is to be built as a single library or 'False' if you want several libraries."
)
......@@ -104,9 +125,6 @@ If you need to change a value which is not provided in this script input, you ma
args = parser.parse_args()
if not args.cache_file:
raise Exception("--cache_file is a mandatory argument!")
if not os.path.isfile(args.cache_file):
raise Exception("The cache file '{}' does not exist!".format(
args.cache_file))
......@@ -122,7 +140,7 @@ If you need to change a value which is not provided in this script input, you ma
In output, self.__pre_cache_dict is filled.
"""
possible_keys = ('CMAKE_INSTALL_PREFIX',
'MOREFEM_THIRD_PARTY_LIBRARIES_DIR', 'MOREFEM_ASAN',
'MOREFEM_THIRD_PARTY_LIBRARIES_DIR',
'CMAKE_CXX_STANDARD', 'CMAKE_CXX_STANDARD_REQUIRED',
'CMAKE_CXX_EXTENSIONS', 'LIBRARY_TYPE',
'BUILD_MOREFEM_UNIQUE_LIBRARY',
......@@ -135,8 +153,10 @@ If you need to change a value which is not provided in this script input, you ma
'BOOST_INCL_DIR', 'BOOST_LIB_DIR',
'LUA_INCL_DIR', 'LUA_LIB_DIR',
'PARMETIS_INCL_DIR', 'PARMETIS_LIB_DIR',
'CMAKE_BUILD_TYPE'
'CMAKE_BUILD_TYPE', 'MOREFEM_ASAN'
)
with open(self.__command_line_args.cache_file) as stream:
......@@ -165,7 +185,7 @@ If you need to change a value which is not provided in this script input, you ma
value = " ".join(splitted[1:])
self.__pre_cache_dict[key] = value
def _cache_entry(self, entry_name, cmake_type, cmake_comment, command_line_entry_value = None):
"""
......@@ -176,7 +196,8 @@ If you need to change a value which is not provided in this script input, you ma
\param[in] cmake_comment Comment of the entry in CMake, e.g. "C++ standard; at least 17 is expected."
\param[in] command_line_entry_value: The value read in the command line if any, None otherwise (in which case the one from the pre-cache file is kept).
"""
if command_line_entry_value:
if command_line_entry_value is not None:
print("VALUE = {}".format(command_line_entry_value))
value = command_line_entry_value
else:
try:
......@@ -188,6 +209,9 @@ If you need to change a value which is not provided in this script input, you ma
entry = 'set({0} {1} CACHE {2} "{3}")'.format(entry_name, value, cmake_type, cmake_comment)
if command_line_entry_value is not None:
print("ENTRY {}".format(entry))
self.__output_file.write("{}\n\n".format(entry))
......@@ -212,15 +236,15 @@ If you need to change a value which is not provided in this script input, you ma
"Path to third party directory",
args.third_party_directory)
self._cache_entry("MOREFEM_ASAN", \
"BOOL",
"If true address sanitizer is enabled.",
args.use_sanitizer)
# self._cache_entry("MOREFEM_ASAN", \
# "BOOL",
# "If true address sanitizer is enabled.",
# args.use_sanitizer)
self._cache_entry("CMAKE_BUILD_TYPE", \
"STRING",
"Either 'Debug' or 'Release'",
args.mode)
args.mode)
self._cache_entry("CMAKE_CXX_STANDARD",
"STRING",
......@@ -236,11 +260,13 @@ If you need to change a value which is not provided in this script input, you ma
self._cache_entry("LIBRARY_TYPE",
"BOOL",
"Choose either STATIC or SHARED.")
"Choose either STATIC or SHARED.",
args.library_type)
self._cache_entry("BUILD_MOREFEM_UNIQUE_LIBRARY",
"BOOL",
"Whether a unique library is built for MoReFEM core libraries or on the contrary if it is splitted in modules.")
"Whether a unique library is built for MoReFEM core libraries or on the contrary if it is splitted in modules.",
args.morefem_as_single_library)
self._cache_entry("MOREFEM_CHECK_UPDATE_GHOSTS_CALL_RELEVANCE",
"BOOL",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment