diff --git a/build.py b/build.py index 9b1019d5..e052fa70 100755 --- a/build.py +++ b/build.py @@ -47,6 +47,7 @@ parser.add_option('-g', '--generate-docs', dest='generate_docs', action="store_true", help='generate documentation for the current target', default=False) parser.add_option('-j', '--parallelism', dest='parallelism', action="store", help='Set the number of parallel threads to build with, if supported', default=10) parser.add_option('-n', '--lines', dest='detail_lines', action="store", help="Sets the number of detail lines to output (only relevant to --status)", default=3 ) +parser.add_option('--cmake-build-type', dest='cmake_build_type', metavar="-DCMAKE_BUILD_TYPE", help="Pass the -DCMAKE_BUILD_TYPE argument to cmake. Default is 'RelWithDebInfo', which targets size optimizations and includes some basic debug info. Other options include 'Debug', 'Release', and 'MinSizeRel'. See cmake documentation for more details.", default='RelWithDebInfo') (options, args) = parser.parse_args() @@ -131,6 +132,11 @@ print("Too many arguments supplied, only one target can be specified.") exit(1) +if options.cmake_build_type not in ['Debug', 'Release', 'MinSizeRel', 'RelWithDebInfo']: + print("Invalid CMake build type specified: {}".format(options.cmake_build_type)) + print("Valid options are: Debug, Release, MinSizeRel, RelWithDebInfo. See CMake documentation for more details.") + exit(1) + if not options.test_platform: if not os.path.exists("../codal.json"): @@ -141,7 +147,7 @@ generate_docs() exit(0) - build(options.clean, verbose=options.verbose, parallelism=options.parallelism) + build(options.clean, verbose=options.verbose, parallelism=options.parallelism, cmake_build_type=options.cmake_build_type) exit(0) for json_obj in test_json: @@ -168,4 +174,4 @@ with open("../codal.json", 'w') as codal_json: json.dump(config, codal_json, indent=4) - build(True, True, options.parallelism) + build(True, True, options.parallelism, cmake_build_type=options.cmake_build_type) diff --git a/utils/python/codal_utils.py b/utils/python/codal_utils.py index 2466a93d..8cf6b734 100644 --- a/utils/python/codal_utils.py +++ b/utils/python/codal_utils.py @@ -11,13 +11,13 @@ def system(cmd): if os.system(cmd) != 0: sys.exit(1) -def build(clean, verbose = False, parallelism = 10): +def build(clean, verbose = False, parallelism = 10, cmake_build_type='RelWithDebInfo'): # Use Ninja on Windows, or if available in any other OS use_ninja = shutil.which("ninja") is not None or platform.system() == "Windows" if use_ninja: # configure - system("cmake .. -DCMAKE_BUILD_TYPE=RelWithDebInfo -G \"Ninja\"") + system(f"cmake .. -DCMAKE_BUILD_TYPE={cmake_build_type} -G \"Ninja\"") if clean: system("ninja clean") @@ -29,7 +29,7 @@ def build(clean, verbose = False, parallelism = 10): system("ninja -j {}".format(parallelism)) else: # configure - system("cmake .. -DCMAKE_BUILD_TYPE=RelWithDebInfo -G \"Unix Makefiles\"") + system(f"cmake .. -DCMAKE_BUILD_TYPE={cmake_build_type} -G \"Unix Makefiles\"") if clean: system("make clean")