Skip to content

Commit

Permalink
Fix tests building issues, restructure directories and dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
fbtom committed Oct 5, 2024
1 parent 735056d commit 7b3a2f6
Show file tree
Hide file tree
Showing 33 changed files with 253 additions and 200 deletions.
15 changes: 15 additions & 0 deletions modules/backend/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,18 @@ add_subdirectory(visits)
add_subdirectory(warehouse)
add_subdirectory(proto)

option(BUILD_TESTS "Build tests" ON)

if(BUILD_TESTS)
enable_testing()
add_subdirectory(tests)
endif()

# Set properties for all targets
get_property(all_targets DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY BUILDSYSTEM_TARGETS)
foreach(target ${all_targets})
set_target_properties(${target} PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${OWN_LIBRARIES_DIR}
)
endforeach()

15 changes: 10 additions & 5 deletions modules/backend/clinic/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,14 @@ target_link_libraries(clinic-lib PUBLIC
target_include_directories(clinic-lib PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})

# install created lib in our own libraries directory
install(TARGETS clinic-lib
ARCHIVE DESTINATION ${OWN_LIBRARIES_DIR})
# install(TARGETS clinic-lib
# ARCHIVE DESTINATION ${OWN_LIBRARIES_DIR})

# copy include files to our own libraries directory
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/ DESTINATION ${OWN_LIBRARIES_DIR}/include
FILES_MATCHING PATTERN "*.h" PATTERN "*.hpp")
# # copy include files to our own libraries directory
# install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/ DESTINATION ${OWN_LIBRARIES_DIR}/include
# FILES_MATCHING PATTERN "*.h" PATTERN "*.hpp")
set_target_properties(clinic-lib PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY ${OWN_LIBRARIES_DIR}
LIBRARY_OUTPUT_DIRECTORY ${OWN_LIBRARIES_DIR}
RUNTIME_OUTPUT_DIRECTORY ${OWN_LIBRARIES_DIR}
)
18 changes: 12 additions & 6 deletions modules/backend/common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ set(COMMON_LIB_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/personal_data/PersonalData.cpp
${CMAKE_CURRENT_SOURCE_DIR}/personal_data/pesel/Pesel.cpp
${CMAKE_CURRENT_SOURCE_DIR}/validators/PeselValidator.cpp
${CMAKE_CURRENT_SOURCE_DIR}/file_manager/FileManager.cpp
)

add_library(common-lib STATIC ${COMMON_LIB_SOURCES})
Expand All @@ -17,9 +18,14 @@ target_compile_options(common-lib PRIVATE -Werror -Wall -Wextra -pedantic -Wunus

target_include_directories(common-lib PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})

# install created lib in our own libraries directory
install(TARGETS common-lib
ARCHIVE DESTINATION ${OWN_LIBRARIES_DIR})
# copy include files to our own libraries directory
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/ DESTINATION ${OWN_LIBRARIES_DIR}/include
FILES_MATCHING PATTERN "*.h" PATTERN "*.hpp")
# # install created lib in our own libraries directory
# install(TARGETS common-lib
# ARCHIVE DESTINATION ${OWN_LIBRARIES_DIR})
# # copy include files to our own libraries directory
# install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/ DESTINATION ${OWN_LIBRARIES_DIR}/include
# FILES_MATCHING PATTERN "*.h" PATTERN "*.hpp")
set_target_properties(common-lib PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY ${OWN_LIBRARIES_DIR}
LIBRARY_OUTPUT_DIRECTORY ${OWN_LIBRARIES_DIR}
RUNTIME_OUTPUT_DIRECTORY ${OWN_LIBRARIES_DIR}
)
27 changes: 11 additions & 16 deletions modules/backend/common/file_manager/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
set(FILE_MANAGER
${CMAKE_CURRENT_SOURCE_DIR}/SerializerHelper.cpp
)
# set(FILE_MANAGER
# ${CMAKE_CURRENT_SOURCE_DIR}/FileManager.cpp
# )

add_library(file_manager_lib STATIC ${FILE_MANAGER})
# add_library(file_manager_lib STATIC ${FILE_MANAGER})

target_compile_options(file_manager_lib PRIVATE -Werror -Wall -Wextra -pedantic -Wunused -Wshadow -Wold-style-cast -Wconversion)
# target_compile_options(file_manager_lib PRIVATE -Werror -Wall -Wextra -pedantic -Wunused -Wshadow -Wold-style-cast -Wconversion)

target_link_libraries(file_manager_lib PUBLIC
clinic-lib
proto
)
# target_link_libraries(file_manager_lib PUBLIC
# )

