11cmake_minimum_required (VERSION 3.10 )
22set (PSTACK_SOVERSION 2.17)
3- set (PSTACK_VERSION 2.17.3 )
3+ set (PSTACK_VERSION 2.17.4 )
44project (pstack LANGUAGES C CXX VERSION "${PSTACK_VERSION} " )
55
66include (GNUInstallDirs )
@@ -18,12 +18,10 @@ set(PSTACK_BIN "pstack" CACHE STRING "Name of the 'pstack' binary")
1818set (CMAKE_POSITION_INDEPENDENT_CODE ON )
1919
2020set (CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX} /${CMAKE_INSTALL_LIBDIR} /" CACHE STRING "Rpath to install for binaries or the empty string" )
21- set (LIBTYPE "SHARED" CACHE STRING "Build libraries as STATIC or SHARED" )
2221option (TIDY "Run clang-tidy on the source" False )
2322
24- find_library (LTHREADDB NAMES thread_db PATHS (/usr/lib /usr/local/lib ))
25- find_package (LibLZMA )
26- find_package (ZLIB )
23+ find_package (LibLZMA REQUIRED )
24+ find_package (ZLIB REQUIRED )
2725
2826if (PYTHON2)
2927 find_package (Python2 COMPONENTS Development )
@@ -60,18 +58,10 @@ add_definitions("-fno-omit-frame-pointer")
6058set (CMAKE_EXPORT_COMPILE_COMMANDS ON )
6159# Make sure to use the local libpstack headers rather than what's installed.
6260include_directories (${CMAKE_SOURCE_DIR} )
61+ include_directories (${ZLIB_INCLUDE_DIRS} )
6362
64- if (LIBLZMA_FOUND)
65- set (lzmasrc lzma.cc)
66- add_definitions ("-DWITH_LZMA" )
67- include_directories (${LIBLZMA_INCLUDES} )
68- endif ()
63+ include_directories (${LIBLZMA_INCLUDE_DIRS} )
6964
70- if (ZLIB_FOUND)
71- set (inflatesrc inflate.cc)
72- add_definitions ("-DWITH_ZLIB" )
73- include_directories (${ZLIB_INCLUDES} )
74- endif ()
7565
7666if (Python3_Development_FOUND OR Python2_Development_FOUND)
7767 set (pysrc python.cc)
@@ -95,7 +85,7 @@ endif()
9585
9686add_definitions ("-g3" )
9787
98- add_library (dwelf ${LIBTYPE}
88+ add_library (dwelf_objects OBJECT
9989 dwarf_die.cc
10090 dwarf_frame.cc
10191 dwarf_info.cc
@@ -109,35 +99,43 @@ add_library(dwelf ${LIBTYPE}
10999 elf.cc
110100 flags .cc
111101 reader.cc
112- ${inflatesrc}
113- ${lzmasrc}
102+ inflate.cc
103+ lzma.cc
114104 )
115105
116- add_library (procman ${LIBTYPE} dead.cc self.cc live.cc process.cc proc_service.cc
117- dwarfproc.cc procdump.cc ${stubsrc} ${pysrc} )
106+ add_library (procman_objects OBJECT dead.cc self.cc live.cc process.cc proc_service.cc
107+ dwarfproc.cc procdump.cc threaddb.cc ${pysrc} )
108+
109+ add_library (dwelf SHARED $<TARGET_OBJECTS :dwelf_objects >)
110+ add_library (dwelf_static STATIC $<TARGET_OBJECTS :dwelf_objects >)
111+ set_target_properties (dwelf_static PROPERTIES OUTPUT_NAME dwelf_s )
112+
113+ add_library (procman SHARED $<TARGET_OBJECTS :procman_objects >)
114+ add_library (procman_static STATIC $<TARGET_OBJECTS :procman_objects >)
115+ set_target_properties (procman_static PROPERTIES OUTPUT_NAME procman_s )
116+
117+ option (LINK_STATIC "Link binaries against static libraries" OFF )
118+ if (LINK_STATIC)
119+ set (PSTACK_LINK_LIBS procman_static dwelf_static)
120+ else ()
121+ set (PSTACK_LINK_LIBS dwelf procman)
122+ endif ()
118123
119124add_executable (canal canal.cc )
120125
121126add_executable (${PSTACK_BIN} pstack.cc )
122127
123- target_link_libraries (procman ${LTHREADDB} dwelf dl )
124- target_link_libraries (${PSTACK_BIN} dwelf procman )
125- target_link_libraries (canal dwelf procman )
128+ target_link_libraries (procman dwelf dl )
129+ target_link_libraries (procman_static dwelf_static dl )
130+ target_link_libraries (${PSTACK_BIN} ${PSTACK_LINK_LIBS} )
131+ target_link_libraries (canal ${PSTACK_LINK_LIBS} )
132+ target_link_options (${PSTACK_BIN} PRIVATE -Wl,--export-dynamic )
133+ target_link_options (canal PRIVATE -Wl,--export-dynamic )
126134
127- set_target_properties (dwelf PROPERTIES VERSION ${PROJECT_VERSION} SOVERSION "${PSTACK_SOVERSION} " )
128- set_target_properties (procman PROPERTIES VERSION ${PROJECT_VERSION} SOVERSION "${PSTACK_SOVERSION} " )
135+ set_target_properties (dwelf PROPERTIES VERSION ${PROJECT_VERSION} SOVERSION "${PSTACK_SOVERSION} " )
136+ set_target_properties (procman PROPERTIES VERSION ${PROJECT_VERSION} SOVERSION "${PSTACK_SOVERSION} " )
129137
130- if (ZLIB_FOUND)
131- target_link_libraries (dwelf ${ZLIB_LIBRARIES} )
132- else ()
133- message (WARNING "no ZLIB support found" )
134- endif ()
135138
136- if (LIBLZMA_FOUND)
137- target_link_libraries (dwelf ${LIBLZMA_LIBRARIES} )
138- else ()
139- message (WARNING "no LZMA support found" )
140- endif ()
141139
142140if ((NOT (Python3_Development_FOUND)) AND PYTHON3)
143141 message (WARNING "no python3 support found" )
@@ -151,13 +149,13 @@ endif()
151149add_library (hdbg SHARED heap.c )
152150add_executable (hdmp hdmp.cc )
153151add_executable (stackusers stackusers.cc )
154- target_link_libraries (hdmp dwelf procman )
152+ target_link_libraries (hdmp ${PSTACK_LINK_LIBS} )
155153target_link_libraries (hdbg dl )
156- target_link_libraries (stackusers dwelf procman )
154+ target_link_libraries (stackusers ${PSTACK_LINK_LIBS} )
157155
158156install (TARGETS ${PSTACK_BIN} canal)
159157install (TARGETS hdmp)
160- install (TARGETS dwelf procman hdbg)
158+ install (TARGETS dwelf procman dwelf_static procman_static hdbg)
161159install (FILES ${CMAKE_SOURCE_DIR} /pstack.1 DESTINATION share/man/man1 RENAME ${PSTACK_BIN} .1 )
162160install (DIRECTORY libpstack DESTINATION include)
163161install (CODE "execute_process (COMMAND setcap cap_sys_ptrace+ep ${DESTDIR}${CMAKE_INSTALL_PREFIX} /bin/${PSTACK_BIN} RESULT_VARIABLE ret)
0 commit comments