Skip to content

Commit

Permalink
Allow override of CMAKE_BUILD_TYPE (#165)
Browse files Browse the repository at this point in the history
* Fix arguments order for generate stage

* Logic rework

* format

* Move build type logic to generate()

* Reintroduce bacwards compatibility

---------

Co-authored-by: thomas-bc <[email protected]>
  • Loading branch information
SMorettini and thomas-bc authored Oct 11, 2023
1 parent f76cbf7 commit 85e7fb0
Showing 1 changed file with 25 additions and 19 deletions.
44 changes: 25 additions & 19 deletions src/fprime/fbuild/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,31 +305,17 @@ def get_cmake_args(self) -> dict:
("FPRIME_CONFIG_DIR", "config_directory"),
("FPRIME_INSTALL_DEST", "install_destination"),
]

cmake_args = {
cache: self.get_settings(setting, None)
for cache, setting in needed
if self.get_settings(setting, None) is not None
}

# Load in the default settings
self.get_settings("default_cmake_options", None)

if "FPRIME_LIBRARY_LOCATIONS" in cmake_args:
cmake_args["FPRIME_LIBRARY_LOCATIONS"] = ";".join(
[str(location) for location in cmake_args["FPRIME_LIBRARY_LOCATIONS"]]
)
# When the new v3 autocoder directory exists, this means we can use the new UT api and preserve the build type
v3_autocoder_directory = Path(
cmake_args.get("FPRIME_FRAMEWORK_PATH") / "cmake" / "autocoder"
)
if (
v3_autocoder_directory.exists()
and self.build_type == BuildType.BUILD_TESTING
):
cmake_args["BUILD_TESTING"] = "ON"
cmake_args["CMAKE_BUILD_TYPE"] = cmake_args.get("CMAKE_BUILD_TYPE", "Debug")
elif self.build_type == BuildType.BUILD_TESTING:
cmake_args["CMAKE_BUILD_TYPE"] = "Testing"
return cmake_args

def get_module_name(self, path: Path):
Expand Down Expand Up @@ -382,14 +368,15 @@ def execute_build_target(
environment=self.settings.get("environment", None),
)

def generate(self, cmake_args):
def generate(self, user_cmake_args):
"""Generates a build given CMake arguments
This will run a generate step of the cmake build process. This will take in any argument used/passed to CMake.
Args:
cmake_args: cmake arguments to pass into the generate step
user_cmake_args: cmake arguments to pass into the generate step
"""
cmake_args = {}
try:

def split_pair(item):
Expand All @@ -399,16 +386,35 @@ def split_pair(item):
default_options_text = self.get_settings("default_cmake_options", None)
default_options = default_options_text.split("\n")

default_cmake_args = {
default_cmake_options = {
option: value
for (option, value) in [split_pair(item) for item in default_options]
if option != ""
}

cmake_args.update(default_cmake_options) # default_cmake_options
cmake_args.update(user_cmake_args) # User-supplied values from command line
cmake_args.update(self.get_cmake_args()) # FPRIME_* values (settings.ini)

# When the new v3 autocoder directory exists, this means we can use the new UT api and preserve the build type
v3_autocoder_directory = Path(
cmake_args.get("FPRIME_FRAMEWORK_PATH") / "cmake" / "autocoder"
)
if (
v3_autocoder_directory.exists()
and self.build_type == BuildType.BUILD_TESTING
):
cmake_args["BUILD_TESTING"] = "ON"
cmake_args["CMAKE_BUILD_TYPE"] = user_cmake_args.get(
"CMAKE_BUILD_TYPE", "Debug"
)
elif self.build_type == BuildType.BUILD_TESTING:
cmake_args["CMAKE_BUILD_TYPE"] = "Testing"

self.cmake.generate_build(
self.cmake_root,
self.build_dir,
{**default_cmake_args, **cmake_args, **self.get_cmake_args()},
cmake_args,
environment=self.settings.get("environment", None),
)
except CMakeException as cexc:
Expand Down

0 comments on commit 85e7fb0

Please sign in to comment.