id = "cpp" name = "C/C++" group = "C/C++" icon = "project-cpp" description = "A CMake executable or library in C or C++." [[fields]] id = "lang" label = "Language:" type = "choice" segmented = true options = [{ value = "cpp", label = "C++" }, { value = "c", label = "C" }] default = "cpp" [[fields]] id = "kind" label = "Project type:" type = "choice" segmented = true options = [{ value = "executable", label = "Executable" }, { value = "library", label = "Library" }] default = "executable" [[fields]] id = "libtype" label = "Library type:" type = "choice" options = [{ value = "static", label = "Static" }, { value = "shared", label = "Shared" }] default = "static" visible = { kind = "library" } [[fields]] id = "cxx" label = "C++ standard:" type = "choice" options = ["23", "20", "17", "14"] default = "20" visible = { lang = "cpp" } [[fields]] id = "cstd" label = "C standard:" type = "choice" options = ["23", "17", "11", "99"] default = "17" visible = { lang = "c" } [[files]] path = "CMakeLists.txt" content = ''' cmake_minimum_required(VERSION 3.20) {{#if lang=cpp}} project({{name|snake}} LANGUAGES CXX) set(CMAKE_CXX_STANDARD {{cxx}}) set(CMAKE_CXX_STANDARD_REQUIRED ON) {{/if}} {{#if lang=c}} project({{name|snake}} LANGUAGES C) set(CMAKE_C_STANDARD {{cstd}}) set(CMAKE_C_STANDARD_REQUIRED ON) {{/if}} set(CMAKE_EXPORT_COMPILE_COMMANDS ON) {{#if kind=executable}} add_executable({{name|snake}} src/main.{{#if lang=cpp}}cpp{{/if}}{{#if lang=c}}c{{/if}}) {{/if}} {{#if kind=library}} {{#if libtype=shared}} # MSVC exports nothing from a DLL by default: export every symbol, as on other platforms. set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON) {{/if}} add_library({{name|snake}} {{#if libtype=static}}STATIC{{/if}}{{#if libtype=shared}}SHARED{{/if}} src/{{name|snake}}.{{#if lang=cpp}}cpp{{/if}}{{#if lang=c}}c{{/if}}) target_include_directories({{name|snake}} PUBLIC include) {{/if}} ''' [[files]] path = "src/main.cpp" when = { lang = "cpp", kind = "executable" } content = ''' #include int main() { std::cout << "Hello, World!" << std::endl; return 0; } ''' [[files]] path = "src/main.c" when = { lang = "c", kind = "executable" } content = ''' #include int main(void) { printf("Hello, World!\n"); return 0; } ''' [[files]] path = "include/{{name|snake}}.h" when = { lang = "cpp", kind = "library" } content = ''' #pragma once namespace {{name|snake}} { void hello(); } // namespace {{name|snake}} ''' [[files]] path = "src/{{name|snake}}.cpp" when = { lang = "cpp", kind = "library" } content = ''' #include "{{name|snake}}.h" #include namespace {{name|snake}} { void hello() { std::cout << "Hello, World!" << std::endl; } } // namespace {{name|snake}} ''' [[files]] path = "include/{{name|snake}}.h" when = { lang = "c", kind = "library" } content = ''' #pragma once void {{name|snake}}_hello(void); ''' [[files]] path = "src/{{name|snake}}.c" when = { lang = "c", kind = "library" } content = ''' #include "{{name|snake}}.h" #include void {{name|snake}}_hello(void) { printf("Hello, World!\n"); } ''' [[files]] path = ".gitignore" content = ''' build/ cmake-build-*/ '''