Skip to content

Commit 907d04c

Browse files
authored
Merge pull request microsoft#595 from eli-schwartz/pkg-config
cmake: add pkg-config file
2 parents 4c24113 + eb97236 commit 907d04c

File tree

3 files changed

+48
-1
lines changed

3 files changed

+48
-1
lines changed

CMakeLists.txt

+14-1
Original file line numberDiff line numberDiff line change
@@ -248,18 +248,22 @@ endif()
248248
# extra needed libraries
249249
if(WIN32)
250250
list(APPEND mi_libraries psapi shell32 user32 advapi32 bcrypt)
251+
set(pc_libraries "-lpsapi -lshell32 -luser32 -ladvapi32 -lbcrypt")
251252
else()
252253
find_library(MI_LIBPTHREAD pthread)
253254
if (MI_LIBPTHREAD)
254255
list(APPEND mi_libraries ${MI_LIBPTHREAD})
256+
set(pc_libraries "-pthread")
255257
endif()
256258
find_library(MI_LIBRT rt)
257259
if(MI_LIBRT)
258260
list(APPEND mi_libraries ${MI_LIBRT})
259-
endif()
261+
set(pc_libraries "${pc_libraries} -lrt")
262+
endif()
260263
find_library(MI_LIBATOMIC atomic)
261264
if (MI_LIBATOMIC OR MI_USE_LIBATOMIC)
262265
list(APPEND mi_libraries atomic)
266+
set(pc_libraries "${pc_libraries} -latomic")
263267
endif()
264268
endif()
265269

@@ -409,6 +413,15 @@ if (MI_BUILD_OBJECT)
409413
RENAME ${mi_basename}${CMAKE_C_OUTPUT_EXTENSION} )
410414
endif()
411415

416+
# pkg-config file support
417+
include("cmake/JoinPaths.cmake")
418+
join_paths(includedir_for_pc_file "\${prefix}" "${CMAKE_INSTALL_INCLUDEDIR}")
419+
join_paths(libdir_for_pc_file "\${prefix}" "${CMAKE_INSTALL_LIBDIR}")
420+
421+
configure_file(mimalloc.pc.in mimalloc.pc @ONLY)
422+
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/mimalloc.pc"
423+
DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig/")
424+
412425
# -----------------------------------------------------------------------------
413426
# API surface testing
414427
# -----------------------------------------------------------------------------

cmake/JoinPaths.cmake

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# This module provides function for joining paths
2+
# known from most languages
3+
#
4+
# SPDX-License-Identifier: (MIT OR CC0-1.0)
5+
# Copyright 2020 Jan Tojnar
6+
# https://github.com/jtojnar/cmake-snips
7+
#
8+
# Modelled after Python’s os.path.join
9+
# https://docs.python.org/3.7/library/os.path.html#os.path.join
10+
# Windows not supported
11+
function(join_paths joined_path first_path_segment)
12+
set(temp_path "${first_path_segment}")
13+
foreach(current_segment IN LISTS ARGN)
14+
if(NOT ("${current_segment}" STREQUAL ""))
15+
if(IS_ABSOLUTE "${current_segment}")
16+
set(temp_path "${current_segment}")
17+
else()
18+
set(temp_path "${temp_path}/${current_segment}")
19+
endif()
20+
endif()
21+
endforeach()
22+
set(${joined_path} "${temp_path}" PARENT_SCOPE)
23+
endfunction()

mimalloc.pc.in

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
prefix=@CMAKE_INSTALL_PREFIX@
2+
libdir=@libdir_for_pc_file@
3+
includedir=@includedir_for_pc_file@
4+
5+
Name: @PROJECT_NAME@
6+
Description: a compact general purpose allocator with excellent performance
7+
Version: @PROJECT_VERSION@
8+
URL: https://github.com/microsoft/mimalloc/
9+
Libs: -L${libdir} -lmimalloc
10+
Libs.private: @pc_libraries@
11+
Cflags: -I${includedir}

0 commit comments

Comments
 (0)