Skip to content

Commit e64c4c0

Browse files
committed
Fix linking
Some libraries that were dependencies of UMF were not link to UMF but rather directly to tests and benchmark. Fix this by extending add_umf_library and passing required libs there.
1 parent 6c79b70 commit e64c4c0

File tree

5 files changed

+46
-26
lines changed

5 files changed

+46
-26
lines changed

benchmark/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ add_dependencies(ubench unified_memory_framework)
1111
target_include_directories(ubench PRIVATE ${UMF_CMAKE_SOURCE_DIR}/include/)
1212
target_link_libraries(ubench
1313
unified_memory_framework
14-
numa
15-
pthread)
14+
pthread
15+
m)

cmake/helpers.cmake

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -72,18 +72,35 @@ function(add_umf_target_exec_options name)
7272
endif()
7373
endfunction()
7474

75-
function(add_umf_executable name)
76-
add_executable(${name} ${ARGN})
77-
add_umf_target_compile_options(${name})
78-
add_umf_target_exec_options(${name})
79-
add_umf_target_link_options(${name})
75+
function(add_umf_executable)
76+
# NAME - a name of the executable
77+
# SRCS - source files
78+
# LIBS - libraries to be linked with
79+
set(oneValueArgs NAME)
80+
set(multiValueArgs SRCS LIBS)
81+
cmake_parse_arguments(ARG "" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
82+
83+
add_executable(${ARG_NAME} ${ARG_SRCS})
84+
target_link_libraries(${ARG_NAME} PRIVATE ${ARG_LIBS})
85+
add_umf_target_compile_options(${ARG_NAME})
86+
add_umf_target_exec_options(${ARG_NAME})
87+
add_umf_target_link_options(${ARG_NAME})
8088
endfunction()
8189

82-
function(add_umf_library name)
83-
add_library(${name} ${ARGN})
84-
target_include_directories(${name} PRIVATE
90+
function(add_umf_library)
91+
# NAME - a name of the executable
92+
# TYPE - type of the library (shared or static)
93+
# SRCS - source files
94+
# LIBS - libraries to be linked with
95+
set(oneValueArgs NAME TYPE)
96+
set(multiValueArgs SRCS LIBS)
97+
cmake_parse_arguments(ARG "" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
98+
99+
add_library(${ARG_NAME} ${ARG_TYPE} ${ARG_SRCS})
100+
target_link_libraries(${ARG_NAME} PRIVATE ${ARG_LIBS})
101+
target_include_directories(${ARG_NAME} PRIVATE
85102
${UMF_CMAKE_SOURCE_DIR}/include
86103
${UMF_CMAKE_SOURCE_DIR}/src/common)
87-
add_umf_target_compile_options(${name})
88-
add_umf_target_link_options(${name})
104+
add_umf_target_compile_options(${ARG_NAME})
105+
add_umf_target_link_options(${ARG_NAME})
89106
endfunction()

src/CMakeLists.txt

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ set(UMF_SOURCES_MACOSX
3131
utils/utils_posix_math.c
3232
)
3333

34+
if(LINUX)
35+
set(UMF_LIBS numa)
36+
else()
37+
set(UMF_LIBS)
38+
endif()
39+
3440
if(LINUX)
3541
set(UMF_SOURCES ${UMF_SOURCES} ${UMF_SOURCES_LINUX})
3642
elseif(WINDOWS)
@@ -40,10 +46,10 @@ elseif(MACOSX)
4046
endif()
4147

4248
if(UMF_BUILD_SHARED_LIBRARY)
43-
add_umf_library(unified_memory_framework SHARED ${UMF_SOURCES})
49+
add_umf_library(NAME unified_memory_framework TYPE SHARED SRCS ${UMF_SOURCES} LIBS ${UMF_LIBS})
4450
target_compile_definitions(unified_memory_framework PUBLIC UMF_SHARED_LIBRARY)
4551
else()
46-
add_umf_library(unified_memory_framework STATIC ${UMF_SOURCES})
52+
add_umf_library(NAME unified_memory_framework TYPE STATIC SRCS ${UMF_SOURCES} LIBS ${UMF_LIBS})
4753
endif()
4854

4955
if (UMF_ENABLE_POOL_TRACKING)
@@ -64,7 +70,7 @@ target_include_directories(unified_memory_framework PUBLIC
6470
# libumf_pool_jemalloc
6571
if(UMF_BUILD_LIBUMF_POOL_JEMALLOC)
6672
if(LINUX)
67-
add_umf_library(pool_jemalloc STATIC pool/pool_jemalloc.c)
73+
add_umf_library(NAME pool_jemalloc TYPE STATIC SRCS pool/pool_jemalloc.c LIBS jemalloc)
6874
else()
6975
message(FATAL_ERROR "libumf_pool_jemalloc is supported on Linux only")
7076
endif()

test/CMakeLists.txt

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,14 @@ function(add_umf_test)
2929
set(TEST_NAME umf-${ARG_NAME})
3030
set(TEST_TARGET_NAME umf_test-${ARG_NAME})
3131

32-
add_umf_executable(${TEST_TARGET_NAME} ${ARG_SRCS})
33-
34-
target_link_libraries(${TEST_TARGET_NAME} PRIVATE
35-
test_common
32+
set(TEST_LIBS test_common
3633
${PROJECT_NAME}::unified_memory_framework
3734
GTest::gtest_main
3835
${ARG_LIBS})
36+
if(UMF_BUILD_LIBUMF_POOL_JEMALLOC)
37+
set(TEST_LIBS ${TEST_LIBS} pool_jemalloc)
38+
endif()
39+
add_umf_executable(NAME ${TEST_TARGET_NAME} SRCS ${ARG_SRCS} LIBS ${TEST_LIBS})
3940

4041
target_include_directories(${TEST_TARGET_NAME} PRIVATE
4142
${UMF_TEST_DIR}/common
@@ -58,17 +59,13 @@ endfunction()
5859

5960
add_subdirectory(common)
6061

61-
if (UMF_BUILD_LIBUMF_POOL_JEMALLOC)
62-
set(LIBS_JEMALLOC pool_jemalloc jemalloc numa)
63-
endif()
64-
6562
add_umf_test(NAME base SRCS base.cpp)
66-
add_umf_test(NAME memoryPool SRCS memoryPoolAPI.cpp malloc_compliance_tests.cpp LIBS ${LIBS_JEMALLOC})
63+
add_umf_test(NAME memoryPool SRCS memoryPoolAPI.cpp malloc_compliance_tests.cpp)
6764
add_umf_test(NAME memoryProvider SRCS memoryProviderAPI.cpp)
6865
add_umf_test(NAME disjointPool SRCS disjoint_pool.cpp malloc_compliance_tests.cpp)
6966
add_umf_test(NAME c_api_disjoint_pool SRCS c_api/disjoint_pool.c)
7067
add_umf_test(NAME memory_pool_internal SRCS memory_pool_internal.cpp)
7168

7269
if(LINUX) # OS-specific functions are implemented only for Linux now
73-
add_umf_test(NAME provider_os_memory SRCS provider_os_memory.cpp LIBS numa)
70+
add_umf_test(NAME provider_os_memory SRCS provider_os_memory.cpp)
7471
endif()

test/common/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ set(COMMON_SOURCES
1010
provider_trace.c
1111
)
1212

13-
add_umf_library(test_common STATIC ${COMMON_SOURCES})
13+
add_umf_library(NAME test_common TYPE STATIC SRCS ${COMMON_SOURCES})
1414

1515
target_include_directories(test_common PRIVATE ${UMF_CMAKE_SOURCE_DIR}/include)

0 commit comments

Comments
 (0)