Skip to content

Commit

Permalink
feat(cmake): update the CMakeLists.txt and add Makefile
Browse files Browse the repository at this point in the history
  • Loading branch information
pplmx committed Sep 22, 2022
1 parent 62b8df0 commit 4de5ca5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
15 changes: 12 additions & 3 deletions template/cxx/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,26 @@ set(CMAKE_CXX_STANDARD_REQUIRED {{cxx_standard_required}})
set(CMAKE_CXX_EXTENSIONS {{cxx_extensions}}) # enable compiler-specific features or not
set(CMAKE_EXPORT_COMPILE_COMMANDS ON) # clangd completion

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

{% if proj_type == "bin" -%}

add_executable(${PROJECT_NAME} ${SOURCES})

{% if bin_type == "static" -%}
link_libraries("-static")

target_link_libraries(${PROJECT_NAME} PUBLIC "-static")

{%- endif %}
add_executable(${PROJECT_NAME} ${SOURCES})

{%- elsif lib_type == "static" -%}

# static
add_library({{project-name}} src/library.cpp)

{%- else -%}

# shared
add_library({{project-name}} SHARED src/library.cpp)

{%- endif %}
7 changes: 7 additions & 0 deletions template/cxx/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.PHONY: dev

dev:
# create a image "{{project-name}}" with tag "latest"
# based on the Dockerfile in the current directory
docker image build . -t {{project-name}}
docker container run --rm {{project-name}}

0 comments on commit 4de5ca5

Please sign in to comment.