Skip to content

Commit

Permalink
feat(cxx): setup the output dir for binary and lib
Browse files Browse the repository at this point in the history
  • Loading branch information
pplmx committed Aug 23, 2024
1 parent ee9b41e commit 7be7f88
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
7 changes: 7 additions & 0 deletions template/cxx/{{cookiecutter.project_slug}}/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ set(CMAKE_CXX_EXTENSIONS {{cookiecutter.cxx_extensions_required}}) # Enable or
# Enable compile commands for clangd
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

# Set output directory for binaries
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)

# Set output directory for libraries
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)

# Source files
file(GLOB SOURCES CONFIGURE_DEPENDS ${CMAKE_SOURCE_DIR}/src/*.h ${CMAKE_SOURCE_DIR}/src/*.cpp)

Expand Down
6 changes: 5 additions & 1 deletion template/cxx/{{cookiecutter.project_slug}}/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@ APP_NAME := {{cookiecutter.project_slug}}

# compile and build
build:
{% if cookiecutter.cxx_build_tool == "cmake" %}
@cmake -S . -B build
@cmake --build build
{% else %}
@xmake
{% endif %}

{% if cookiecutter.cxx_project_type == "binary" %}
# run
run:
@./build/{{cookiecutter.project_slug}}
@./build/bin/{{cookiecutter.project_slug}}
{% endif %}

# build image
Expand Down
2 changes: 2 additions & 0 deletions template/cxx/{{cookiecutter.project_slug}}/xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ set_languages("c++{{cookiecutter.cxx_standard_version}}")
{% if cookiecutter.cxx_project_type == "binary" %}
-- Binary project setup
target("{{cookiecutter.project_slug}}")
set_targetdir("build/bin")
set_kind("binary")
add_files("src/*.cpp")
add_headerfiles("src/*.h")
Expand All @@ -19,6 +20,7 @@ target("{{cookiecutter.project_slug}}")
{% else %}
-- Library project setup
target("{{cookiecutter.project_slug}}")
set_targetdir("build/lib")
set_kind("{{cookiecutter.cxx_share_enabled | lower}}")
add_files("src/*.cpp")
add_headerfiles("src/*.h")
Expand Down

0 comments on commit 7be7f88

Please sign in to comment.