@@ -13,63 +13,55 @@ add_subdirectory(pybind11)
1313
1414option (EASYGRAPH_ENABLE_GPU "EASYGRAPH_ENABLE_GPU" OFF )
1515
16- # 启用OpenMP支持
16+ # Find OpenMP (optional)
1717find_package (OpenMP )
1818if (OpenMP_CXX_FOUND)
1919 message (STATUS "Found OpenMP: ${OpenMP_CXX_VERSION} " )
20- message (STATUS "OpenMP flags: ${OpenMP_CXX_FLAGS} " )
2120else ()
22- message (WARNING "OpenMP not found. Parallel optimization will be disabled. " )
21+ message (STATUS "OpenMP not found; continuing without OpenMP " )
2322endif ()
2423
25- # 查找ARPACK库(兼容无CMake配置的系统)
26- find_library (ARPACK_LIB NAMES arpack arpack_double PATHS ENV LD_LIBRARY_PATH )
27- if (NOT ARPACK_LIB)
28- message (FATAL_ERROR "ARPACK library not found" )
29- else ()
24+ # Find ARPACK (optional; do not fail if absent)
25+ find_library (ARPACK_LIB NAMES arpack arpack_double )
26+ if (ARPACK_LIB)
3027 message (STATUS "Found ARPACK library: ${ARPACK_LIB} " )
28+ add_compile_definitions (HAVE_ARPACK=1 )
29+ else ()
30+ message (WARNING "ARPACK not found; ARPACK-based solvers will be disabled (fallback used)." )
31+ add_compile_definitions (HAVE_ARPACK=0 )
3132endif ()
3233
3334find_package (LAPACK REQUIRED )
3435
35- if (EASYGRAPH_ENABLE_GPU)
36-
37- pybind11_add_module (cpp_easygraph
38- ${SOURCES}
39- $<TARGET_OBJECTS :gpu_easygraph >
40- )
41-
42- set_property (TARGET cpp_easygraph PROPERTY CUDA_ARCHITECTURES all )
43-
44- target_compile_definitions (cpp_easygraph
45- PRIVATE EASYGRAPH_ENABLE_GPU
46- )
47-
48- target_link_libraries (cpp_easygraph
49- PRIVATE cudart_static
50- )
51-
52- else ()
53-
54- pybind11_add_module (cpp_easygraph
55- ${SOURCES}
56- )
57-
58- endif ()
59-
36+ # Find Eigen (optional). Change to REQUIRED if Eigen must be enforced.
6037find_package (Eigen3 QUIET )
6138if (Eigen3_FOUND)
62- message (STATUS "Found Eigen3: ${EIGEN3_INCLUDE_DIR} " )
63- include_directories (${EIGEN3_INCLUDE_DIR} )
64- add_definitions (-DEIGEN_MAJOR_VERSION=${EIGEN3_VERSION_MAJOR} )
65- endif ()
66-
67- # 将OpenMP链接到target
68- if (OpenMP_CXX_FOUND)
69- target_link_libraries (cpp_easygraph PRIVATE OpenMP::OpenMP_CXX )
70- target_compile_options (cpp_easygraph PRIVATE ${OpenMP_CXX_FLAGS} )
71- message (STATUS "OpenMP enabled for cpp_easygraph" )
39+ message (STATUS "Found Eigen3: ${Eigen3_INCLUDE_DIRS} " )
40+ add_compile_definitions (HAVE_EIGEN=1 )
41+ else ()
42+ message (STATUS "Eigen3 not found; eigen-accelerated code will be disabled" )
43+ add_compile_definitions (HAVE_EIGEN=0 )
7244endif ()
7345
74- # 链接ARPACK和LAPACK
75- target_link_libraries (cpp_easygraph PRIVATE ${ARPACK_LIB} LAPACK::LAPACK )
46+ # Link/include to cpp_easygraph only if the target exists.
47+ # This avoids errors when the target is created elsewhere or later.
48+ if (TARGET cpp_easygraph)
49+ if (Eigen3_FOUND)
50+ target_include_directories (cpp_easygraph PRIVATE ${Eigen3_INCLUDE_DIRS} )
51+ if (TARGET Eigen3::Eigen)
52+ target_link_libraries (cpp_easygraph PRIVATE Eigen3::Eigen )
53+ endif ()
54+ endif ()
55+
56+ if (OpenMP_CXX_FOUND)
57+ target_link_libraries (cpp_easygraph PRIVATE OpenMP::OpenMP_CXX )
58+ endif ()
59+
60+ if (ARPACK_LIB)
61+ target_link_libraries (cpp_easygraph PRIVATE ${ARPACK_LIB} LAPACK::LAPACK )
62+ else ()
63+ target_link_libraries (cpp_easygraph PRIVATE LAPACK::LAPACK )
64+ endif ()
65+ else ()
66+ message (STATUS "cpp_easygraph target not defined yet; optional libs will be linked after target creation." )
67+ endif ()
0 commit comments