# target_include_directories(file_manager_lib PUBLIC
# .
# install(TARGETS file_manager_lib
# ARCHIVE DESTINATION ${OWN_LIBRARIES_DIR}
# )
install(TARGETS file_manager_lib
ARCHIVE DESTINATION ${OWN_LIBRARIES_DIR}/lib
)

install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/ DESTINATION ${OWN_LIBRARIES_DIR}/include
FILES_MATCHING PATTERN "*.h" PATTERN "*.hpp")
# install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/ DESTINATION ${OWN_LIBRARIES_DIR}/include
# FILES_MATCHING PATTERN "*.h" PATTERN "*.hpp")
30 changes: 15 additions & 15 deletions modules/backend/installation_rules.cmake
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
# EXPERIMENTAl: installing specific versions of libraries to be used by our project
include(ExternalProject)
# # EXPERIMENTAl: installing specific versions of libraries to be used by our project
# include(ExternalProject)

####### fixed version of protobuf for project
set(PROTOBUF_PREFIX "${EXTERNAL_LIBRARIES_DIR}/protobuf")
set(PROTOBUF_BASE_URL "https://github.com/protocolbuffers/protobuf/releases/download")
set(RELEASE_TAG "v21.0")
set(PROTOBUF_VERSION "3.21.0")
# ####### fixed version of protobuf for project
# set(PROTOBUF_PREFIX "${EXTERNAL_LIBRARIES_DIR}/protobuf")
# set(PROTOBUF_BASE_URL "https://github.com/protocolbuffers/protobuf/releases/download")
# set(RELEASE_TAG "v21.0")
# set(PROTOBUF_VERSION "3.21.0")

ExternalProject_Add(protobuf
URL "${PROTOBUF_BASE_URL}/${RELEASE_TAG}/protobuf-cpp-${PROTOBUF_VERSION}.tar.gz"
PREFIX ${PROTOBUF_PREFIX}
CONFIGURE_COMMAND <SOURCE_DIR>/configure --prefix=<INSTALL_DIR>
BUILD_COMMAND ${MAKE}
DOWNLOAD_EXTRACT_TIMESTAMP true
)
# ExternalProject_Add(protobuf
# URL "${PROTOBUF_BASE_URL}/${RELEASE_TAG}/protobuf-cpp-${PROTOBUF_VERSION}.tar.gz"
# PREFIX ${PROTOBUF_PREFIX}
# CONFIGURE_COMMAND <SOURCE_DIR>/configure --prefix=<INSTALL_DIR>
# BUILD_COMMAND ${MAKE}
# DOWNLOAD_EXTRACT_TIMESTAMP true
# )

set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} ${PROTOBUF_PREFIX})
# set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} ${PROTOBUF_PREFIX})
15 changes: 10 additions & 5 deletions modules/backend/patients/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,13 @@ target_link_libraries(patients-lib PUBLIC common-lib)
target_include_directories(patients-lib PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})

# install library in our own libraries directory
install(TARGETS patients-lib
ARCHIVE DESTINATION ${OWN_LIBRARIES_DIR})
# copy include files to our own libraries directory
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/ DESTINATION ${OWN_LIBRARIES_DIR}/include
FILES_MATCHING PATTERN "*.h" PATTERN "*.hpp")
# install(TARGETS patients-lib
# ARCHIVE DESTINATION ${OWN_LIBRARIES_DIR})
# # copy include files to our own libraries directory
# install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/ DESTINATION ${OWN_LIBRARIES_DIR}/include
# FILES_MATCHING PATTERN "*.h" PATTERN "*.hpp")
set_target_properties(patients-lib PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY ${OWN_LIBRARIES_DIR}
LIBRARY_OUTPUT_DIRECTORY ${OWN_LIBRARIES_DIR}
RUNTIME_OUTPUT_DIRECTORY ${OWN_LIBRARIES_DIR}
)
26 changes: 13 additions & 13 deletions modules/backend/patients/PatientsFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@
namespace patient
{

std::vector<std::unique_ptr<iPatient>> initializePatients([[maybe_unused]] const serializer::Serializer& serializer)
{
std::vector<std::unique_ptr<iPatient>> patients;
// Expected that Patient data will be deserialized and
// emplaced in patient vector, something like following way:
// for(const auto& patient : serializer.DeserializePatients())
// {
// patients.emplace_back(std::make_unique<iPatient>(patient));
// }
// other deserialized objects should follow the same approach
patients.emplace_back(std::make_unique<Patient>());
// std::vector<std::unique_ptr<iPatient>> initializePatients([[maybe_unused]] const serializer::Serializer& serializer)
// {
// std::vector<std::unique_ptr<iPatient>> patients;
// // Expected that Patient data will be deserialized and
// // emplaced in patient vector, something like following way:
// // for(const auto& patient : serializer.DeserializePatients())
// // {
// // patients.emplace_back(std::make_unique<iPatient>(patient));
// // }
// // other deserialized objects should follow the same approach
// patients.emplace_back(std::make_unique<Patient>());

return patients;
}
// return patients;
// }

} // namespace patient
7 changes: 2 additions & 5 deletions modules/backend/patients/PatientsFactory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
#include <memory>
#include <vector>

