релиз

This commit is contained in:
2024-12-10 17:38:20 +03:00
commit 6e7ebd4027
12 changed files with 189 additions and 0 deletions

View File

@@ -0,0 +1,42 @@
cmake_minimum_required(VERSION 3.20)
project({{ project_name_cmake }})
option({{ project_name | replace(" ", "_") | upper }}_BUILD_TESTS "Build {{ project_name }} tests" OFF)
option({{ project_name | replace(" ", "_") | upper }}_BUILD_EXAMPLES "Build {{ project_name }} examples" OFF)
set(CMAKE_CXX_STANDARD 20)
set(default_build_type "Release")
set(CMAKE_CXX_FLAGS "-Wall ${CMAKE_CXX_FLAGS}")
if ("${CMAKE_BUILD_TYPE}" STREQUAL "Release")
message(STATUS "Build type is release. Optimization for speed, without debug info.")
add_compile_options(-Ofast -s)
elseif ("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
message(STATUS "Minimal optimization, debug info included")
add_compile_options(-g)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0")
add_definitions(-DUSE_DEBUG)
else()
message(FATAL_ERROR "You must set build type \"Debug\" or \"Release\". Another build types not supported!")
endif()
message("{{ project_name }} CXX Flags: " ${CMAKE_CXX_FLAGS})
message("{{ project_name }} CMAKE_BUILD_TYPE: " ${CMAKE_BUILD_TYPE})
add_library(${PROJECT_NAME} STATIC
include/{{ include_header }}
src/{{ namespace }}.cpp
)
target_include_directories(${PROJECT_NAME} PUBLIC include/)
if ({{ project_name | replace(" ", "_") | upper }}_BUILD_EXAMPLES)
message("Build examples enabled")
{% for ex in examples_names %} add_subdirectory(examples/{{ ex | replace(" ", "-") | lower }})
{% endfor %}endif()
if ({{ project_name | replace(" ", "_") | upper }}_BUILD_TESTS)
message("Build tests enabled")
add_subdirectory(tests)
endif()

View File

@@ -0,0 +1,12 @@
set(EXECUTABLE {{ example_name_cmake }})
set(CMAKE_CXX_STANDARD 20)
include_directories(./)
set(SOURCES
main.cpp
)
add_executable(${EXECUTABLE} ${SOURCES})
target_link_libraries(${EXECUTABLE} PRIVATE {{ project_name_cmake }})

View File

@@ -0,0 +1,8 @@
#include <{{ include_header }}>
#include <iostream>
int main() {
{{ namespace }}::func();
std::cout << "Hello from example {{ example_name }}!" << std::endl;
return 0;
}

View File

@@ -0,0 +1,8 @@
#ifndef {{ project_name | replace(" ", "_") | upper }}_H
#define {{ project_name | replace(" ", "_") | upper }}_H
namespace {{ namespace }} {
void func();
}
#endif //{{ project_name | replace(" ", "_") | upper }}_H

View File

@@ -0,0 +1,4 @@
#include <{{ include_header }}>
void {{ namespace }}::func() {
}

View File

@@ -0,0 +1,24 @@
cmake_minimum_required(VERSION 3.20)
project({{ project_name_cmake }}-tests)
set(CMAKE_CXX_STANDARD 20)
find_package(GTest REQUIRED)
set(default_build_type "Release")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
set(CMAKE_CXX_FLAGS_DEBUG "-ggdb -O0") # -fprofile-arcs -ftest-coverage
set(CMAKE_CXX_FLAGS_RELEASE "-O2 -s")
message(${CMAKE_CXX_FLAGS})
include_directories(../include)
add_executable(${PROJECT_NAME}
main.cpp
test-{{ namespace }}.cpp
../include/{{ include_header }}
../src/{{ namespace }}.cpp
)
target_link_libraries(${PROJECT_NAME} GTest::gtest)

View File

@@ -0,0 +1,6 @@
#include "gtest/gtest.h"
int main(int argc, char ** argv) {
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}

View File

@@ -0,0 +1,7 @@
#include <{{ include_header }}>
#include <gtest/gtest.h>
TEST({{ project_name_code }}, {{ namespace }}_example) {
{{ namespace }}::func();
SUCCEED();
}