diff --git a/cmake/macros/macro_setup_problem.cmake b/cmake/macros/macro_setup_problem.cmake index c034a74..0f293df 100644 --- a/cmake/macros/macro_setup_problem.cmake +++ b/cmake/macros/macro_setup_problem.cmake @@ -22,4 +22,8 @@ macro(setup_problem namel) ${namel}.${buildl} PRIVATE kintera::kintera $,kintera::kintera_cu,>) + + if (UNIX AND NOT APPLE) + target_link_options(${namel}.${buildl} PRIVATE -Wl,--no-as-needed) + endif() endmacro() diff --git a/cmake/macros/macro_setup_test.cmake b/cmake/macros/macro_setup_test.cmake index 3f0faf6..e052bd9 100644 --- a/cmake/macros/macro_setup_test.cmake +++ b/cmake/macros/macro_setup_test.cmake @@ -19,9 +19,13 @@ macro(setup_test namel) target_link_libraries( ${namel}.${buildl} - PRIVATE kintera::kintera + PRIVATE kintera::kintera $,kintera::kintera_cu,> gtest_main) + if (UNIX AND NOT APPLE) + target_link_options(${namel}.${buildl} PRIVATE -Wl,--no-as-needed) + endif() + add_test(NAME ${namel}.${buildl} COMMAND ${namel}.${buildl}) endmacro() diff --git a/setup.py b/setup.py index 5a5b2f3..3051035 100644 --- a/setup.py +++ b/setup.py @@ -21,9 +21,15 @@ def parse_library_names(libdir): library_names.extend(['netcdf']) # move current library name to first - current = [item for item in library_names if item.startswith('kintera')] - other = [item for item in library_names if not item.startswith('kintera')] - return current + other + #current = [item for item in library_names if item.startswith('kintera')] + #other = [item for item in library_names if not item.startswith('kintera')] + # 1) non-cuda libs first (consumers) + kintera_non_cuda = [l for l in library_names if l.startswith("kintera") and "cuda" not in l] + # 2) cuda libs last (providers) + kintera_cuda = [l for l in library_names if l.startswith("kintera") and "cuda" in l] + # 3) everything else + other = [l for l in library_names if not l.startswith("kintera")] + return kintera_non_cuda + other + kintera_cuda site_dir = sysconfig.get_paths()["purelib"] @@ -56,33 +62,23 @@ def parse_library_names(libdir): ] else: extra_link_args = [ + "-Wl,--no-as-needed", "-Wl,-rpath,$ORIGIN/lib", "-Wl,-rpath,$ORIGIN/../torch/lib", "-Wl,-rpath,$ORIGIN/../pydisort/lib", "-Wl,-rpath,$ORIGIN/../pyharp/lib", + "-Wl,--as-needed", ] -if torch.cuda.is_available(): - ext_module = cpp_extension.CUDAExtension( - name='kintera.kintera', - sources=glob.glob('python/csrc/*.cpp'), - include_dirs=include_dirs, - library_dirs=lib_dirs, - libraries=libraries, - extra_compile_args={'nvcc': ['--extended-lambda'], - 'cc': ["-Wno-attributes"]}, - extra_link_args=extra_link_args, +ext_module = cpp_extension.CppExtension( + name='kintera.kintera', + sources=glob.glob('python/csrc/*.cpp'), + include_dirs=include_dirs, + library_dirs=lib_dirs, + libraries=libraries, + extra_compile_args=['-Wno-attributes'], + extra_link_args=extra_link_args, ) -else: - ext_module = cpp_extension.CppExtension( - name='kintera.kintera', - sources=glob.glob('python/csrc/*.cpp'), - include_dirs=include_dirs, - library_dirs=lib_dirs, - libraries=libraries, - extra_compile_args=['-Wno-attributes'], - extra_link_args=extra_link_args, - ) setup( package_dir={"kintera": "python"},