Skip to content

Commit 7a7b76e

Browse files
committed
feat(cxx): support load third_party by xmake
- 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
1 parent ae47134 commit 7a7b76e

File tree

4 files changed

+14
-17
lines changed

4 files changed

+14
-17
lines changed

template/cxx/hooks/post_gen_project.py

-3
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ def remove_path_if_exists(path):
1313

1414
cxx_build_tool = "{{cookiecutter.cxx_build_tool}}"
1515

16-
test_main = "tests/test_main.cpp"
17-
1816
cmake_root = "CMakeLists.txt"
1917
cmake_test = "tests/CMakeLists.txt"
2018
cmake_custom = "cmake"
@@ -25,7 +23,6 @@ def remove_path_if_exists(path):
2523
if cxx_build_tool == "cmake":
2624
remove_path_if_exists(xmake_root)
2725
remove_path_if_exists(xmake_test)
28-
remove_path_if_exists(test_main)
2926
elif cxx_build_tool == "xmake":
3027
remove_path_if_exists(cmake_root)
3128
remove_path_if_exists(cmake_test)

template/cxx/{{cookiecutter.project_slug}}/tests/test_main.cpp

-6
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
-- Add Google Test package
2-
add_requires("gtest")
2+
add_requires("gtest", {configs = {main = true, gmock = true}})
33

44
-- Add test target
55
target("{{cookiecutter.project_slug}}-tests")
@@ -8,3 +8,9 @@ target("{{cookiecutter.project_slug}}-tests")
88
add_files("*.cpp")
99
add_deps("{{cookiecutter.package_name}}_lib")
1010
add_packages("gtest")
11+
add_links("gtest_main")
12+
13+
if is_plat("windows") then
14+
-- fixes "LINK : fatal error LNK1561: entry point must be defined"
15+
add_ldflags("/subsystem:console")
16+
end

template/cxx/{{cookiecutter.project_slug}}/xmake.lua

+7-7
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@ set_version("{{cookiecutter.project_version}}")
44
set_languages("c++{{cookiecutter.cxx_standard_version}}")
55

66
-- Dependencies
7-
add_requires("spdlog 1.15.0") -- Add spdlog as a required dependency
7+
add_requires("spdlog") -- Add spdlog as a required dependency
88

99
-- Define Library Target
1010
target("{{cookiecutter.package_name}}_lib")
1111
set_kind("static") -- Build as a static library
1212
set_targetdir("build/lib") -- Specify output directory
13-
add_includedirs("include") -- Include project's header files
14-
add_includedirs("third_party") -- Include project's header files
13+
add_includedirs("include", {public = true}) -- Include project's header files
14+
add_includedirs("third_party", {public = true}) -- Include project's header files
1515
add_files("src/*.cpp") -- Add project source files
16-
add_headerfiles("include/*.h") -- Add project's header files
17-
add_headerfiles("include/*.hpp") -- Add project's header files
18-
add_headerfiles("third_party/*.h") -- Add project's header files
19-
add_headerfiles("third_party/*.hpp") -- Add project's header files
16+
add_headerfiles("include/**/*.h") -- Add project's header files
17+
add_headerfiles("include/**/*.hpp") -- Add project's header files
18+
add_headerfiles("third_party/**/*.h") -- Add project's header files
19+
add_headerfiles("third_party/**/*.hpp") -- Add project's header files
2020
add_packages("spdlog") -- Link spdlog headers and library
2121

2222
-- Define Executable Target

0 commit comments

Comments
 (0)