Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 47 additions & 34 deletions packages/g/gtest/xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,53 +25,66 @@ package("gtest")

add_configs("main", {description = "Link to the gtest_main entry point.", default = false, type = "boolean"})
add_configs("gmock", {description = "Link to the googlemock library.", default = true, type = "boolean"})
add_configs("cmake", {description = "Use cmake build system", default = true, type = "boolean"})

if is_plat("linux", "bsd") then
add_syslinks("pthread")
end

on_load(function (package)
if package:config("cmake") then
package:add("deps", "cmake")
end

if package:config("shared") and package:is_plat("windows") then
package:add("defines", "GTEST_LINKED_AS_SHARED_LIBRARY=1")
end
end)

on_install(function (package)
local std = "cxx14"
if package:version() and package:version():gt("1.16.0") then
std = "cxx17"
if package:config("cmake") then
local configs = {}
table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release"))
table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
table.insert(configs, "-DBUILD_GMOCK=" .. (package:config("gmock") and "ON" or "OFF"))
import("package.tools.cmake").install(package, configs)
else
Comment on lines +45 to +51

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The new CMake build path does not respect the main configuration option. In the xmake build path, package:config("main") controls whether the gtest_main target is a default part of the package. In this new CMake path, the main config is ignored, and gtest_main is always built but never becomes a default target. This is a behavioral regression that breaks configuration consistency for the package. Please ensure the main config is also handled in the CMake build path to maintain consistent behavior between the two build options.

local std = "cxx14"
if package:version() and package:version():gt("1.16.0") then
std = "cxx17"
end
io.writefile("xmake.lua", format([[
add_rules("utils.install.cmake_importfiles")
set_languages("%s")
target("gtest")
set_kind("$(kind)")
add_files("googletest/src/gtest-all.cc")
add_includedirs("googletest/include", "googletest")
add_headerfiles("googletest/include/(**.h)")
if is_kind("shared") and is_plat("windows") then
add_defines("GTEST_CREATE_SHARED_LIBRARY=1")
end

target("gtest_main")
set_kind("$(kind)")
set_default(]] .. tostring(package:config("main")) .. [[)
add_files("googletest/src/gtest_main.cc")
add_includedirs("googletest/include", "googletest")
add_deps("gtest")

target("gmock")
set_kind("$(kind)")
set_default(]] .. tostring(package:config("gmock")) .. [[)
add_files("googlemock/src/gmock-all.cc")
add_includedirs("googlemock/include", "googlemock", "googletest/include", "googletest")
add_headerfiles("googlemock/include/(**.h)")
if is_kind("shared") and is_plat("windows") then
add_defines("GTEST_CREATE_SHARED_LIBRARY=1")
end
add_deps("gtest")
]], std))
import("package.tools.xmake").install(package)
end
io.writefile("xmake.lua", format([[
add_rules("utils.install.cmake_importfiles")
set_languages("%s")
target("gtest")
set_kind("$(kind)")
add_files("googletest/src/gtest-all.cc")
add_includedirs("googletest/include", "googletest")
add_headerfiles("googletest/include/(**.h)")
if is_kind("shared") and is_plat("windows") then
add_defines("GTEST_CREATE_SHARED_LIBRARY=1")
end

target("gtest_main")
set_kind("$(kind)")
set_default(]] .. tostring(package:config("main")) .. [[)
add_files("googletest/src/gtest_main.cc")
add_includedirs("googletest/include", "googletest")
add_deps("gtest")

target("gmock")
set_kind("$(kind)")
set_default(]] .. tostring(package:config("gmock")) .. [[)
add_files("googlemock/src/gmock-all.cc")
add_includedirs("googlemock/include", "googlemock", "googletest/include", "googletest")
add_headerfiles("googlemock/include/(**.h)")
if is_kind("shared") and is_plat("windows") then
add_defines("GTEST_CREATE_SHARED_LIBRARY=1")
end
add_deps("gtest")
]], std))
import("package.tools.xmake").install(package)
end)

on_test(function (package)
Expand Down
Loading