diff --git a/cpp/CMakeLists.txt b/cpp/CMakeLists.txt index fad727416..6298e32ec 100644 --- a/cpp/CMakeLists.txt +++ b/cpp/CMakeLists.txt @@ -41,26 +41,16 @@ include(ExternalProject) include(cugraph) # Install testing dependencies (gtest) -set(GTEST_ROOT ${PROJECT_BINARY_DIR}/gtest) -ExternalProject_Add(gtest-proj - PREFIX ${GTEST_ROOT} - INSTALL_DIR ${GTEST_ROOT} +FetchContent_Declare(googletest GIT_REPOSITORY https://github.com/google/googletest.git GIT_TAG v1.16.0 - CMAKE_ARGS "-DCMAKE_INSTALL_PREFIX=" - "-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}" - "-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}" - "-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}") -set(GTEST_INCLUDE_DIR ${GTEST_ROOT}/include) -set(GTEST_LIBRARY_PATH ${GTEST_ROOT}/lib/${CMAKE_FIND_LIBRARY_PREFIXES}gtest.a) -set(GTEST_DEBUG_LIBRARY_PATH ${GTEST_ROOT}/lib/${CMAKE_FIND_LIBRARY_PREFIXES}gtestd.a) -add_library(mage_gtest STATIC IMPORTED) -set_target_properties(mage_gtest PROPERTIES - IMPORTED_LOCATION "${GTEST_LIBRARY_PATH}" - IMPORTED_LOCATION_DEBUG "${GTEST_DEBUG_LIBRARY_PATH}" - INTERFACE_LINK_LIBRARIES "${CMAKE_THREAD_LIBS_INIT}") -include_directories("${GTEST_INCLUDE_DIR}") -add_dependencies(mage_gtest gtest-proj) +) +# For Windows: Prevent overriding the parent project's compiler/linker settings +set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) +FetchContent_MakeAvailable(googletest) + +# Create an alias for consistency with existing code +add_library(mage_gtest ALIAS gtest) # Add OpenMP compiling option find_package(OpenMP) diff --git a/cpp/betweenness_centrality_module/CMakeLists.txt b/cpp/betweenness_centrality_module/CMakeLists.txt index 784e266ba..6fb9c1542 100644 --- a/cpp/betweenness_centrality_module/CMakeLists.txt +++ b/cpp/betweenness_centrality_module/CMakeLists.txt @@ -29,25 +29,23 @@ endif() set(betweenness_centrality_online_src betweenness_centrality_online_module.cpp algorithm/betweenness_centrality.cpp - algorithm_online/betweenness_centrality_online.cpp - ../biconnected_components_module/algorithm/biconnected_components.cpp) + algorithm_online/betweenness_centrality_online.cpp) add_query_module(betweenness_centrality_online 1 "${betweenness_centrality_online_src}") # Link external libraries -target_link_libraries(betweenness_centrality_online PRIVATE mg_utility) +target_link_libraries(betweenness_centrality_online PRIVATE mg_utility biconnected_components_algorithm) target_include_directories(betweenness_centrality_online PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) # Module tests if (NOT MAGE_CUGRAPH_ENABLE) include(GoogleTest) - set(betweenness_centrality_online_src + set(betweenness_centrality_online_test_src betweenness_centrality_online_test.cpp algorithm/betweenness_centrality.cpp - algorithm_online/betweenness_centrality_online.cpp - ../biconnected_components_module/algorithm/biconnected_components.cpp) + algorithm_online/betweenness_centrality_online.cpp) - add_executable(betweenness_centrality_online_test "${betweenness_centrality_online_src}") - target_link_libraries(betweenness_centrality_online_test PRIVATE mg_utility mage_gtest) + add_executable(betweenness_centrality_online_test "${betweenness_centrality_online_test_src}") + target_link_libraries(betweenness_centrality_online_test PRIVATE mg_utility mage_gtest biconnected_components_algorithm) gtest_add_tests(TARGET betweenness_centrality_online_test) endif() diff --git a/cpp/biconnected_components_module/CMakeLists.txt b/cpp/biconnected_components_module/CMakeLists.txt index d1cac144b..d0e945562 100644 --- a/cpp/biconnected_components_module/CMakeLists.txt +++ b/cpp/biconnected_components_module/CMakeLists.txt @@ -1,21 +1,25 @@ -set(biconnected_components_module_src - biconnected_components_module.cpp +# Create a static library for the shared algorithm code +add_library(biconnected_components_algorithm STATIC algorithm/biconnected_components.cpp) +target_include_directories(biconnected_components_algorithm PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) +target_link_libraries(biconnected_components_algorithm PRIVATE mg_utility) + +set(biconnected_components_module_src + biconnected_components_module.cpp) add_query_module(biconnected_components 1 "${biconnected_components_module_src}") # Link external libraries -target_link_libraries(biconnected_components PRIVATE mg_utility) +target_link_libraries(biconnected_components PRIVATE mg_utility biconnected_components_algorithm) target_include_directories(biconnected_components PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) # Module tests if (NOT MAGE_CUGRAPH_ENABLE) include(GoogleTest) set(biconnected_components_test_src - biconnected_components_test.cpp - algorithm/biconnected_components.cpp) + biconnected_components_test.cpp) add_executable(biconnected_components_test "${biconnected_components_test_src}") - target_link_libraries(biconnected_components_test PRIVATE mg_utility mage_gtest) + target_link_libraries(biconnected_components_test PRIVATE mg_utility mage_gtest biconnected_components_algorithm) gtest_add_tests(TARGET biconnected_components_test) -endif() \ No newline at end of file +endif() diff --git a/rust/rsmgp-sys/src/temporal/mod.rs b/rust/rsmgp-sys/src/temporal/mod.rs index 31452f2d3..1f2f3829d 100644 --- a/rust/rsmgp-sys/src/temporal/mod.rs +++ b/rust/rsmgp-sys/src/temporal/mod.rs @@ -76,7 +76,8 @@ impl Date { } pub fn to_naive_date(&self) -> NaiveDate { - NaiveDate::from_ymd(self.year(), self.month(), self.day()) + NaiveDate::from_ymd_opt(self.year(), self.month(), self.day()) + .expect("Invalid date parameters from Memgraph") } pub fn mgp_ptr(&self) -> *mut mgp_date { @@ -106,12 +107,13 @@ fn create_naive_time( millisecond: u32, microsecond: u32, ) -> NaiveTime { - NaiveTime::from_hms_micro( + NaiveTime::from_hms_micro_opt( hour, minute, second, millisecond * MICROS_PER_MILLIS + microsecond, ) + .expect("Invalid time parameters from Memgraph") } fn create_mgp_local_time_parameters(from: &NaiveTime) -> mgp_local_time_parameters { @@ -177,7 +179,8 @@ impl LocalTime { let timestamp = self.timestamp(); let seconds = (timestamp / MICROS_PER_SECOND) as u32; let micros = (timestamp % MICROS_PER_SECOND) as u32; - NaiveTime::from_num_seconds_from_midnight(seconds, micros * NANOS_PER_MICROS) + NaiveTime::from_num_seconds_from_midnight_opt(seconds, micros * NANOS_PER_MICROS) + .expect("Invalid time parameters from Memgraph") } pub fn mgp_ptr(&self) -> *mut mgp_local_time { @@ -272,13 +275,15 @@ impl LocalDateTime { } pub fn to_naive_date_time(&self) -> NaiveDateTime { - NaiveDate::from_ymd(self.year(), self.month(), self.day()).and_time(create_naive_time( - self.hour(), - self.minute(), - self.second(), - self.millisecond(), - self.microsecond(), - )) + NaiveDate::from_ymd_opt(self.year(), self.month(), self.day()) + .expect("Invalid date parameters from Memgraph") + .and_time(create_naive_time( + self.hour(), + self.minute(), + self.second(), + self.millisecond(), + self.microsecond(), + )) } pub fn mgp_ptr(&self) -> *mut mgp_local_date_time { diff --git a/setup b/setup index 931b14c8f..1a9436379 100755 --- a/setup +++ b/setup @@ -191,8 +191,8 @@ def build_and_copy_cpp_modules(args: Dict[str, Any]) -> bool: os.makedirs(CPP_BUILD_DIRECTORY, exist_ok=True) # Prepare CMake flags - os.chdir(CPP_BUILD_DIRECTORY) - cmake_args = [".."] + os.chdir(CPP_DIRECTORY) + cmake_args = [".", "-B", CPP_BUILD_DIRECTORY] if args[Parameter.GPU.value]: cmake_args.append(f"-D{MAGE_GPU_BUILD}") if args[Parameter.CPP_BUILD_FLAGS.value] is not None: @@ -200,15 +200,14 @@ def build_and_copy_cpp_modules(args: Dict[str, Any]) -> bool: else: cmake_args += [f"-DCMAKE_BUILD_TYPE={BuildType.RELEASE}"] - cmake_command = ["cmake"] + cmake_args + cmake_command = ["cmake"] + cmake_args + ["-GNinja"] cmake_status = run_command(cmake_command) if not cmake_status: logger.error("[Terminal] (1/7) Building C++ modules failed.") return False - core_count = mp.cpu_count() - make_command = ["make", f"-j{core_count}"] + make_command = ["cmake", "--build", CPP_BUILD_DIRECTORY] make_status = run_command(make_command) if not make_status: