Skip to content

Commit

Permalink
feat(cxx): introduce xmake option
Browse files Browse the repository at this point in the history
  • Loading branch information
pplmx committed Aug 23, 2024
1 parent f940d5e commit ee9b41e
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ All notable changes to this project will be documented in this file.
- *(python)* Use uv for all scenario
- *(python)* Only install uv at Dockerfile
- *(python)* Add UV_INDEX_URL at Dockerfile
- *(python)* Use debian bookworm
- Introduce git-cliff to generate the changelog

## [1.0.0] - 2024-08-17

Expand Down
3 changes: 1 addition & 2 deletions template/cxx/cookiecutter.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
"email": "email@example.com",
"github_username": "your-org-or-username",


"cxx_cmake_version": "3.28",
"cxx_build_tool": ["xmake", "cmake"],
"cxx_standard_version": "20",
"cxx_standard_required": true,
"cxx_extensions_required": false,
Expand Down
15 changes: 15 additions & 0 deletions template/cxx/hooks/post_gen_project.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import os

cxx_build_tool = "{{cookiecutter.cxx_build_tool}}"

cmake_file = "CMakeLists.txt"
xmake_file = "xmake.lua"

if cxx_build_tool == "cmake":
if os.path.exists(xmake_file):
os.remove(xmake_file)
elif cxx_build_tool == "xmake":
if os.path.exists(cmake_file):
os.remove(cmake_file)
else:
raise ValueError(f"Unknown cxx_build_tool: {cxx_build_tool}")
2 changes: 1 addition & 1 deletion template/cxx/{{cookiecutter.project_slug}}/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION {{cookiecutter.cxx_cmake_version}})
cmake_minimum_required(VERSION 3.28)
project({{cookiecutter.project_slug}} LANGUAGES CXX)

# C++ Standard settings
Expand Down
25 changes: 25 additions & 0 deletions template/cxx/{{cookiecutter.project_slug}}/xmake.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
-- Set project name and language
set_project("{{cookiecutter.project_slug}}")
set_languages("c++{{cookiecutter.cxx_standard_version}}")

{% if cookiecutter.cxx_project_type == "binary" %}
-- Binary project setup
target("{{cookiecutter.project_slug}}")
set_kind("binary")
add_files("src/*.cpp")
add_headerfiles("src/*.h")

{% if cookiecutter.cxx_share_enabled == "STATIC" %}
-- Static link settings for non-macOS platforms
if not is_plat("macosx") then
add_ldflags("-static", {force = true})
end
{% endif %}

{% else %}
-- Library project setup
target("{{cookiecutter.project_slug}}")
set_kind("{{cookiecutter.cxx_share_enabled | lower}}")
add_files("src/*.cpp")
add_headerfiles("src/*.h")
{% endif %}

0 comments on commit ee9b41e

Please sign in to comment.