Skip to content

Commit

Permalink
feat(classify): bin and lib(shared or static)
Browse files Browse the repository at this point in the history
  • Loading branch information
pplmx committed Sep 5, 2022
1 parent c388060 commit db7b912
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 6 deletions.
10 changes: 9 additions & 1 deletion template/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,12 @@ project({{project-name}})

set(CMAKE_CXX_STANDARD {{cxx-standard}})

add_executable({{project-name}} main.cpp)
{% if project-type == "bin" %}
add_executable({{project-name}} src/main.cpp)
{% else if lib-type == "static" %}
# static
add_library({{project-name}} src/library.cpp)
{% else %}
# shared
add_library({{project-name}} SHARED src/library.cpp)
{% endif %}
24 changes: 19 additions & 5 deletions template/cargo-generate.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,22 @@ type = "string"
prompt = "Cxx standard version?"
regex = "^[0-9]+$"

#[conditional.'crate_type == "lib"']
#ignore = [ "src/main.rs" ]
#
#[conditional.'crate_type == "bin"']
#ignore = [ "src/lib.rs" ]
[placeholders.project-type]
type = "string"
prompt = "Which cxx project type?"
choices = [
"bin",
"lib"
]
default = "bin"

[conditional.'project-type == "bin"']
ignore = ["src/library.h", "src/library.cpp"]

[conditional.'project-type == "lib"'.placeholders.lib-type]
ignore = ["src/main.cpp"]
type = "string"
prompt = "Which lib type?"
choices = ["static", "shared"]
default = "shared"

7 changes: 7 additions & 0 deletions template/src/library.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include "library.h"

#include <iostream>

void hello() {
std::cout << "Hello, World!" << std::endl;
}
6 changes: 6 additions & 0 deletions template/src/library.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#ifndef {{project-name}}_LIBRARY_H
#define {{project-name}}_LIBRARY_H

void hello();

#endif //{{project-name}}_LIBRARY_H

0 comments on commit db7b912

Please sign in to comment.