diff --git a/.github/workflows/gh-actions.yml b/.github/workflows/gh-actions.yml index ef4660d..ee9fe18 100644 --- a/.github/workflows/gh-actions.yml +++ b/.github/workflows/gh-actions.yml @@ -93,8 +93,8 @@ jobs: - name: Build # Build your program with the given configuration. Note that --config is needed because the default Windows generator is a multi-config generator (Visual Studio generator). run: > - cmake --build ${{ steps.strings.outputs.build-output-dir }} --config ${{ matrix.build_type }} # && - # cmake --build ${{ steps.strings.outputs.build-output-dir }} --config ${{ matrix.build_type }} --target vm_unit_tests + cmake --build ${{ steps.strings.outputs.build-output-dir }} --config ${{ matrix.build_type }} && + cmake --build ${{ steps.strings.outputs.build-output-dir }} --config ${{ matrix.build_type }} --target vm_unit_tests - name: Test diff --git a/CMakeLists.txt b/CMakeLists.txt index 0b8af2e..200d340 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -38,15 +38,14 @@ CPMAddPackage( "gh:psiha/std_fix#master" ) CPMAddPackage( "gh:psiha/err#master" ) CPMAddPackage( "gh:psiha/build#master" ) -CPMAddPackage( "gh:google/googletest@1.14.0" ) - - +if ( ${CMAKE_SYSTEM_NAME} MATCHES "Linux" ) + set( PSI_USE_LINKER "lld" ) # for thinlto-cache-dir support +endif() include( ${build_SOURCE_DIR}/build_options.cmake ) PSI_add_compile_options( Debug ${PSI_compiler_runtime_sanity_checks} ) PSI_add_link_options ( Debug ${PSI_linker_runtime_sanity_checks} ) -set( CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELEASE true ) PSI_add_link_options ( Release ${PSI_linker_LTO} ) PSI_add_compile_options( Release ${PSI_compiler_LTO} ${PSI_compiler_optimize_for_size} ${PSI_compiler_disable_thread_safe_init} ${PSI_compiler_fastmath} ${PSI_compiler_debug_symbols} ) @@ -54,13 +53,24 @@ if ( WIN32 ) add_compile_definitions( WIN32_LEAN_AND_MEAN NOMINMAX NOCOMM ) endif() +if ( ${CMAKE_SYSTEM_NAME} MATCHES "Linux" ) + PSI_add_link_options( Release -flto ) # lld does not seem to be enough + add_compile_options( -stdlib=libc++ ) + # Needed under WSL for some reason? + PSI_add_link_options( Debug -lc++ -lc++abi -lubsan ) +else() +set( CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELEASE true ) +PSI_add_link_options( Release ${PSI_linker_LTO} ) +endif() + + ################### ## Target(s) ################### include( vm.cmake ) -target_link_libraries( psi_vm PRIVATE +target_link_libraries( psi_vm PUBLIC Boost::core Boost::assert Boost::preprocessor @@ -68,16 +78,14 @@ target_link_libraries( psi_vm PRIVATE Boost::utility ) -target_include_directories( psi_vm PRIVATE - "${assert_SOURCE_DIR}/include" - "${core_SOURCE_DIR}/include" - "${preprocessor_SOURCE_DIR}/include" - "${winapi_SOURCE_DIR}/include" - "${utility_SOURCE_DIR}/include" +target_include_directories( psi_vm PUBLIC + "${build_SOURCE_DIR}/include" "${config_ex_SOURCE_DIR}/include" - "${std_fix_SOURCE_DIR}/include" "${err_SOURCE_DIR}/include" - "${build_SOURCE_DIR}/include" +) + +target_include_directories( psi_vm PRIVATE + "${std_fix_SOURCE_DIR}/include" ) ################### @@ -85,5 +93,4 @@ target_include_directories( psi_vm PRIVATE ################### enable_testing() - add_subdirectory( "${PROJECT_SOURCE_DIR}/test" ) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 10082dd..5d21b04 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,44 +1,33 @@ -# TESTS -include(GoogleTest) +# psi::vm tests -# set( -# vm_test_sources -# -# # Common -# "${PROJECT_SOURCE_DIR}/test/pch.hpp" -# -# # Core tests -# "${CMAKE_CURRENT_SOURCE_DIR}/vector_test.cpp" -# ) -# -# Creating executable test target -# add_executable(rama_unit_tests EXCLUDE_FROM_ALL ${rama_test_sources}) -# target_link_libraries(rama_unit_tests database api GTest::gtest GTest::gtest_main Boost::boost Boost.Container ) -# target_precompile_headers(rama_unit_tests PRIVATE "${PROJECT_SOURCE_DIR}/test/pch.hpp") -# target_include_directories( -# rama_unit_tests -# PRIVATE -# ${PROJECT_SOURCE_DIR}/src -# ${PROJECT_SOURCE_DIR}/deps/gtest/googletest/include -# ${PROJECT_SOURCE_DIR}/deps/range-v3/include -# ${PROJECT_SOURCE_DIR}/deps/psiha/std_fix/include -# ) -# set_target_properties( -# rama_unit_tests -# PROPERTIES -# RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/test" -# COMMAND rama_unit_tests -# ) -# -# gtest_discover_tests( -# rama_unit_tests -# EXTRA_ARGS -# --gtest_color=auto -# --gtest_output=xml:${CMAKE_BINARY_DIR}/test/rama_unit_tests.xml -# --gtest_catch_exceptions=0 -# DISCOVERY_TIMEOUT 120 -# PROPERTIES -# TIMEOUT 120 -# ) -# -# add_test("rama_unit_tests" rama_unit_tests) +# Fix ODR violations and compiler and linker option mismatches: add GTest after everything is already setup. +CPMAddPackage( "gh:google/googletest@1.14.0" ) + +include( GoogleTest ) + +set( vm_test_sources + "${CMAKE_CURRENT_SOURCE_DIR}/vector.cpp" +) + +add_executable( vm_unit_tests EXCLUDE_FROM_ALL ${vm_test_sources} ) +target_link_libraries( vm_unit_tests PRIVATE GTest::gtest GTest::gtest_main psi::vm ) + +set_target_properties( + vm_unit_tests + PROPERTIES + RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/test" + COMMAND vm_unit_tests +) + +gtest_discover_tests( + vm_unit_tests + EXTRA_ARGS + --gtest_color=auto + --gtest_output=xml:${CMAKE_BINARY_DIR}/test/vm_unit_tests.xml + --gtest_catch_exceptions=1 + DISCOVERY_TIMEOUT 120 + PROPERTIES + TIMEOUT 120 +) + +add_test( "vm_unit_tests" vm_unit_tests ) diff --git a/test/vector.cpp b/test/vector.cpp new file mode 100644 index 0000000..cb9ad46 --- /dev/null +++ b/test/vector.cpp @@ -0,0 +1,39 @@ +#include + +#include + +#include +#include +#include +//------------------------------------------------------------------------------ +namespace psi::vm +{ +//------------------------------------------------------------------------------ + +TEST( vector, playground ) +{ + std::filesystem::path const test_vec{ "test_vec" }; + std::filesystem::remove( test_vec ); + { + psi::vm::vector< double, std::uint16_t > vec; + vec.open( test_vec.c_str() ); + EXPECT_EQ( vec.size(), 0 ); + vec.append_range({ 3.14, 0.14, 0.04 }); + EXPECT_EQ( vec.size(), 3 ); + EXPECT_EQ( vec[ 0 ], 3.14 ); + EXPECT_EQ( vec[ 1 ], 0.14 ); + EXPECT_EQ( vec[ 2 ], 0.04 ); + } + { + psi::vm::vector< double, std::uint16_t > vec; + vec.open( test_vec.c_str() ); + EXPECT_EQ( vec.size(), 3 ); + EXPECT_EQ( vec[ 0 ], 3.14 ); + EXPECT_EQ( vec[ 1 ], 0.14 ); + EXPECT_EQ( vec[ 2 ], 0.04 ); + } +} + +//------------------------------------------------------------------------------ +} // namespace psi::vm +//------------------------------------------------------------------------------