Skip to content

Commit

Permalink
Add config param for CMAKE_BUILD_TYPE
Browse files Browse the repository at this point in the history
- default to "Release"
- allow :cmake_build_type kwarg to the constructor
- override everything with CMAKE_BUILD_TYPE env var
  • Loading branch information
flavorjones committed Oct 10, 2023
1 parent fe56918 commit d2a6035
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/mini_portile2/mini_portile_cmake.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down
11 changes: 11 additions & 0 deletions test/test_cmake.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down

0 comments on commit d2a6035

Please sign in to comment.