diff --git a/CMakeLists.txt b/CMakeLists.txt index 5a229bb64259d52f96d4dd9b74797390374a4996..3ed4a7df88aa517e5ca84e6b852dfdca8c6007e4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -136,9 +136,6 @@ add_custom_command( # add generated files to include path include_directories(${CMAKE_CURRENT_BINARY_DIR}/include) -# show generated files -message(DEBUG "GRPC_GENERATED: ${GRPC_GENERATED}") - ############################################################################### ### Set up main targets ### * linkahead - The main library including the protobuf and grpc generated files. @@ -165,13 +162,19 @@ message(DEBUG "CMAKE_CXX_FLAGS: ${CMAKE_CXX_FLAGS}") message(DEBUG "liblinkahead_SOURCE_DIR: ${liblinkahead_SOURCE_DIR}") message(DEBUG "liblinkahead_BINARY_DIR: ${liblinkahead_BINARY_DIR}") +# libcaosdb_grpc +# -------------- +add_library(caosdb_grpc STATIC ${GRPC_GENERATED}) +target_link_libraries(caosdb_grpc + gRPC::grpc gRPC::grpc++ protobuf::libprotobuf +) # liblinkahead # --------- add_library(linkahead SHARED - ${liblinkahead_INCL} ${liblinkahead_SRC} ${GRPC_GENERATED}) + ${liblinkahead_INCL} ${liblinkahead_SRC}) target_link_libraries(linkahead PUBLIC - gRPC::grpc gRPC::grpc++ protobuf::libprotobuf ${Boost_LIBRARIES} + caosdb_grpc gRPC::grpc gRPC::grpc++ protobuf::libprotobuf ${Boost_LIBRARIES} ) set(liblinkahead linkahead) @@ -184,10 +187,9 @@ target_include_directories(linkahead PUBLIC # libclinkahead # ---------- -add_library(clinkahead SHARED src/clinkahead.cpp ${GRPC_GENERATED}) +add_library(clinkahead SHARED src/clinkahead.cpp) target_link_libraries(clinkahead PUBLIC - linkahead - gRPC::grpc gRPC::grpc++ protobuf::libprotobuf ${Boost_LIBRARIES} + linkahead caosdb_grpc gRPC::grpc gRPC::grpc++ protobuf::libprotobuf ${Boost_LIBRARIES} ) target_include_directories(clinkahead PUBLIC $<BUILD_INTERFACE:${liblinkahead_SOURCE_DIR}/include> @@ -204,10 +206,9 @@ target_include_directories(clinkaheadcli PUBLIC $<BUILD_INTERFACE:${liblinkahead_BINARY_DIR}/include> $<INSTALL_INTERFACE:include> ) - target_link_libraries(clinkaheadcli PRIVATE + caosdb_grpc clinkahead gRPC::grpc protobuf::libprotobuf ${Boost_LIBRARIES} - clinkahead ) # cxxlinkaheadcli @@ -219,7 +220,7 @@ target_include_directories(cxxlinkaheadcli PUBLIC $<INSTALL_INTERFACE:include> ) target_link_libraries(cxxlinkaheadcli PRIVATE - linkahead gRPC::grpc++ protobuf::libprotobuf ${Boost_LIBRARIES} + linkahead caosdb_grpc gRPC::grpc++ protobuf::libprotobuf ${Boost_LIBRARIES} ) @@ -346,10 +347,10 @@ endif() ### UNIT TEST ####################################################### -if("${CMAKE_BUILD_TYPE}" MATCHES "Debug") +#if("${CMAKE_BUILD_TYPE}" MATCHES "Debug") enable_testing() add_subdirectory(test) -endif() +#endif() # ############################################### # ############ INSTALLATION ##################### @@ -361,7 +362,7 @@ set(liblinkahead_LIB_DEST "lib") set(CMAKE_INSTALL_PREFIX "$ENV{HOME}/.local/") install( # targets to install - TARGETS ${liblinkahead} clinkahead + TARGETS linkahead clinkahead caosdb_grpc # name of the CMake "export group" containing the targets we want to install EXPORT linkaheadTargets # Dynamic, static library and include destination locations after running diff --git a/doc/Install_develop.rst b/doc/Install_develop.rst index 0f1b193c743a343062297d4a40474c0f423541b1..8661d8bf4ccd5d29cdaab98e752c7b1cded68239 100644 --- a/doc/Install_develop.rst +++ b/doc/Install_develop.rst @@ -108,22 +108,19 @@ How to build on Windows We use `Visual Studio 2022 <https://visualstudio.microsoft.com/de/vs/features/cplusplus/>`__ as compiler. We use `cmake <https://cmake.org/download/>`__ as build -tool. - -1. Install Python and create a virtual environment with the dependencies in `requirements.txt`. -2. Activate the environment run in the repository folder: ``conan install . --build=missing -s build_type=Release`` -3. ``cmake --preset conan-default`` -4. Open ``build/liblinkahead.sln`` with Visual Studio, change the - buildtype to ``Release`` and build the project (ALL_BUILD). (You - can open Tools/Command Line/Developer Command Prompt and execute - ``msbuild liblinkahead.sln /property:Configuration=Release``) -5. Try running the cli clients in ``.\build\Release\``. - -Known problems -^^^^^^^^^^^^^^ - -- Building the unit tests on Windows currently fails with linker errors. See - `#90 <https://gitlab.indiscale.com/caosdb/src/caosdb-cpplib/-/issues/90>`__ +tool, which can be installed together with Visual Studio. + +1. Install Python and create a virtual environment with the dependencies in + `requirements.txt`. +2. In a PowerShell, activate the environment and run the following commands from the + repository root: +3. ``conan profile detect --force`` (and check the output) +3. ``make.ps1 conan-install`` +4. ``make.ps1 build`` + +You'll find the shared libraries and cli clients in ``.\build\Release\``. To run the tests, +use ``make.ps1 test``. As a shortcut to run all steps, use ``make.ps1 all``. + Troubleshooting ~~~~~~~~~~~~~~~ diff --git a/make.ps1 b/make.ps1 new file mode 100644 index 0000000000000000000000000000000000000000..64d73e62b3d5d710cd6e2378679bb3bb743a29ea --- /dev/null +++ b/make.ps1 @@ -0,0 +1,80 @@ +param ( + [string]$target +) + +function Install-Conan { + Write-Output "Installing Release dependencies with Conan..." + # check if conan is available + if (-not (Get-Command conan -ErrorAction SilentlyContinue)) { + Write-Output "Conan is not available. Please install Conan or activate the Conan environment venv" + exit 1 + } + conan install . --build=missing -s build_type=Release -s compiler.cppstd=17 + cmake --preset conan-default +} + +function Build-Project { + Write-Output "Building the project..." + # check if msbuild is available + if (-not (Get-Command msbuild -ErrorAction SilentlyContinue)) { + Write-Output "msbuild is not available. Please install Visual Studio or open the Developer PowerShell." + exit 1 + } + # check if conan install was run + if (-not (Test-Path .\build\liblinkahead.sln)) { + Write-Output "Please run conan-install first." + exit 1 + } + msbuild .\build\liblinkahead.sln /property:Configuration=Release +} + +function Invoke-Tests { + Write-Output "Running tests..." + # check if build was run before + if (-not (Test-Path .\build\Release\linkahead.dll)) { + Write-Output "Please build the project first." + exit 1 + } + Set-Location .\build\ + ctest +} + +# check if vswhere is available +if (-not (Test-Path "C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe")) { + Write-Output "vswhere is not available. Please install Visual Studio" + exit 1 +} + +# locate the latest Visual Studio installation +$currentPath = Get-Location +$installPath = &"C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe" -latest -products * -requires Microsoft.Component.MSBuild -property installationPath +Import-Module (Join-Path $installPath "Common7\Tools\Microsoft.VisualStudio.DevShell.dll") +Enter-VsDevShell -VsInstallPath $installPath +Set-Location $currentPath + + +# Windows is with Release only for now + +switch ($target) { + "build" { + Build-Project + } + "test" { + Invoke-Tests + } + "conan-install" { + Install-Conan + } + "clean"{ + Write-Output "Cleaning the project..." + Remove-Item -Recurse -Force .\build\* + } + "all" { + Install-Conan + Build-Project + Invoke-Tests + } + default { + Write-Output "Usage: .\make.ps1 [all|conan-install|build|test|clean]" + } +} diff --git a/src/linkahead/transaction.cpp b/src/linkahead/transaction.cpp index 08d507f260c4e33b4349a6f0bf0f6af2e4779172..2af4cadfef5a33cc33ae1648c19ffe73a6d99d7b 100644 --- a/src/linkahead/transaction.cpp +++ b/src/linkahead/transaction.cpp @@ -19,7 +19,7 @@ */ #include "linkahead/transaction.h" #include "caosdb/entity/v1/main.pb.h" // for EntityTransac... -#include "caosdb/entity/v1/main.grpc.pb.h" // for TransactionRe... +#include "caosdb/entity/v1/main.grpc.pb.h" // for TransactionRe... #include "linkahead/file_transmission/download_request_handler.h" // Download... #include "linkahead/file_transmission/file_reader.h" // for path #include "linkahead/file_transmission/register_file_upload_handler.h" // for RegisterFileUploadHandler diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 4442e66dcf1fbf5c832a33d352cfc75204d5a589..6497de6bd54eb4de357202116d9dd472163d5b1d 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -61,13 +61,14 @@ list(LENGTH test_cases len_test_cases) math(EXPR len_test_cases "${len_test_cases} - 1") foreach (i RANGE "${len_test_cases}") list(GET test_cases ${i} test_case_name) - add_executable(${test_case_name} ${test_case_name}.cpp) + add_executable(${test_case_name} ${test_case_name}.cpp) set(liblinkahead_TEST_SRC "${CMAKE_CURRENT_SOURCE_DIR}/${test_case_name}.cpp ${liblinkahead_TEST_SRC}") target_link_libraries(${test_case_name} - PRIVATE GTest::gtest_main linkahead clinkahead gtest::gtest) + PRIVATE GTest::gtest_main linkahead clinkahead gtest::gtest caosdb_grpc) target_include_directories(${test_case_name} - PUBLIC ${CMAKE_CURRENT_BINARY_DIR}) + PUBLIC ${CMAKE_CURRENT_BINARY_DIR}/include ${CMAKE_CURRENT_BINARY_DIR}) + set_target_properties(${test_case_name} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}") if(_LINTING) message(STATUS "linting for tests: ${_CMAKE_CXX_INCLUDE_WHAT_YOU_USE}") set_target_properties(${test_case_name} @@ -76,12 +77,15 @@ foreach (i RANGE "${len_test_cases}") CXX_INCLUDE_WHAT_YOU_USE "${_CMAKE_CXX_INCLUDE_WHAT_YOU_USE}") endif() gtest_discover_tests(${test_case_name} - WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}" + WORKING_DIRECTORY "${CMAKE_BINARY_DIR}" PROPERTIES LABELS "linkahead-cpplib-unit-tests" ) endforeach () +message(STATUS "CMAKE_BINARY_DIR ${CMAKE_BINARY_DIR}") +message(STATUS "CMAKE_CURRENT_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}") + # copy test data to build dir set(TEST_DATA_DIR "${CMAKE_CURRENT_SOURCE_DIR}/test_data") configure_file(${CMAKE_CURRENT_SOURCE_DIR}/linkahead_test_utility.h.in diff --git a/test/test_entity.cpp b/test/test_entity.cpp index c36090064ed0d5e5e158839f7f659807edfbb222..61e53c13ec41b9f0fda2ea14ea931bc7c053eaf4 100644 --- a/test/test_entity.cpp +++ b/test/test_entity.cpp @@ -20,17 +20,17 @@ * along with this program. If not, see <https://www.gnu.org/licenses/>. * */ -#include "linkahead/data_type.h" // for DataType, AtomicDat... -#include "linkahead/entity.h" // for Entity, Property -#include "caosdb/entity/v1/main.pb.h" // for EntityTransactionSe... -#include "caosdb/entity/v1/main.grpc.pb.h" // for IdResponse, Message -#include "linkahead/message_code.h" // for MessageCode, ENTITY... -#include "linkahead/protobuf_helper.h" // for get_arena -#include "linkahead/status_code.h" // for StatusCode, FILE_DO... -#include "linkahead/transaction.h" // for Transaction -#include "linkahead/value.h" // for Value -#include "linkahead_test_utility.h" // for TEST_DATA_DIR -#include <google/protobuf/arena.h> // for Arena +#include "linkahead/data_type.h" // for DataType, AtomicDat... +#include "linkahead/entity.h" // for Entity, Property +#include "caosdb/entity/v1/main.pb.h" // for EntityTransactionSe... +#include "caosdb/entity/v1/main.grpc.pb.h" // for IdResponse, Message +#include "linkahead/message_code.h" // for MessageCode, ENTITY... +#include "linkahead/protobuf_helper.h" // for get_arena +#include "linkahead/status_code.h" // for StatusCode, FILE_DO... +#include "linkahead/transaction.h" // for Transaction +#include "linkahead/value.h" // for Value +#include "linkahead_test_utility.h" // for TEST_DATA_DIR +#include <google/protobuf/arena.h> // for Arena #include <gtest/gtest.h> #include <gtest/gtest-message.h> // for Message #include <gtest/gtest-test-part.h> // for TestPartResult, Sui...