diff --git a/.gitignore b/.gitignore index 378eac2..4469528 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1 @@ -build +**/build diff --git a/cmake_demo/.clang-format b/cmake_demo/.clang-format new file mode 100644 index 0000000..9133c1d --- /dev/null +++ b/cmake_demo/.clang-format @@ -0,0 +1,71 @@ +# Ultracruise Localization clang-format configuration file +# Please seek consensus from the team before modifying this file. +# +# To compare these settings with all available clang-format options: +# diff <(clang-format -dump-config | grep -Ev '^$|^( |BraceWrapping|IncludeCategories)' | sed -Ee 's/: +/: /g' | sort) <(cat .clang-format | grep -Ev '^$|^#' | sort) | colordiff +# + +DisableFormat: false +Language: Cpp +Standard: Cpp11 + +# Indentation & whitespace +AccessModifierOffset: -4 +ColumnLimit: 140 +ConstructorInitializerIndentWidth: 8 +ContinuationIndentWidth: 8 +IndentCaseLabels: true +IndentWidth: 4 +IndentWrappedFunctionNames: false +KeepEmptyLinesAtTheStartOfBlocks: true +MaxEmptyLinesToKeep: 2 +NamespaceIndentation: None +SpacesBeforeTrailingComments: 2 +TabWidth: 4 +UseTab: Never + +# Spacing style +Cpp11BracedListStyle: true +DerivePointerAlignment: false +PointerAlignment: Left +SpaceAfterCStyleCast: true +SpaceBeforeAssignmentOperators: true +SpaceBeforeParens: ControlStatements +SpaceInEmptyParentheses: false +SpacesInCStyleCastParentheses: false +SpacesInContainerLiterals: false +SpacesInParentheses: false +SpacesInSquareBrackets: false + +# Comments +AlignTrailingComments: true +CommentPragmas: '' +ReflowComments: true + +# Pattern-based special behavior +ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ] +IncludeCategories: [] +MacroBlockBegin: '' +MacroBlockEnd: '' + +# Alignment & breaking +AlignAfterOpenBracket: AlwaysBreak +AlignConsecutiveAssignments: false +AlignConsecutiveDeclarations: false +AlignOperands: false +AllowAllParametersOfDeclarationOnNextLine: false +AllowShortBlocksOnASingleLine: false +AllowShortCaseLabelsOnASingleLine: false +AllowShortFunctionsOnASingleLine: Empty +AllowShortIfStatementsOnASingleLine: false +AllowShortLoopsOnASingleLine: false +AlwaysBreakAfterReturnType: None +AlwaysBreakBeforeMultilineStrings: true +AlwaysBreakTemplateDeclarations: true +BinPackArguments: false +BinPackParameters: false +BreakBeforeBinaryOperators: NonAssignment +BreakBeforeBraces: Attach +BreakBeforeTernaryOperators: true +BreakConstructorInitializersBeforeComma: true +ConstructorInitializerAllOnOneLineOrOnePerLine: true diff --git a/cmake_demo/.gitea/workflows/demo.yaml b/cmake_demo/.gitea/workflows/demo.yaml new file mode 100644 index 0000000..ef3dc1b --- /dev/null +++ b/cmake_demo/.gitea/workflows/demo.yaml @@ -0,0 +1,28 @@ +name: Gitea Actions Demo +run-name: ${{ gitea.actor }} is testing out Gitea Actions 🚀 +on: [push] + +jobs: + Explore-Gitea-Actions: + runs-on: ubuntu-latest + steps: + - run: echo "🎉 The job was automatically triggered by a ${{ gitea.event_name }} event." + - run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by Gitea!" + - run: echo "🔎 The name of your branch is ${{ gitea.ref }} and your repository is ${{ gitea.repository }}." + + - name: Disable SSL verification for Git + run: | + git config --global http.sslVerify false + echo "SSL verification is to: $(git config --global http.sslVerify)." + + - run: echo "💡 Attempting to clone ${{ gitea.repository }}" + + - name: Check out repository code + uses: actions/checkout@v4 + + - run: echo "💡 The ${{ gitea.repository }} repository has been cloned to the runner." + - run: echo "🖥️ The workflow is now ready to test your code on the runner." + - name: List files in the repository + run: | + ls ${{ gitea.workspace }} + - run: echo "🍏 This job's status is ${{ job.status }}." diff --git a/cmake_demo/.gitignore b/cmake_demo/.gitignore new file mode 100644 index 0000000..2aecc9b --- /dev/null +++ b/cmake_demo/.gitignore @@ -0,0 +1,4 @@ +**/build +compile_commands.json +.cache + diff --git a/cmake_demo/CMakeLists.txt.bak b/cmake_demo/CMakeLists.txt.bak new file mode 100644 index 0000000..c35a5a0 --- /dev/null +++ b/cmake_demo/CMakeLists.txt.bak @@ -0,0 +1,7 @@ +cmake_minimum_required(VERSION 3.5) +project( + SimpleLibrary + VERSION 1.0.0 + LANGUAGES CXX) + +add_subdirectory(simple_library) diff --git a/cmake_demo/README.md b/cmake_demo/README.md new file mode 100644 index 0000000..4da94d1 --- /dev/null +++ b/cmake_demo/README.md @@ -0,0 +1,3 @@ +# cmake_demo + +demo to create a simple library, consume it in another cmake project, make a conan repo out of it, and make it cpakcable for debian, \ No newline at end of file diff --git a/cmake_demo/simple_caller/CMakeLists.txt b/cmake_demo/simple_caller/CMakeLists.txt new file mode 100644 index 0000000..51d9397 --- /dev/null +++ b/cmake_demo/simple_caller/CMakeLists.txt @@ -0,0 +1,56 @@ +cmake_minimum_required(VERSION 3.5) +project( + SimpleCaller + VERSION 1.0.0 + LANGUAGES CXX) + +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) + +# +# auto genrate a stamp header +# +execute_process( + COMMAND git rev-parse --short HEAD + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + OUTPUT_VARIABLE GIT_HASH + OUTPUT_STRIP_TRAILING_WHITESPACE) + +execute_process( + COMMAND git rev-parse --abbrev-ref HEAD + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + OUTPUT_VARIABLE GIT_BRANCH + OUTPUT_STRIP_TRAILING_WHITESPACE) + +set(CUSTOM_VALUE "Blah blah custom value.") + +configure_file("${CMAKE_CURRENT_SOURCE_DIR}/include/version.h.in" + "${CMAKE_CURRENT_BINARY_DIR}/include/version.h") + +add_custom_target(generate_version_h ALL + DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/include/version.h") + +# +# Build +# +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wpedantic") +set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g") +set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3 -DNDEBUG") +set(CMAKE_CXX_FLAGS_RELWITHDEBINFO + "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -O2 -g -DNDEBUG") +set(CMAKE_BUILD_TYPE + "Release" + CACHE STRING "Choose the type of build." FORCE) +set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" + "RelWithDebInfo") + +file(GLOB_RECURSE SOURCES "src/*.cpp") +# file(GLOB_RECURSE HEADERS "include/*.h") + +find_package(simple_library REQUIRED) + +# shared - set_target_properties is so that the binary is libSimpleLibrary.so +# add_depdencies so the config.h file is auto generated +add_executable(${PROJECT_NAME} ${SOURCES}) +target_include_directories(${PROJECT_NAME} PUBLIC include) +target_link_libraries(${PROJECT_NAME} SimpleLibrary::SimpleLibrary) +set_target_properties(${PROJECT_NAME} PROPERTIES OUTPUT_NAME "simple_caller") diff --git a/cmake_demo/simple_caller/CMakeUserPresets.json b/cmake_demo/simple_caller/CMakeUserPresets.json new file mode 100644 index 0000000..71aeace --- /dev/null +++ b/cmake_demo/simple_caller/CMakeUserPresets.json @@ -0,0 +1,9 @@ +{ + "version": 4, + "vendor": { + "conan": {} + }, + "include": [ + "build/Release/generators/CMakePresets.json" + ] +} \ No newline at end of file diff --git a/cmake_demo/simple_caller/README.md b/cmake_demo/simple_caller/README.md new file mode 100644 index 0000000..a70c41e --- /dev/null +++ b/cmake_demo/simple_caller/README.md @@ -0,0 +1,4 @@ +``` +conan install . --build=missing +conan build . --name=simple_caller --version=1.0.0 --user=ras --channel=stable +``` diff --git a/cmake_demo/simple_caller/conanfile.py b/cmake_demo/simple_caller/conanfile.py new file mode 100644 index 0000000..64a8051 --- /dev/null +++ b/cmake_demo/simple_caller/conanfile.py @@ -0,0 +1,23 @@ +from conan import ConanFile +from conan.tools.cmake import CMake, cmake_layout + +class SimpleCallerConan(ConanFile): + name = "simple_caller" + version = "1.0.0" + settings = "os", "compiler", "build_type", "arch" + requires = "simple_library/1.0.0@ras/stable" # Replace with the actual reference + generators = "CMakeDeps", "CMakeToolchain" + + def layout(self): + cmake_layout(self) + + def imports(self): + self.copy("*.dll", dst="bin", src="bin") + self.copy("*.dylib*", dst="bin", src="lib") + self.copy("*.so", dst="bin", src="lib") + + def build(self): + cmake = CMake(self) + cmake.configure() + cmake.build() + diff --git a/cmake_demo/simple_caller/include/header.h b/cmake_demo/simple_caller/include/header.h new file mode 100644 index 0000000..516ace9 --- /dev/null +++ b/cmake_demo/simple_caller/include/header.h @@ -0,0 +1,3 @@ +#pragma once + +const char * hello(); diff --git a/cmake_demo/simple_caller/include/version.h.in b/cmake_demo/simple_caller/include/version.h.in new file mode 100644 index 0000000..22e36b6 --- /dev/null +++ b/cmake_demo/simple_caller/include/version.h.in @@ -0,0 +1,11 @@ +#pragma once + +#define SIMPLE_LIBRARY_VERSION_MAJOR @SimpleLibrary_VERSION_MAJOR@ +#define SIMPLE_LIBRARY_VERSION_MINOR @SimpleLibrary_VERSION_MINOR@ +#define SIMPLE_LIBRARY_VERSION_PATCH @SimpleLibrary_VERSION_PATCH@ +#define SIMPLE_LIBRARY_VERSION "@SimpleLibrary_VERSION@" + +#define SIMPLE_LIBRARY_GIT_HASH "@GIT_HASH@" +#define SIMPLE_LIBRARY_GIT_BRANCH "@GIT_BRANCH@" +#define SIMPLE_LIBRARY_CUSTOM_VALUE "@CUSTOM_VALUE@" + diff --git a/cmake_demo/simple_caller/src/header.cpp b/cmake_demo/simple_caller/src/header.cpp new file mode 100644 index 0000000..0805731 --- /dev/null +++ b/cmake_demo/simple_caller/src/header.cpp @@ -0,0 +1,5 @@ +#include "header.h" + +const char *hello() { + return "Hello, World!"; +} diff --git a/cmake_demo/simple_caller/src/main.cpp b/cmake_demo/simple_caller/src/main.cpp new file mode 100644 index 0000000..077ba39 --- /dev/null +++ b/cmake_demo/simple_caller/src/main.cpp @@ -0,0 +1,10 @@ +#include "header.h" + +#include +using std::cout; +using std::endl; + +int main(int argc, char *argv[], char *envp[]) { + cout << hello() << endl; + return 0; +} diff --git a/cmake_demo/simple_library/CMakeLists.txt b/cmake_demo/simple_library/CMakeLists.txt new file mode 100644 index 0000000..d97e780 --- /dev/null +++ b/cmake_demo/simple_library/CMakeLists.txt @@ -0,0 +1,185 @@ +cmake_minimum_required(VERSION 3.5) +project( + SimpleLibrary + VERSION 1.0.0 + LANGUAGES CXX) + +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) + +# +# auto genrate a stamp header +# +execute_process( + COMMAND git rev-parse --short HEAD + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + OUTPUT_VARIABLE GIT_HASH + OUTPUT_STRIP_TRAILING_WHITESPACE) + +execute_process( + COMMAND git rev-parse --abbrev-ref HEAD + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + OUTPUT_VARIABLE GIT_BRANCH + OUTPUT_STRIP_TRAILING_WHITESPACE) + +set(CUSTOM_VALUE "Blah blah custom value.") + +configure_file("${CMAKE_CURRENT_SOURCE_DIR}/include/version.h.in" + "${CMAKE_CURRENT_BINARY_DIR}/include/simple/version.h") + +add_custom_target( + generate_version_h ALL + DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/include/simple/version.h") + +# +# Build +# +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wpedantic") +set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g") +set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3 -DNDEBUG") +set(CMAKE_CXX_FLAGS_RELWITHDEBINFO + "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -O2 -g -DNDEBUG") +set(CMAKE_BUILD_TYPE + "Release" + CACHE STRING "Choose the type of build." FORCE) +set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" + "RelWithDebInfo") + +file(GLOB_RECURSE SOURCES "src/*.cpp") +# file(GLOB_RECURSE HEADERS "include/*.h") + +# shared - set_target_properties is so that the binary is libSimpleLibrary.so +# add_depdencies so the config.h file is auto generated +add_library(SimpleLibraryShared SHARED ${SOURCES}) +target_include_directories( + SimpleLibraryShared + PRIVATE $ + PUBLIC $ + $ + $) +set_target_properties(SimpleLibraryShared PROPERTIES OUTPUT_NAME + "SimpleLibrary") +add_dependencies(SimpleLibraryShared generate_version_h doc_doxygen) + +# static - set_target_properties is so that the binary is libSimpleLibrary.a +# add_depdencies so the config.h file is auto generated +add_library(SimpleLibraryStatic STATIC ${SOURCES}) +set_target_properties(SimpleLibraryStatic PROPERTIES OUTPUT_NAME + "SimpleLibrary") +target_include_directories( + SimpleLibraryStatic + PRIVATE $ + PUBLIC $ + $ + $) +add_dependencies(SimpleLibraryStatic generate_version_h doc_doxygen) + +# +# Test +# +enable_testing() +add_subdirectory(test) + +# +# doxygen +# +find_package(Doxygen REQUIRED) +set(DOXYGEN_IN ${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in) +set(DOXYGEN_OUT ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile) + +configure_file(${DOXYGEN_IN} ${DOXYGEN_OUT} @ONLY) +add_custom_target( + doc_doxygen # ALL otherwise it's constantly being rebuilt + COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYGEN_OUT} + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + COMMENT "Generating API documentation with Doxygen" + VERBATIM) + +# +# man page +# +# look into pandoc that'll turn markdown into man pages. +add_custom_target( + man ALL + COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/man + ${CMAKE_CURRENT_BINARY_DIR}/man + COMMENT "Copying man pages") + +# +# CMake find support +# +include(CMakePackageConfigHelpers) +write_basic_package_version_file( + "${CMAKE_CURRENT_BINARY_DIR}/SimpleLibraryConfigVersion.cmake" + VERSION ${PROJECT_VERSION} + COMPATIBILITY AnyNewerVersion) + +configure_package_config_file( + "${CMAKE_CURRENT_SOURCE_DIR}/SimpleLibraryConfig.cmake.in" + "${CMAKE_CURRENT_BINARY_DIR}/SimpleLibraryConfig.cmake" + INSTALL_DESTINATION lib/cmake/SimpleLibrary) + +# +# Install +# +install( + TARGETS SimpleLibraryShared SimpleLibraryStatic + ARCHIVE DESTINATION lib + LIBRARY DESTINATION lib + RUNTIME DESTINATION bin + PUBLIC_HEADER DESTINATION include/simple) + +install(DIRECTORY include/simple/ DESTINATION include/simple) + +install(FILES "${CMAKE_CURRENT_BINARY_DIR}/include/simple/version.h" + DESTINATION include/simple) + +install(FILES "${CMAKE_CURRENT_BINARY_DIR}/SimpleLibraryConfig.cmake" + "${CMAKE_CURRENT_BINARY_DIR}/SimpleLibraryConfigVersion.cmake" + DESTINATION lib/cmake/SimpleLibrary) + +install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/doc/html + DESTINATION share/doc/SimpleLibrary) + +install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/man/ DESTINATION share/man) + +# +# CPack +# +set(CPACK_PACKAGE_NAME "SimpleLibrary") +set(CPACK_PACKAGE_VERSION ${PROJECT_VERSION}) +set(CPACK_PACKAGE_CONTACT "RAS ") +set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "A simple library example") +set(CPACK_PACKAGE_VENDOR "Your Organization") +set(CPACK_PACKAGE_LICENSE "MIT") +set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}") +set(CPACK_SOURCE_PACKAGE_FILE_NAME + "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-Source") + +# Debian specific settings +set(CPACK_DEBIAN_PACKAGE_MAINTAINER "RAS ") +set(CPACK_DEBIAN_PACKAGE_DEPENDS "libc6 (>= 2.27)") +set(CPACK_DEBIAN_PACKAGE_SECTION "devel") +set(CPACK_DEBIAN_ARCHITECTURE ${CMAKE_SYSTEM_PROCESSOR}) + +include(CPack) + +cpack_add_component_group(Development) +cpack_add_component( + Headers + DISPLAY_NAME "C++ Headers" + DESCRIPTION "C++ header files for SimpleLibrary" + GROUP Development + REQUIRED) +cpack_add_component( + Libraries + DISPLAY_NAME "Libraries" + DESCRIPTION "Shared and static libraries for SimpleLibrary" + GROUP Development + REQUIRED) + +cpack_add_component( + Doxygen + DISPLAY_NAME "Doxygen Documentation" + DESCRIPTION "API documentation generated by Doxygen" + GROUP Development + REQUIRED) diff --git a/cmake_demo/simple_library/CMakeUserPresets.json b/cmake_demo/simple_library/CMakeUserPresets.json new file mode 100644 index 0000000..71aeace --- /dev/null +++ b/cmake_demo/simple_library/CMakeUserPresets.json @@ -0,0 +1,9 @@ +{ + "version": 4, + "vendor": { + "conan": {} + }, + "include": [ + "build/Release/generators/CMakePresets.json" + ] +} \ No newline at end of file diff --git a/cmake_demo/simple_library/Doxyfile.in b/cmake_demo/simple_library/Doxyfile.in new file mode 100644 index 0000000..49d6d33 --- /dev/null +++ b/cmake_demo/simple_library/Doxyfile.in @@ -0,0 +1,18 @@ +# Doxyfile.in + +# Doxyfile configuration for Doxygen + +# Project related configuration options +PROJECT_NAME = @PROJECT_NAME@ +PROJECT_NUMBER = @PROJECT_VERSION@ + +# Build related configuration options +OUTPUT_DIRECTORY = @CMAKE_CURRENT_BINARY_DIR@/doc +GENERATE_HTML = YES +GENERATE_LATEX = NO + +# Configuration options related to the input files +INPUT = @CMAKE_SOURCE_DIR@/include + +# Configuration options related to the output files +HTML_OUTPUT = html diff --git a/cmake_demo/simple_library/README.md b/cmake_demo/simple_library/README.md new file mode 100644 index 0000000..d655ef6 --- /dev/null +++ b/cmake_demo/simple_library/README.md @@ -0,0 +1,47 @@ +# Conan development + +```bash +# install depedencies +conan install . --build=missing + +# export recipe to the local cache +conan export . --name=simple_library --version=1.0.0 --user=ras --channel=stable + +# builds the package +conan build . --name=simple_library --version=1.0.0 --user=ras --channel=stable + +# create a package from a recipe in add to local cache +conan create . --name=simple_library --version=1.0.0 --user=ras --channel=stable + +# check to see create works +conan list simple_library/1.0.0@ras/stable +``` + +# conanfile.py + +looks like exports_sources in conanfile.py is where you specify the essential files. + + +# Upload to Conan +```bash +conan remote login -p <> <> <> +# rastar sprague.a.rick + +conan upload --remote <> <> +# rastar simple_library + +conan search simple_library +``` + +# Building DEB + +```bash +cpack -G DEB -C Release --config CPackConfig.cmake +dpkg-deb --contents SimpleLibrary-1.0.0.deb +dpkg-deb --info SimpleLibrary-1.0.0.deb +``` +``` + +# Other notes +* pandoc to make man pages from markdown +* using conan for gmock and gtest diff --git a/cmake_demo/simple_library/SimpleLibraryConfig.cmake.in b/cmake_demo/simple_library/SimpleLibraryConfig.cmake.in new file mode 100644 index 0000000..99e2c8c --- /dev/null +++ b/cmake_demo/simple_library/SimpleLibraryConfig.cmake.in @@ -0,0 +1,16 @@ +@PACKAGE_INIT@ + +include(CMakeFindDependencyMacro) + +# Include the version file +include("${CMAKE_CURRENT_LIST_DIR}/SimpleLibraryConfigVersion.cmake") + +# Add the targets file +include("${CMAKE_CURRENT_LIST_DIR}/SimpleLibraryTargets.cmake") + +# Set the include directories +set(SimpleLibrary_INCLUDE_DIRS "@PACKAGE_INCLUDE_INSTALL_DIR@") + +# Provide the include directories to the caller +set(SimpleLibrary_INCLUDE_DIRS ${SimpleLibrary_INCLUDE_DIRS}) +mark_as_advanced(SimpleLibrary_INCLUDE_DIRS) diff --git a/cmake_demo/simple_library/conanfile.py b/cmake_demo/simple_library/conanfile.py new file mode 100644 index 0000000..98fb337 --- /dev/null +++ b/cmake_demo/simple_library/conanfile.py @@ -0,0 +1,47 @@ +from conan import ConanFile +from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout +import os + +class SimpleLibraryConan(ConanFile): + name = "simple_library" + version = "1.0.0" + license = "MIT" + url = "https://rastar.netgear.com/gitea/sprague.a.rick/cmake_demo.git" + description = "A simple library that adds two integers" + settings = "os", "compiler", "build_type", "arch" + exports_sources = ( + "CMakeLists.txt", + "src/*", + "include/*", + "test/*", + "SimpleLibraryConfig.cmake.in", + "man/*", + "Doxyfile.in" + ) + generators = "CMakeDeps" + requires = "gtest/1.11.0" + + def layout(self): + cmake_layout(self) + + def generate(self): + tc = CMakeToolchain(self) + tc.generator = "Ninja" + tc.generate() + + def build(self): + os.environ["CONAN_CPU_COUNT"] = "4" + cmake = CMake(self) + cmake.configure() + cmake.build() + + def package(self): + cmake = CMake(self) + cmake.install() + + def package_info(self): + self.cpp_info.libs = ["simple_library", "simple_library_shared"] + + def test(self): + cmake = CMake(self) + cmake.test() diff --git a/cmake_demo/simple_library/include/internal.h b/cmake_demo/simple_library/include/internal.h new file mode 100644 index 0000000..abdec60 --- /dev/null +++ b/cmake_demo/simple_library/include/internal.h @@ -0,0 +1,3 @@ +#pragma once + +int getvalue(); diff --git a/cmake_demo/simple_library/include/simple/simple_library.h b/cmake_demo/simple_library/include/simple/simple_library.h new file mode 100644 index 0000000..ad8020b --- /dev/null +++ b/cmake_demo/simple_library/include/simple/simple_library.h @@ -0,0 +1,33 @@ +#pragma once + +/** + * Brief description of the function. + * + * Detailed description of the function. This part can be used to elaborate on the functionality, parameters, and return values. + * + * @param x The first parameter, representating an integer value. + * @param y The second parameter, representing an integer value. + * @return The sum of x and y. + */ +int add(int a, int b); + +/** + * Get the version that was generated. + */ +const char* getVersion(); + +/** + * Get the git hash + */ +const char* getGitHash(); + +/** + * Get the git branch + */ +const char* getGitBranch(); + +/** + * Get the custom value + */ +const char* getCustomValue(); + diff --git a/cmake_demo/simple_library/include/version.h.in b/cmake_demo/simple_library/include/version.h.in new file mode 100644 index 0000000..22e36b6 --- /dev/null +++ b/cmake_demo/simple_library/include/version.h.in @@ -0,0 +1,11 @@ +#pragma once + +#define SIMPLE_LIBRARY_VERSION_MAJOR @SimpleLibrary_VERSION_MAJOR@ +#define SIMPLE_LIBRARY_VERSION_MINOR @SimpleLibrary_VERSION_MINOR@ +#define SIMPLE_LIBRARY_VERSION_PATCH @SimpleLibrary_VERSION_PATCH@ +#define SIMPLE_LIBRARY_VERSION "@SimpleLibrary_VERSION@" + +#define SIMPLE_LIBRARY_GIT_HASH "@GIT_HASH@" +#define SIMPLE_LIBRARY_GIT_BRANCH "@GIT_BRANCH@" +#define SIMPLE_LIBRARY_CUSTOM_VALUE "@CUSTOM_VALUE@" + diff --git a/cmake_demo/simple_library/man/simple_library.1 b/cmake_demo/simple_library/man/simple_library.1 new file mode 100644 index 0000000..32f8d7c --- /dev/null +++ b/cmake_demo/simple_library/man/simple_library.1 @@ -0,0 +1,11 @@ +.TH SIMPLE_LIBRARY 1 "October 2023" "SimpleLibrary 1.0.0" "SimpleLibrary Manual" +.SH NAME +simple_library \- A simple library example +.SH SYNOPSIS +.B simple_library +.SH DESCRIPTION +This is a simple library example for demonstration purposes. +.SH AUTHOR +Written by RAS . +.SH COPYRIGHT +MIT License diff --git a/cmake_demo/simple_library/src/internal.cpp b/cmake_demo/simple_library/src/internal.cpp new file mode 100644 index 0000000..388bdc7 --- /dev/null +++ b/cmake_demo/simple_library/src/internal.cpp @@ -0,0 +1,6 @@ +#include "internal.h" + +int getvalue() { + return 10; +} + diff --git a/cmake_demo/simple_library/src/simple_library.cpp b/cmake_demo/simple_library/src/simple_library.cpp new file mode 100644 index 0000000..a21d3b0 --- /dev/null +++ b/cmake_demo/simple_library/src/simple_library.cpp @@ -0,0 +1,33 @@ +#include "simple/simple_library.h" +#include "simple/version.h" +#include "internal.h" + +#include +using std::cout; +using std::endl; + +int add(int a, int b) { + int rv = (a + b) * getvalue(); + cout << "a: " << a << endl; + cout << "b: " << b << endl; + cout << "c: " << getvalue() << endl; + cout << "(a + b) * c = " << rv << endl; + return rv; + return (a + b) * getvalue(); +} + +const char *getCustomValue() { + return SIMPLE_LIBRARY_CUSTOM_VALUE; +} + +const char *getVersion() { + return SIMPLE_LIBRARY_VERSION; +} + +const char *getGitHash() { + return SIMPLE_LIBRARY_GIT_HASH; +} + +const char *getGitBranch() { + return SIMPLE_LIBRARY_GIT_BRANCH; +} diff --git a/cmake_demo/simple_library/test/CMakeLists.txt b/cmake_demo/simple_library/test/CMakeLists.txt new file mode 100644 index 0000000..9e1b3b5 --- /dev/null +++ b/cmake_demo/simple_library/test/CMakeLists.txt @@ -0,0 +1,7 @@ +file(GLOB_RECURSE SOURCES "src/*.cpp") + +find_package(GTest REQUIRED) +add_executable(SimpleLibraryTests ${SOURCES}) +target_link_libraries(SimpleLibraryTests GTest::gtest GTest::gtest_main SimpleLibraryShared) +add_test(NAME SimpleLibraryTests COMMAND SimpleLibraryTests) + diff --git a/cmake_demo/simple_library/test/src/test_simple_library.cpp b/cmake_demo/simple_library/test/src/test_simple_library.cpp new file mode 100644 index 0000000..ee3fdc9 --- /dev/null +++ b/cmake_demo/simple_library/test/src/test_simple_library.cpp @@ -0,0 +1,11 @@ +#include "simple_library.h" // Include your library header +#include + +TEST(SimpleLibraryTest, BasicAssertions) { + // Expect two strings not to be equal. + EXPECT_STRNE("hello", "world"); + // Expect equality. + EXPECT_EQ(7 * 6, 42); + + EXPECT_EQ(150, add(5, 10)); +}