Skip to content

Commit

Permalink
Basic CMake project configuration (#8)
Browse files Browse the repository at this point in the history
* Basic CMake project configuration
  • Loading branch information
BarTes8 authored Feb 1, 2024
1 parent 7cf8e96 commit 9481b26
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 0 deletions.
25 changes: 25 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
cmake_minimum_required(VERSION 3.14)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

project(PasswordManager)

set(FLAGS -Wall -Werror -Wpedantic -Wextra)

enable_testing()

if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Debug)
endif()

if(CMAKE_BUILD_TYPE MATCHES Release)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/Release/)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/Release/)
else()
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/Debug/)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/Debug/)
endif()

include_directories(headers)
add_subdirectory(source)
13 changes: 13 additions & 0 deletions headers/PasswordManager.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#pragma once

#include <string>

class PasswordManager {
public:
PasswordManager() = default;
PasswordManager(const std::string& password);

~PasswordManager();
private:
std::string password_;
};
5 changes: 5 additions & 0 deletions source/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
project(PasswordManager)

add_executable(passwordManager main.cpp PasswordManager.cpp)

add_subdirectory(test)
13 changes: 13 additions & 0 deletions source/PasswordManager.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include <iostream>

#include "PasswordManager.h"

PasswordManager::PasswordManager(const std::string& password)
: password_(password)
{
std::cout << "Password is: " << password_ << '\n';
}

PasswordManager::~PasswordManager() {
std::cout << "Password manager destructor\n";
}
10 changes: 10 additions & 0 deletions source/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include <string>

#include "PasswordManager.h"

int main() {
std::string password = "haslo";
PasswordManager passwordManager(password);

return 0;
}
18 changes: 18 additions & 0 deletions source/test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
include(FetchContent)

set(TEST_NAME ${PROJECT_NAME}-UT)

FetchContent_Declare(
googletest
GIT_REPOSITORY "https://github.com/google/googletest.git"
GIT_TAG release-1.11.0
)

FetchContent_MakeAvailable(googletest)

add_executable(${TEST_NAME} test.cpp)
target_link_libraries(${TEST_NAME} gtest_main)
set_target_properties(${TEST_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/test")

include(GoogleTest)
gtest_discover_tests(${TEST_NAME})
6 changes: 6 additions & 0 deletions source/test/test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include "gtest/gtest.h"
#include "PasswordManager.h"

TEST(CheckIfCMakeWorks, returnsTrue) {
ASSERT_TRUE(true);
}

0 comments on commit 9481b26

Please sign in to comment.