Skip to content

Commit

Permalink
#111 multiple changes:
Browse files Browse the repository at this point in the history
- adding the debug release libs for windows (#123)
- improving compilation cmake for windows so we can run latest libs without copy and paste all the time.
- added the installation targets for windows to copy all necesary libs
- fixing serialization of binary objects and reading binary objects from files, seems either new standard changed the way this work or windows works differently.
- fixing logging issue using static instances in multiple compilation units, seems either windows or new standard change this.
  • Loading branch information
agustin committed Nov 3, 2020
1 parent f666ac3 commit 1d701e6
Show file tree
Hide file tree
Showing 13 changed files with 184 additions and 45 deletions.
20 changes: 12 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ project(alias VERSION 0.5)
#configure_file(alias_config.h.in alias_config.h)
#target_include_directories(alias PUBLIC "${PROJECT_BINARY_DIR}")

# enable debug messages for now
if ("${CMAKE_BUILD_TYPE}" STREQUAL "")
set(CMAKE_BUILD_TYPE "Debug")
endif()

include(general_defs.cmake)
include(revision_creator.cmake)

Expand All @@ -23,19 +28,13 @@ include_directories(BEFORE SYSTEM "${ALIAS_DEP_ROOT}/include")
include_directories("${ROOT_PROJECT_DIR}/src/global/include")
link_directories("${ALIAS_DEP_ROOT}/lib")

# enable debug messages for now
add_definitions("-DDEBUG_LOG_ENABLE")
if ("${CMAKE_BUILD_TYPE}" STREQUAL "")
set(CMAKE_BUILD_TYPE "Debug")
endif()


# include the cmake project utils framework
include(${THIRD_PARTY_DIR}/cmake-project-utils/cmake_configs/global_definitions.cmake)
include(${THIRD_PARTY_DIR}/cmake-project-utils/cmake_configs/testing.cmake)

# enable debug messages for now
add_definitions("-DDEBUG_LOG_ENABLE")
add_definitions(-DDEBUG_LOG_ENABLE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -std=c++17")

# Find includes in corresponding build directories
Expand All @@ -57,7 +56,12 @@ add_subdirectory(third_party/googletest EXCLUDE_FROM_ALL)
################################
enable_global_testing()


# we want to setup the output of all libs and executables to the same place in windows
# to test it easily
if(WIN32)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
endif(WIN32)

# When done tweaking common stuff, configure the components (subprojects).
# NOTE: The order matters! The most independent ones should go first.
Expand Down
49 changes: 42 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,14 +149,23 @@ To compile, make sure you have downloaded the repo and configured the environmen
- Create the dependencies folder
```bash
mkdir %ALIAS_DEP_ROOT%
mkdir %ALIAS_DEP_ROOT%/Debug
mkdir %ALIAS_DEP_ROOT%/Release
```

- Compile protobuf
```bash
# ensure that $ALIAS_ROOT and all env vars exists and is set
cd %ALIAS_REPO_ROOT%/third_party/protobuf/cmake && mkdir build && cd build
cmake -Dprotobuf_BUILD_SHARED_LIBS=ON -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX="%ALIAS_DEP_ROOT%" -Dprotobuf_BUILD_TESTS=OFF -G "MinGW Makefiles" ..
#compile release
cmake -Dprotobuf_BUILD_SHARED_LIBS=ON -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX="%ALIAS_DEP_ROOT%/Release/" -Dprotobuf_BUILD_TESTS=OFF -G "MinGW Makefiles" ..
cmake --build . --target install --config Release -- -j 8

# Debug we will use the same than release since we do not care to debug this
cmake -Dprotobuf_BUILD_SHARED_LIBS=ON -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX="%ALIAS_DEP_ROOT%/Debug/" -Dprotobuf_BUILD_TESTS=OFF -G "MinGW Makefiles" ..
cmake --build . --target install --config Release -- -j 8


```

- compile qxtglobalshortcut dependency
Expand All @@ -165,25 +174,51 @@ cmake --build . --target install --config Release -- -j 8
cd %ALIAS_REPO_ROOT%/third_party/qxtglobalshortcut && mkdir build && cd build
#cmake -DCMAKE_PREFIX_PATH:PATH="C:\Qt\5.12.4\mingw73_64\lib\cmake" -DCMAKE_INSTALL_PREFIX:PATH="%ALIAS_DEP_ROOT%" -DBUILD_SHARED_LIBS=ON -DCMAKE_BUILD_TYPE=Release -G "MinGW Makefiles" ..
#cmake --build . --target install --config Release -- -j 8
cmake -DCMAKE_PREFIX_PATH:PATH="C:\Qt\5.12.4\mingw73_64\lib\cmake" -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX:PATH="%ALIAS_DEP_ROOT%" -DBUILD_SHARED_LIBS=ON -G "MinGW Makefiles" ..
cmake --build . --target install -- -j 8

# Compile release
cmake -DCMAKE_PREFIX_PATH:PATH="C:\Qt\5.12.4\mingw73_64\lib\cmake" -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX:PATH="%ALIAS_DEP_ROOT%/Release" -DBUILD_SHARED_LIBS=ON -G "MinGW Makefiles" ..
cmake --build . --target install --config Release -- -j 8

# Compile debug
del *.* /Q
cmake -DCMAKE_PREFIX_PATH:PATH="C:\Qt\5.12.4\mingw73_64\lib\cmake" -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX:PATH="%ALIAS_DEP_ROOT%/Debug" -DBUILD_SHARED_LIBS=ON -G "MinGW Makefiles" ..
cmake --build . --target install --config Debug -- -j 8

```

- Compile special dependency crossguid
```bash
# Release
cd %ALIAS_REPO_ROOT%/third_party/crossguid && mkdir build && cd build
cmake -DCMAKE_INSTALL_PREFIX:PATH="%ALIAS_DEP_ROOT%" -DBUILD_SHARED_LIBS=ON -G "MinGW Makefiles" ..
cmake --build . --target install
cmake -DCMAKE_INSTALL_PREFIX:PATH="%ALIAS_DEP_ROOT%/Release" -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON -G "MinGW Makefiles" ..
cmake --build . --target install --config Release -- -j 8

# Debug
del *.* /Q
cmake -DCMAKE_INSTALL_PREFIX:PATH="%ALIAS_DEP_ROOT%/Debug" -DCMAKE_BUILD_TYPE=Debug -DBUILD_SHARED_LIBS=ON -G "MinGW Makefiles" ..
cmake --build . --target install --config Debug -- -j 8

```

#### Project

Now you should be able to compile the project.


Release

```bash
mkdir "%ALIAS_ROOT%/build-Release" && cd "%ALIAS_ROOT%/build-Release"
cmake -DCMAKE_PREFIX_PATH:PATH="C:\Qt\5.12.4\mingw73_64\lib\cmake" -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX:PATH="C:/alias/" -G "MinGW Makefiles" "%ALIAS_REPO_ROOT%"
cmake --build . --target install --config Release -- -j 8
```

Debug

```bash
mkdir "%ALIAS_ROOT%/build-Debug" && cd "%ALIAS_ROOT%/build-Debug"
cmake -DCMAKE_PREFIX_PATH:PATH="C:\Qt\5.12.4\mingw73_64\lib\cmake" -G "MinGW Makefiles" "%ALIAS_REPO_ROOT%"
cmake --build .
cmake -DCMAKE_PREFIX_PATH:PATH="C:\Qt\5.12.4\mingw73_64\lib\cmake" -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX:PATH="C:/alias/" -G "MinGW Makefiles" "%ALIAS_REPO_ROOT%"
cmake --build . --target install -- -j 8
```


Expand Down
4 changes: 2 additions & 2 deletions general_defs.cmake
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# We will define here all the general definitions we need in order to configure properly this project

# ENV_VARS ALIAS_DEP_ROOT
set(ALIAS_DEP_ROOT "$ENV{ALIAS_ROOT}/dependencies")
# ENV_VARS ALIAS_DEP_ROOT + build type
set(ALIAS_DEP_ROOT "$ENV{ALIAS_ROOT}/dependencies/${CMAKE_BUILD_TYPE}")

# Root source project is the same for all cases
set(ROOT_PROJECT_DIR ${PROJECT_SOURCE_DIR})
Expand Down
52 changes: 46 additions & 6 deletions install_targets.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
# Configure the install to be in a specific folder the binary and the libs that is not
# the /usr/bin for now




# check the default destination folder
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
# TODO: check on windows?
Expand All @@ -25,10 +28,12 @@ set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
list(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_PREFIX}/app" isSystemDir)
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/app")

set(DEST_INSTALL_BIN_PATH ${CMAKE_INSTALL_PREFIX}/app)


# set the install targets for all the project libs
# TODO: we can iterate on the global variable of all targets here instead?
set(INSTALL_TARGETS_LIST
set(INSTALL_TARGETS_LIBS_LIST
toolbox
encryption
data
Expand All @@ -40,21 +45,54 @@ set(INSTALL_TARGETS_LIST
)

if (UNIX)
set(INSTALL_TARGETS_LIST ${INSTALL_TARGETS_LIST} uuid)
set(INSTALL_TARGETS_LIBS_LIST ${INSTALL_TARGETS_LIBS_LIST} uuid)
endif(UNIX)

install(TARGETS ${INSTALL_TARGETS_LIST} DESTINATION app)
install(TARGETS ${INSTALL_TARGETS_LIBS_LIST} DESTINATION app)


# TODO: add the post install target to copy the third party libs (all the deps folder
# into the destination folder?
# install(CODE "cp -rf ${ALIAS_DEP_ROOT}/lib/*.so ${CMAKE_INSTALL_PREFIX}/app")

if(WIN32)
install(DIRECTORY ${ALIAS_DEP_ROOT}/bin/ DESTINATION ${CMAKE_INSTALL_PREFIX}/app
FILES_MATCHING PATTERN "*.dll*")
##
## Windows installations
##

# check the env vars are set
set(MINGW64_ROOT $ENV{MINGW64_ROOT})
set(QT_MINGW_ROOT $ENV{QT_MINGW_ROOT})
assert_def_exists(MINGW64_ROOT)
assert_def_exists(QT_MINGW_ROOT)

function(copy_libs ROOT_FOLDER LIB_NAMES)
set(full_list_files "")
foreach(the_lib IN LISTS ${LIB_NAMES})
set(full_lib_path "${ROOT_FOLDER}/${the_lib}.dll")
set(full_list_files ${full_list_files} ${full_lib_path})
endforeach()
install(FILES ${full_list_files} DESTINATION "${DEST_INSTALL_BIN_PATH}/")
endfunction()

# we need to copy all the dependencies libs from the bin folder
install(DIRECTORY ${ALIAS_DEP_ROOT}/bin/ DESTINATION ${DEST_INSTALL_BIN_PATH}
FILES_MATCHING PATTERN "*.dll")

# we need to install qt dependencies
if ("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
set(QT_DEP_LIBS Qt5Cored Qt5Guid Qt5Widgetsd)
else()
set(QT_DEP_LIBS Qt5Core Qt5Gui Qt5Widgets)
endif()
copy_libs("${QT_MINGW_ROOT}/bin" QT_DEP_LIBS)

# We need to copy the mingw c++ related libs
set(MINGW_DEP_LIBS libgcc_s_seh-1 libstdc++-6 libwinpthread-1)
copy_libs("${MINGW64_ROOT}/bin" MINGW_DEP_LIBS)

else(WIN32)
install(DIRECTORY ${ALIAS_DEP_ROOT}/lib/ DESTINATION ${CMAKE_INSTALL_PREFIX}/app
install(DIRECTORY ${ALIAS_DEP_ROOT}/lib/ DESTINATION ${DEST_INSTALL_BIN_PATH}
FILES_MATCHING PATTERN "*.so*")
endif(WIN32)

Expand All @@ -63,3 +101,5 @@ install(FILES "${ROOT_PROJECT_DIR}/resources/config/init.json" DESTINATION ${CMA

# create the storage empty folder
install(DIRECTORY DESTINATION ${CMAKE_INSTALL_PREFIX}/storage)


14 changes: 14 additions & 0 deletions src/data/include/data/content.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include <string>
#include <memory>
#include <ostream>
#include <set>

#include <toolbox/types/id_type.h>
Expand Down Expand Up @@ -189,6 +190,19 @@ Content::clonePtr(bool clone_id) const
return result;
}

static inline std::ostream&
operator<<(std::ostream& out_stream, const Content& c)
{
out_stream << "Content {uuid: " << c.id() << ", content-size: " << c.data().size()
<< ", tag-ids: {";
for (const auto& t_id : c.tagIDs()) {
out_stream << t_id.toStr() << ", ";
}
out_stream << "} }";
return out_stream;
}



} // namespace data

Expand Down
8 changes: 1 addition & 7 deletions src/qt_client/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,7 @@ set(CMAKE_AUTOUIC ON)

# Find the QtWidgets library
find_package(Qt5Widgets CONFIG REQUIRED)
set(LIB_DEPENDENCIES_LIST Qt5::Widgets)
if (DEBUG_MODE)
set(LIB_DEPENDENCIES_LIST ${LIB_DEPENDENCIES_LIST} qxtglobalshortcutd)
else(DEBUG_MODE)
set(LIB_DEPENDENCIES_LIST ${LIB_DEPENDENCIES_LIST} qxtglobalshortcut)
endif(DEBUG_MODE)

set(LIB_DEPENDENCIES_LIST Qt5::Widgets qxtglobalshortcut)


##
Expand Down
2 changes: 1 addition & 1 deletion src/service/src/service_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ ServiceAPI::getRelevantSuggestions(const std::string& query,

const std::string norm_query = normalizeTagText(query);
auto suggestions = data_mapper_->suggestedTags(norm_query);
for (const data::Tag::ConstPtr& suggested_tag : suggestions) {
for (const auto& suggested_tag : suggestions) {
// here we will filtered out the Tags that don't have any element in common
// with the Tags already set by the user
if (current_tags.empty() ||
Expand Down
31 changes: 23 additions & 8 deletions src/storage/src/file_storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,14 @@ buildFileNameFromTag(const data::Tag& tag)
static data::Content::Ptr
contentFromFile(const std::string& file_path)
{
std::ifstream filestream(file_path.c_str(), std::ifstream::binary);

if (!filestream.is_open() || !filestream.good()) {
LOG_ERROR("We couldn't read the file " << file_path);
return data::Content::Ptr();
}

proto::Content proto;
std::ifstream filestream(file_path.c_str(), std::ifstream::in);
const bool success = proto.ParseFromIstream(&filestream);

filestream.close();
Expand All @@ -63,15 +69,19 @@ contentFromFile(const std::string& file_path)
return data::Content::Ptr();
}

LOG_INFO("**** loading Proto tag ids count: " << proto.tag_ids_size() << " from " << file_path);

return data::Content::Ptr(new data::Content(protos::ConvertUtils::fromProto(proto)));
}

static bool
contentToFile(const data::Content& content, const std::string& file_path)
{
std::ofstream out_stream(file_path.c_str(), std::ofstream::binary);
const proto::Content proto = protos::ConvertUtils::toProto(content);
const std::string serialized = proto.SerializeAsString();
return toolbox::OSHelper::writeFileData(file_path, serialized);
const bool success = proto.SerializeToOstream(&out_stream);
out_stream.close();
return success;
}

/**
Expand All @@ -83,7 +93,7 @@ static data::Tag::Ptr
tagFromFile(const std::string& file_path)
{
proto::Tag proto;
std::ifstream filestream(file_path.c_str(), std::ifstream::in);
std::ifstream filestream(file_path.c_str(), std::ifstream::binary);
const bool success = proto.ParseFromIstream(&filestream);

filestream.close();
Expand All @@ -99,9 +109,11 @@ tagFromFile(const std::string& file_path)
static bool
tagToFile(const data::Tag& tag, const std::string& file_path)
{
std::ofstream out_stream(file_path.c_str(), std::ofstream::binary);
const proto::Tag proto = protos::ConvertUtils::toProto(tag);
const std::string serialized = proto.SerializeAsString();
return toolbox::OSHelper::writeFileData(file_path, serialized);
const bool success = proto.SerializeToOstream(&out_stream);
out_stream.close();
return success;
}


Expand Down Expand Up @@ -152,11 +164,12 @@ FileStorage::loadAllContent(std::vector<data::Content::Ptr>& contents)
if (fname.find(".content") == std::string::npos) {
continue;
}
const std::string full_path = content_folder_path_ + fname;
const std::string full_path = toolbox::OSHelper::normalizeFilePath(content_folder_path_, fname);
data::Content::Ptr content = contentFromFile(full_path);
if (content.get() != nullptr) {
contents.push_back(content);
}
LOG_INFO("==== content loaded: " << *content);
}

return true;
Expand All @@ -172,7 +185,7 @@ FileStorage::loadAllTags(std::vector<data::Tag::Ptr>& tags)
if (fname.find(".tag") == std::string::npos) {
continue;
}
const std::string full_path = tags_folder_path_ + fname;
const std::string full_path = toolbox::OSHelper::normalizeFilePath(tags_folder_path_, fname);
data::Tag::Ptr tag = tagFromFile(full_path);
if (tag.get() != nullptr) {
tags.push_back(tag);
Expand All @@ -197,6 +210,8 @@ FileStorage::saveContent(const data::Content::Ptr& content)
return false;
}

LOG_INFO("==== content saved: " << *content);

return true;
}

Expand Down
Loading

0 comments on commit 1d701e6

Please sign in to comment.