Skip to content

Commit

Permalink
feat(cxx): support load third_party by xmake
Browse files Browse the repository at this point in the history
- Remove unused test_main.cpp file for cmake build
- Update xmake.lua files to include gtest_main and fix Windows build
- Modify xmake.lua to use latest spdlog version and adjust include directories
- Remove unnecessary files and update build configurations
  • Loading branch information
pplmx committed Dec 16, 2024
1 parent ae47134 commit 7a7b76e
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 17 deletions.
3 changes: 0 additions & 3 deletions template/cxx/hooks/post_gen_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ def remove_path_if_exists(path):

cxx_build_tool = "{{cookiecutter.cxx_build_tool}}"

test_main = "tests/test_main.cpp"

cmake_root = "CMakeLists.txt"
cmake_test = "tests/CMakeLists.txt"
cmake_custom = "cmake"
Expand All @@ -25,7 +23,6 @@ def remove_path_if_exists(path):
if cxx_build_tool == "cmake":
remove_path_if_exists(xmake_root)
remove_path_if_exists(xmake_test)
remove_path_if_exists(test_main)
elif cxx_build_tool == "xmake":
remove_path_if_exists(cmake_root)
remove_path_if_exists(cmake_test)
Expand Down

This file was deleted.

8 changes: 7 additions & 1 deletion template/cxx/{{cookiecutter.project_slug}}/tests/xmake.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-- Add Google Test package
add_requires("gtest")
add_requires("gtest", {configs = {main = true, gmock = true}})

-- Add test target
target("{{cookiecutter.project_slug}}-tests")
Expand All @@ -8,3 +8,9 @@ target("{{cookiecutter.project_slug}}-tests")
add_files("*.cpp")
add_deps("{{cookiecutter.package_name}}_lib")
add_packages("gtest")
add_links("gtest_main")

if is_plat("windows") then
-- fixes "LINK : fatal error LNK1561: entry point must be defined"
add_ldflags("/subsystem:console")
end
14 changes: 7 additions & 7 deletions template/cxx/{{cookiecutter.project_slug}}/xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ set_version("{{cookiecutter.project_version}}")
set_languages("c++{{cookiecutter.cxx_standard_version}}")

-- Dependencies
add_requires("spdlog 1.15.0") -- Add spdlog as a required dependency
add_requires("spdlog") -- Add spdlog as a required dependency

-- Define Library Target
target("{{cookiecutter.package_name}}_lib")
set_kind("static") -- Build as a static library
set_targetdir("build/lib") -- Specify output directory
add_includedirs("include") -- Include project's header files
add_includedirs("third_party") -- Include project's header files
add_includedirs("include", {public = true}) -- Include project's header files
add_includedirs("third_party", {public = true}) -- Include project's header files
add_files("src/*.cpp") -- Add project source files
add_headerfiles("include/*.h") -- Add project's header files
add_headerfiles("include/*.hpp") -- Add project's header files
add_headerfiles("third_party/*.h") -- Add project's header files
add_headerfiles("third_party/*.hpp") -- Add project's header files
add_headerfiles("include/**/*.h") -- Add project's header files
add_headerfiles("include/**/*.hpp") -- Add project's header files
add_headerfiles("third_party/**/*.h") -- Add project's header files
add_headerfiles("third_party/**/*.hpp") -- Add project's header files
add_packages("spdlog") -- Link spdlog headers and library

-- Define Executable Target
Expand Down

0 comments on commit 7a7b76e

Please sign in to comment.