diff --git a/lib/mini_portile2/mini_portile_cmake.rb b/lib/mini_portile2/mini_portile_cmake.rb index 8543645..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 @@ -69,7 +74,8 @@ def cmake_compile_flags "-DCMAKE_SYSTEM_NAME=#{cmake_system_name}", "-DCMAKE_SYSTEM_PROCESSOR=#{cpu_type}", "-DCMAKE_C_COMPILER=#{c_compiler}", - "-DCMAKE_CXX_COMPILER=#{cxx_compiler}" + "-DCMAKE_CXX_COMPILER=#{cxx_compiler}", + "-DCMAKE_BUILD_TYPE=#{cmake_build_type}", ] end diff --git a/test/test_cmake.rb b/test/test_cmake.rb index c7bfb35..7a3483c 100644 --- a/test/test_cmake.rb +++ b/test/test_cmake.rb @@ -96,7 +96,8 @@ def test_configure_defaults_with_macos "-DCMAKE_SYSTEM_NAME=Darwin", "-DCMAKE_SYSTEM_PROCESSOR=arm64", "-DCMAKE_C_COMPILER=some-host-clang", - "-DCMAKE_CXX_COMPILER=some-host-clang++" + "-DCMAKE_CXX_COMPILER=some-host-clang++", + "-DCMAKE_BUILD_TYPE=Release" ], recipe.configure_defaults) end @@ -119,7 +120,8 @@ def test_configure_defaults_with_manual_system_name "-DCMAKE_SYSTEM_NAME=Custom", "-DCMAKE_SYSTEM_PROCESSOR=x86_64", "-DCMAKE_C_COMPILER=gcc", - "-DCMAKE_CXX_COMPILER=g++" + "-DCMAKE_CXX_COMPILER=g++", + "-DCMAKE_BUILD_TYPE=Release" ], recipe.configure_defaults) end @@ -194,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') @@ -227,7 +240,8 @@ def default_x86_compile_flags "-DCMAKE_SYSTEM_NAME=Linux", "-DCMAKE_SYSTEM_PROCESSOR=x86_64", "-DCMAKE_C_COMPILER=gcc", - "-DCMAKE_CXX_COMPILER=g++" + "-DCMAKE_CXX_COMPILER=g++", + "-DCMAKE_BUILD_TYPE=Release" ] end