From d2a6035109dfa8cd77c3069658a710c6c6ae15ab Mon Sep 17 00:00:00 2001 From: Mike Dalessio Date: Tue, 10 Oct 2023 17:33:49 -0400 Subject: [PATCH] Add config param for CMAKE_BUILD_TYPE - default to "Release" - allow :cmake_build_type kwarg to the constructor - override everything with CMAKE_BUILD_TYPE env var --- lib/mini_portile2/mini_portile_cmake.rb | 7 ++++++- test/test_cmake.rb | 11 +++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/mini_portile2/mini_portile_cmake.rb b/lib/mini_portile2/mini_portile_cmake.rb index fd7aa08..41e1ad1 100644 --- a/lib/mini_portile2/mini_portile_cmake.rb +++ b/lib/mini_portile2/mini_portile_cmake.rb @@ -11,6 +11,7 @@ def configure_prefix def initialize(name, version, **kwargs) super(name, version, **kwargs) @cmake_command = kwargs[:cmake_command] + @cmake_build_type = kwargs[:cmake_build_type] end def configure_defaults @@ -49,6 +50,10 @@ def cmake_cmd (ENV["CMAKE"] || @cmake_command || "cmake").dup end + def cmake_build_type + (ENV["CMAKE_BUILD_TYPE"] || @cmake_build_type || "Release").dup + end + private def generator_defaults @@ -70,7 +75,7 @@ def cmake_compile_flags "-DCMAKE_SYSTEM_PROCESSOR=#{cpu_type}", "-DCMAKE_C_COMPILER=#{c_compiler}", "-DCMAKE_CXX_COMPILER=#{cxx_compiler}", - "-DCMAKE_BUILD_TYPE=Release" + "-DCMAKE_BUILD_TYPE=#{cmake_build_type}", ] end diff --git a/test/test_cmake.rb b/test/test_cmake.rb index 20abe75..7a3483c 100644 --- a/test/test_cmake.rb +++ b/test/test_cmake.rb @@ -196,6 +196,17 @@ def test_cmake_command_configuration end end + def test_cmake_build_type_configuration + without_env("CMAKE_BUILD_TYPE") do + assert_equal("Release", MiniPortileCMake.new("test", "1.0.0").cmake_build_type) + assert_equal("xyzzy", MiniPortileCMake.new("test", "1.0.0", cmake_build_type: "xyzzy").cmake_build_type) + end + with_env("CMAKE_BUILD_TYPE"=>"Debug") do + assert_equal("Debug", MiniPortileCMake.new("test", "1.0.0").cmake_build_type) + assert_equal("Debug", MiniPortileCMake.new("test", "1.0.0", cmake_build_type: "xyzzy").cmake_build_type) + end + end + private def with_stubbed_target(os: 'linux', cpu: 'x86_64')