namespace serializer
{
class Serializer;
}

namespace patient
{

Expand All @@ -16,7 +13,7 @@ class iPatient;
* initializes Patients from serialized data.
* Shall be performed only once when application is started.
*/
std::vector<std::unique_ptr<iPatient>> initializePatients(const serializer::Serializer& serializer);
// std::vector<std::unique_ptr<iPatient>> initializePatients(const serializer::Serializer& serializer);
// this free functions should be in single file
// and only be accessible within start of the program section.

Expand Down
28 changes: 18 additions & 10 deletions modules/backend/proto/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@

include(FindProtobuf)
find_package(Protobuf REQUIRED 3.21.0)
include_directories(${PROTOBUF_INCLUDE_DIR})
include_directories(${CMAKE_CURRENT_BINARY_DIR})

protobuf_generate_cpp(PROTO_SRCS PROTO_HDRS
allergen.proto
Expand All @@ -14,14 +11,25 @@ protobuf_generate_cpp(PROTO_SRCS PROTO_HDRS
treatment.proto
treatment_state.proto)

add_library(proto ${PROTO_SRCS} ${PROTO_HDRS})

target_include_directories(proto PUBLIC ${CMAKE_CURRENT_BINARY_DIR})
target_link_libraries(proto PUBLIC ${PROTOBUF_LIBRARIES})
add_library(protobuff ${PROTO_SRCS} ${PROTO_HDRS})
target_compile_options(protobuff PRIVATE -Werror -Wall -Wextra -pedantic)
target_link_libraries(protobuff PUBLIC ${PROTOBUF_LIBRARIES})
message(STATUS "PROTOBUF_LIBRARIES ${PROTOBUF_LIBRARIES}")
target_include_directories(protobuff PUBLIC ${CMAKE_CURRENT_BINARY_DIR})

install(TARGETS proto
ARCHIVE DESTINATION ${OWN_LIBRARIES_DIR}/lib)
set_target_properties(protobuff PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY ${OWN_LIBRARIES_DIR}
LIBRARY_OUTPUT_DIRECTORY ${OWN_LIBRARIES_DIR}
RUNTIME_OUTPUT_DIRECTORY ${OWN_LIBRARIES_DIR}
)
# install(TARGETS protobuff
# ARCHIVE DESTINATION ${OWN_LIBRARIES_DIR})

install(FILES ${PROTO_HDRS} DESTINATION ${OWN_LIBRARIES_DIR}/include/proto)
install(FILES ${PROTO_SRCS} DESTINATION ${OWN_LIBRARIES_DIR}/include/proto)
# install(FILES ${PROTO_HDRS} DESTINATION ${OWN_LIBRARIES_DIR}/include/proto)
# install(FILES ${PROTO_SRCS} DESTINATION ${OWN_LIBRARIES_DIR}/include/proto)

message(STATUS "PROTOBUF_INCLUDE_DIR ${PROTOBUF_INCLUDE_DIR}")
include_directories(${PROTOBUF_INCLUDE_DIR})
message(STATUS "CMAKE_CURRENT_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}")
include_directories(${CMAKE_CURRENT_BINARY_DIR})
21 changes: 14 additions & 7 deletions modules/backend/serializer/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,24 +1,31 @@
set(SERIALIZER_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/SerializerHelper.cpp
${CMAKE_CURRENT_SOURCE_DIR}/Serializer.cpp
)

add_library(serializer-lib STATIC ${SERIALIZER_SOURCES})

target_compile_options(serializer-lib PRIVATE -Werror -Wall -Wextra -pedantic -Wunused -Wshadow -Wold-style-cast -Wconversion)

target_link_libraries(serializer-lib PUBLIC
common-lib
clinic-lib
proto
protobuff
)

target_include_directories(serializer-lib PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}
${OWN_LIBRARIES_DIR}/include/proto
# ${OWN_LIBRARIES_DIR}/include/proto
)

install(TARGETS serializer-lib
ARCHIVE DESTINATION ${OWN_LIBRARIES_DIR}/lib
set_target_properties(serializer-lib PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY ${OWN_LIBRARIES_DIR}
LIBRARY_OUTPUT_DIRECTORY ${OWN_LIBRARIES_DIR}
RUNTIME_OUTPUT_DIRECTORY ${OWN_LIBRARIES_DIR}
)
# install(TARGETS serializer-lib
# ARCHIVE DESTINATION ${OWN_LIBRARIES_DIR}
# )

install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/ DESTINATION ${OWN_LIBRARIES_DIR}/include
FILES_MATCHING PATTERN "*.h" PATTERN "*.hpp")
# install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/ DESTINATION ${OWN_LIBRARIES_DIR}/include
# FILES_MATCHING PATTERN "*.h" PATTERN "*.hpp")
# message(STATUS "OWN_LIBRARIES_DIR: ${OWN_LIBRARIES_DIR}")
1 change: 1 addition & 0 deletions modules/backend/serializer/Serializer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "Serializer.hpp"
6 changes: 3 additions & 3 deletions modules/backend/serializer/Serializer.hpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#pragma once

#include "SerializerHelper.hpp"
#include "clinic/staff/Staff.hpp"
#include "common/file_manager/FileManager.hpp"
#include "common/file_manager/Paths.hpp"
#include "staff/Staff.hpp"
#include "file_manager/FileManager.hpp"
#include "file_manager/Paths.hpp"

namespace serde
{
Expand Down
6 changes: 3 additions & 3 deletions modules/backend/serializer/SerializerHelper.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include "staff.pb.h"
#include <staff.pb.h>
#include "staff/Staff.hpp"

namespace serde
Expand Down Expand Up @@ -101,7 +101,7 @@ ::common::PersonalData deserializePersonalData(const ::proto_common::PersonalDat
{
::common::PersonalData personal_data{
deserializeName(proto_personal_data.name()), deserializeAddress(proto_personal_data.address()),
deserializePhoneNumber(proto_personal_data.phone_numbers()), deserializePesel(proto_personal_data.pesel())};
deserializePesel(proto_personal_data.pesel()), deserializePhoneNumber(proto_personal_data.phone_numbers())};
return personal_data;
}

Expand All @@ -124,7 +124,7 @@ ::proto_staff::Staff serializeStaff(const ::clinic::staff::Staff& staff)
{
serializeDoctor(doctor, proto_staff.add_doctor());
}

return proto_staff;
}

Expand Down
38 changes: 38 additions & 0 deletions modules/backend/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# cmake_minimum_required(VERSION 3.23)
# project(desktop-business-app-tests)

# set(CMAKE_CXX_STANDARD 20)

# TODO: adjust both after new structure is finalized
# set(BACKEND_LIB_DIRECTORY ${PROJECT_SOURCE_DIR}/../backend/)
# set(OWN_LIB_DIRECTORY ${PROJECT_SOURCE_DIR}/../../own_libraries)
message(STATUS "BACKEND_LIB_DIRECTORY: ${BACKEND_LIB_DIRECTORY}")
# message(STATUS "OWN_LIB_DIRECTORY: ${OWN_LIB_DIRECTORY}")

# test binaries will be in this directory
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/../../bin)

