From 35b76453145c6d132c677a9aae7be9c6d5ee02eb Mon Sep 17 00:00:00 2001 From: David Madl Date: Sat, 28 Feb 2026 01:56:55 +0100 Subject: [PATCH] CMake: add lib skeleton and google-tests --- .gitignore | 4 ++++ CMakeLists.txt | 12 ++++++++++++ google-tests/CMakeLists.txt | 19 +++++++++++++++++++ google-tests/test1.cpp | 15 +++++++++++++++ pasada-lib/CMakeLists.txt | 24 ++++++++++++++++++++++++ pasada-lib/include/library.h | 6 ++++++ pasada-lib/library.cpp | 7 +++++++ 7 files changed, 87 insertions(+) create mode 100644 .gitignore create mode 100644 CMakeLists.txt create mode 100644 google-tests/CMakeLists.txt create mode 100644 google-tests/test1.cpp create mode 100644 pasada-lib/CMakeLists.txt create mode 100644 pasada-lib/include/library.h create mode 100644 pasada-lib/library.cpp diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5f6744f --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +# ignore checkout dir for Google Tests +google-tests/lib +/.idea +/build diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..1c70f0e --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,12 @@ +cmake_minimum_required(VERSION 4.1) + +project(PasadaSuperProject) + +option(PASADA_BUILD_TESTS "Build Google Tests" ON) + +add_subdirectory(pasada-lib) + +if(PASADA_BUILD_TESTS) + enable_testing() + add_subdirectory(google-tests) +endif() diff --git a/google-tests/CMakeLists.txt b/google-tests/CMakeLists.txt new file mode 100644 index 0000000..f47692c --- /dev/null +++ b/google-tests/CMakeLists.txt @@ -0,0 +1,19 @@ +project(Google_Tests) + +set(CMAKE_CXX_STANDARD 20) + +# 'lib' is the folder with Google Test sources +add_subdirectory(lib) +include_directories(${gtest_SOURCE_DIR}/include ${gtest_SOURCE_DIR}) + +# 'Google_Tests_run' is the target name +# 'test1.cpp test2.cpp' are source files with tests +add_executable(Google_Tests_run test1.cpp) + +target_link_libraries(Google_Tests_run pasada) +#target_include_directories(Google_Tests_run PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/pasada-lib/include") + +target_link_libraries(Google_Tests_run gtest gtest_main) +#target_link_libraries(Google_Tests_run PRIVATE Pasada_Lib) + +target_include_directories(Google_Tests_run PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/../pasada-lib/include") diff --git a/google-tests/test1.cpp b/google-tests/test1.cpp new file mode 100644 index 0000000..bb2e03c --- /dev/null +++ b/google-tests/test1.cpp @@ -0,0 +1,15 @@ +// +// Created by david on 28.02.2026. +// +#include +#include "library.h" + +// Demonstrate some basic assertions. +TEST(HelloTest, BasicAssertions) { + // Expect two strings not to be equal. + EXPECT_STRNE("hello", "world from test1.cpp"); + // Expect equality. + EXPECT_EQ(7 * 6, 42); + printf("asdf"); + hello(); +} \ No newline at end of file diff --git a/pasada-lib/CMakeLists.txt b/pasada-lib/CMakeLists.txt new file mode 100644 index 0000000..22a82a8 --- /dev/null +++ b/pasada-lib/CMakeLists.txt @@ -0,0 +1,24 @@ +project(Pasada_Lib) + +SET(PASADA_SRC + library.cpp +) + +if(PASADA_BUILD_TESTS) + # must build a STATIC library for google-tests to successfully consume us + # (otherwise, strange runtime errors ensue when trying to call into the lib) + add_library(pasada STATIC + ${PASADA_SRC} + ) +else() + add_library(pasada SHARED + ${PASADA_SRC} + ) +endif() + +target_include_directories(pasada + PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}/include +) + +set(CMAKE_CXX_STANDARD 20) diff --git a/pasada-lib/include/library.h b/pasada-lib/include/library.h new file mode 100644 index 0000000..7dc7aec --- /dev/null +++ b/pasada-lib/include/library.h @@ -0,0 +1,6 @@ +#ifndef LIBPASADA_LIBRARY_H +#define LIBPASADA_LIBRARY_H + +void hello(); + +#endif // LIBPASADA_LIBRARY_H \ No newline at end of file diff --git a/pasada-lib/library.cpp b/pasada-lib/library.cpp new file mode 100644 index 0000000..461e8d7 --- /dev/null +++ b/pasada-lib/library.cpp @@ -0,0 +1,7 @@ +#include "library.h" + +#include + +void hello() { + std::cout << "Hello, World!" << std::endl; +} \ No newline at end of file