Skip to content

Commit

Permalink
c4core: add package (#4405)
Browse files Browse the repository at this point in the history
  • Loading branch information
star-hengxing committed Jun 19, 2024
1 parent 886959c commit 1598d93
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 0 deletions.
29 changes: 29 additions & 0 deletions packages/c/c4core/patches/0.2.1/cmake-deps.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index ea146a8..31373e5 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -69,14 +69,12 @@ set(C4CORE_SRC_FILES
c4/windows_push.hpp
c4/c4core.natvis
#
- c4/ext/debugbreak/debugbreak.h
c4/ext/rng/rng.hpp
c4/ext/sg14/inplace_function.h
)
if(C4CORE_WITH_FASTFLOAT)
list(APPEND C4CORE_SRC_FILES
c4/ext/fast_float.hpp
- c4/ext/fast_float_all.h
)
endif()
set(C4CORE_AMALGAMATED ${C4CORE_SRC_DIR}/../src_singleheader/c4/c4core_all.hpp)
@@ -97,6 +95,9 @@ c4_add_library(c4core
)
if(NOT C4CORE_WITH_FASTFLOAT)
target_compile_definitions(c4core PUBLIC -DC4CORE_NO_FAST_FLOAT)
+else()
+ find_package(FastFloat REQUIRED CONFIG)
+ target_link_libraries(c4core PUBLIC "FastFloat::fast_float")
endif()
if(C4CORE_NO_DEBUG_BREAK)
target_compile_definitions(c4core PUBLIC -DC4_NO_DEBUG_BREAK)
56 changes: 56 additions & 0 deletions packages/c/c4core/xmake.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package("c4core")
set_homepage("https://github.com/biojppm/c4core")
set_description("C++ utilities")
set_license("MIT")

add_urls("https://github.com/biojppm/c4core/releases/download/v$(version)/c4core-$(version)-src.zip",
"https://github.com/biojppm/c4core.git")

add_versions("0.2.1", "81ff1c0d15e24da6d76fdd1b6fdd903fa23d0df7c82e564f993147a4dac88773")

add_configs("fast_float", {description = "use fastfloat to parse floats", default = false, type = "boolean"})
add_configs("debugbreak", {description = "use debug break in debug builds", default = false, type = "boolean"})

add_deps("cmake")

on_load(function (package)
if package:config("fast_float") then
package:add("deps", "fast_float")
else
package:add("defines", "C4CORE_NO_FAST_FLOAT")
end
if package:config("debugbreak") then
package:add("deps", "debugbreak")
else
package:add("defines", "C4_NO_DEBUG_BREAK")
end

if package:config("fast_float") or package:config("debugbreak") then
package:add("patches", "0.2.1", "patches/0.2.1/cmake-deps.patch", "92c0c6510cc3b8cbd10b575b5b9d0defa2a19d19f24c1618a73d4f4636da4c9b")
end
end)

on_install(function (package)
if package:config("fast_float") then
io.replace("src/c4/ext/fast_float.hpp", "c4/ext/fast_float_all.h", "fast_float/fast_float.h", {plain = true})
end
if package:config("debugbreak") then
io.replace("src/c4/error.hpp", "c4/ext/debugbreak/debugbreak.h", "debugbreak.h", {plain = true})
end

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, "-DC4CORE_WITH_FASTFLOAT=" .. (package:config("fast_float") and "ON" or "OFF"))
table.insert(configs, "-DC4CORE_NO_DEBUG_BREAK=" .. (package:config("debugbreak") and "OFF" or "ON"))
import("package.tools.cmake").install(package, configs, {packagedeps = "debugbreak"})
end)

on_test(function (package)
assert(package:check_cxxsnippets({test = [[
void test() {
double value;
c4::from_chars("52.4354", &value);
}
]]}, {configs = {languages = "c++11"}, includes = "c4/charconv.hpp"}))
end)

0 comments on commit 1598d93

Please sign in to comment.