include(install_gtest.cmake)

include(GoogleTest)
enable_testing()

# Set vars to the path to the libraries installed from backend
# set(CLINIC_LIB ${OWN_LIB_DIRECTORY}/libclinic-lib.a)
# set(COMMON_LIB ${OWN_LIB_DIRECTORY}/libcommon-lib.a)
# set(PATIENTS_LIB ${OWN_LIB_DIRECTORY}/libpatients-lib.a)
# set(SERIALIZER_LIB ${OWN_LIB_DIRECTORY}/libserializer-lib.a)
# set(VISITS_LIB ${OWN_LIB_DIRECTORY}/libvisits-lib.a)
# set(WAREHOUSE_LIB ${OWN_LIB_DIRECTORY}/libwarehouse-lib.a)

# Set the path to the headers installed from backend
# set(OWN_LIBS_INCLUDE_DIR ${BACKEND_LIB_DIRECTORY})

# Global settings for memory checks
include(CTest)
set(MEMORYCHECK_COMMAND_OPTIONS
"--trace-children=yes --leak-check=full --show-reachable=yes --read-var-info=yes --track-origins=yes --error-limit=no -error-exitcode=1")
set(MEMORYCHECK_COMMAND valgrind)

add_subdirectory(unit)
add_subdirectory(integration)
File renamed without changes.
Loading

0 comments on commit 7b3a2f6

Please sign in to comment.