Skip to contentSkip to conversation

dwarves: enable-SHARED-and-STATIC-lib-creation

PATCH Superseded Deepak Kumar Mishra 2 participants 7 messages Jun 2, 2021 – Jun 7, 2021

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover dwarves: enable-SHARED-and-STATIC-lib-creation

CMakeLists.txt does not allow creation of static library and link applications accordingly.

Creation of SHARED and STATIC should be allowed using -DBUILD_SHARED_LIBS

README file is also ammended to provide information regarding use of -DBUILD_SHARED_LIBS while using cmake

Deepak Kumar Mishra (2):
CMakeLists.txt: enable SHARED and STATIC lib creation
README: add documentation for -DBUILD_SHARED_LIBS

 CMakeLists.txt | 10 +++++-----
 README         | 13 +++++++++++--
 2 files changed, 16 insertions(+), 7 deletions(-)

--
2.17.1

#1 lore raw

PATCH 1/2 CMakeLists.txt: enable SHARED and STATIC lib creation

CMakeLists.txt does not allow creation of static library and link applications accordingly.

Creation of SHARED and STATIC should be allowed using -DBUILD_SHARED_LIBS

Ex:
cmake -D__LIB=lib -DBUILD_SHARED_LIBS=OFF ..
cmake -D__LIB=lib -DBUILD_SHARED_LIBS=ON ..

---
 CMakeLists.txt | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
CMakeLists.txt +5 -5
index 5aada20..bc9be63 100644
@@ -91,7 +91,7 @@ target_include_directories(bpf PRIVATE
 set(dwarves_LIB_SRCS dwarves.c dwarves_fprintf.c gobuffer.c strings.c
 		     ctf_encoder.c ctf_loader.c libctf.c btf_encoder.c btf_loader.c libbtf.c
 		     dwarf_loader.c dutil.c elf_symtab.c rbtree.c)
-add_library(dwarves SHARED ${dwarves_LIB_SRCS} $<TARGET_OBJECTS:bpf>)
+add_library(dwarves ${dwarves_LIB_SRCS} $<TARGET_OBJECTS:bpf>)
 set_target_properties(dwarves PROPERTIES VERSION 1.0.0 SOVERSION 1)
 set_target_properties(dwarves PROPERTIES INTERFACE_LINK_LIBRARIES "")
 target_include_directories(dwarves PRIVATE
@@ -99,12 +99,12 @@ target_include_directories(dwarves PRIVATE
 target_link_libraries(dwarves ${DWARF_LIBRARIES} ${ZLIB_LIBRARIES})
 
 set(dwarves_emit_LIB_SRCS dwarves_emit.c)
-add_library(dwarves_emit SHARED ${dwarves_emit_LIB_SRCS})
+add_library(dwarves_emit ${dwarves_emit_LIB_SRCS})
 set_target_properties(dwarves_emit PROPERTIES VERSION 1.0.0 SOVERSION 1)
 target_link_libraries(dwarves_emit dwarves)
 
 set(dwarves_reorganize_LIB_SRCS dwarves_reorganize.c)
-add_library(dwarves_reorganize SHARED ${dwarves_reorganize_LIB_SRCS})
+add_library(dwarves_reorganize ${dwarves_reorganize_LIB_SRCS})
 set_target_properties(dwarves_reorganize PROPERTIES VERSION 1.0.0 SOVERSION 1)
 target_link_libraries(dwarves_reorganize dwarves)
 
@@ -151,8 +151,8 @@ target_link_libraries(syscse dwarves)
 install(TARGETS codiff ctracer dtagnames pahole pdwtags
 		pfunct pglobal prefcnt scncopy syscse RUNTIME DESTINATION
 		${CMAKE_INSTALL_PREFIX}/bin)
-install(TARGETS dwarves LIBRARY DESTINATION ${LIB_INSTALL_DIR})
-install(TARGETS dwarves dwarves_emit dwarves_reorganize LIBRARY DESTINATION ${LIB_INSTALL_DIR})
+install(TARGETS dwarves LIBRARY DESTINATION ${LIB_INSTALL_DIR} ARCHIVE DESTINATION ${LIB_INSTALL_DIR})
+install(TARGETS dwarves dwarves_emit dwarves_reorganize LIBRARY DESTINATION ${LIB_INSTALL_DIR} ARCHIVE DESTINATION ${LIB_INSTALL_DIR})
 install(FILES dwarves.h dwarves_emit.h dwarves_reorganize.h
 	      dutil.h gobuffer.h list.h rbtree.h pahole_strings.h
 	      btf_encoder.h config.h ctf_encoder.h ctf.h
Signature · 1 line
2.17.1
#2 lore raw

PATCH 2/2 README: add documentation for -DBUILD_SHARED_LIBS

In reply to Deepak Kumar Mishra

added a section in README to give details about use of -DBUILD_SHARED_LIBS cmake option and existing documentation reformatted to accomodate this.

---
 README | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
README +11 -2
index 576cd42..40ca984 100644
@@ -6,8 +6,17 @@ Build instructions:
 4. cmake -D__LIB=lib ..
 5. make install
 
-Default is to install to /usr/local, use -DCMAKE_INSTALL_PREFIX=
-when invoking cmake to specify another install location.
+cmake Options:
+  -DBUILD_SHARED_LIBS
+    By default STATIC libraries are created and applications are linked to it.
+    use -DBUILD_SHARED_LIBS=ON while invoking cmake to create SHARED libraries
+    and link applications to it.
+
+    Ex. cmake -D__LIB=lib -DBUILD_SHARED_LIBS=ON ..
+
+  -DCMAKE_INSTALL_PREFIX
+    Default is to install to /usr/local, use -DCMAKE_INSTALL_PREFIX=
+    when invoking cmake to specify another install location.
 
 Known to work scenarios:
 
Signature · 1 line
2.17.1
#3 lore raw

Re: [PATCH 2/2] README: add documentation for -DBUILD_SHARED_LIBS

Em Wed, Jun 02, 2021 at 11:26:24AM +0530, Deepak Kumar Mishra escreveu:

Quoted 2 lines

added a section in README to give details about use of -DBUILD_SHARED_LIBS cmake option and existing documentation reformatted to accomodate this.

So are you changing the default to build as static? Please keep the existing default and make building statically the opt-in mode, ok?

- Arnaldo

Quoted 32 lines
---
 README | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
README +11 -2
index 576cd42..40ca984 100644
@@ -6,8 +6,17 @@ Build instructions:
 4. cmake -D__LIB=lib ..
 5. make install
 
-Default is to install to /usr/local, use -DCMAKE_INSTALL_PREFIX=
-when invoking cmake to specify another install location.
+cmake Options:
+  -DBUILD_SHARED_LIBS
+    By default STATIC libraries are created and applications are linked to it.
+    use -DBUILD_SHARED_LIBS=ON while invoking cmake to create SHARED libraries
+    and link applications to it.
+
+    Ex. cmake -D__LIB=lib -DBUILD_SHARED_LIBS=ON ..
+
+  -DCMAKE_INSTALL_PREFIX
+    Default is to install to /usr/local, use -DCMAKE_INSTALL_PREFIX=
+    when invoking cmake to specify another install location.
 
 Known to work scenarios:
 
Signature · 1 line
2.17.1
Signature · 1 line
- Arnaldo
#4 lore raw

Re: [PATCH 2/2] README: add documentation for -DBUILD_SHARED_LIBS

Hi Arnaldo,

Quoted 7 lines · Arnaldo Carvalho de Melo

Em Wed, Jun 02, 2021 at 11:26:24AM +0530, Deepak Kumar Mishra escreveu:

Quoted 2 lines

added a section in README to give details about use of -DBUILD_SHARED_LIBS cmake option and existing documentation reformatted to accomodate this.

So are you changing the default to build as static? Please keep the existing default and make building statically the opt-in mode, ok?

As per Cmake documentation if -DBUILD_SHARED_LIBS is present and true, cmake will cause all libraries to be built shared.
https://cmake.org/cmake/help/latest/variable/BUILD_SHARED_LIBS.html

If you still suggest, I can override the default behavior to SHARED and only when -DBUILD_SHARED_LIBS=OFF is provided, it will make STATIC.

Kindly confirm.
-Deepak

Quoted 35 lines

- Arnaldo

Quoted 32 lines
---
 README | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
README +11 -2
index 576cd42..40ca984 100644
@@ -6,8 +6,17 @@ Build instructions:
 4. cmake -D__LIB=lib ..
 5. make install
 
-Default is to install to /usr/local, use -DCMAKE_INSTALL_PREFIX=
-when invoking cmake to specify another install location.
+cmake Options:
+  -DBUILD_SHARED_LIBS
+    By default STATIC libraries are created and applications are linked to it.
+    use -DBUILD_SHARED_LIBS=ON while invoking cmake to create SHARED libraries
+    and link applications to it.
+
+    Ex. cmake -D__LIB=lib -DBUILD_SHARED_LIBS=ON ..
+
+  -DCMAKE_INSTALL_PREFIX
+    Default is to install to /usr/local, use -DCMAKE_INSTALL_PREFIX=
+    when invoking cmake to specify another install location.
 
 Known to work scenarios:
 
Signature · 1 line
2.17.1
#5 lore raw

Re: [PATCH 2/2] README: add documentation for -DBUILD_SHARED_LIBS

Em Thu, Jun 03, 2021 at 01:08:23PM +0530, Deepak Kumar Mishra escreveu:

Quoted 10 lines

Hi Arnaldo,

Quoted 7 lines · Arnaldo Carvalho de Melo

Em Wed, Jun 02, 2021 at 11:26:24AM +0530, Deepak Kumar Mishra escreveu:

Quoted 2 lines

added a section in README to give details about use of -DBUILD_SHARED_LIBS cmake option and existing documentation reformatted to accomodate this.

So are you changing the default to build as static? Please keep the existing default and make building statically the opt-in mode, ok?

Quoted 6 lines

As per Cmake documentation if -DBUILD_SHARED_LIBS is present and true, cmake will cause all libraries to be built shared.
https://cmake.org/cmake/help/latest/variable/BUILD_SHARED_LIBS.html

If you still suggest, I can override the default behavior to SHARED and only when -DBUILD_SHARED_LIBS=OFF is provided, it will make STATIC.

Please keep the pre-existing default, i.e. people building pahole all these years expect the shared library to be produced, if after this change that isn't the case, some confusion will ensue.

Now if you could provide numbers for, say, 'pahole -J' liked statically, that would be great and would help understand what decision to make.

- Arnaldo

Quoted 38 lines

Kindly confirm.
-Deepak

Quoted 35 lines

- Arnaldo

Quoted 32 lines
---
 README | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
README +11 -2
index 576cd42..40ca984 100644
@@ -6,8 +6,17 @@ Build instructions:
 4. cmake -D__LIB=lib ..
 5. make install
 
-Default is to install to /usr/local, use -DCMAKE_INSTALL_PREFIX=
-when invoking cmake to specify another install location.
+cmake Options:
+  -DBUILD_SHARED_LIBS
+    By default STATIC libraries are created and applications are linked to it.
+    use -DBUILD_SHARED_LIBS=ON while invoking cmake to create SHARED libraries
+    and link applications to it.
+
+    Ex. cmake -D__LIB=lib -DBUILD_SHARED_LIBS=ON ..
+
+  -DCMAKE_INSTALL_PREFIX
+    Default is to install to /usr/local, use -DCMAKE_INSTALL_PREFIX=
+    when invoking cmake to specify another install location.
 
 Known to work scenarios:
 
Signature · 1 line
2.17.1
Signature · 1 line
- Arnaldo
#6 lore raw

Re: [PATCH 2/2] README: add documentation for -DBUILD_SHARED_LIBS

Hi Arnaldo,

Quoted 15 lines · Arnaldo Carvalho de Melo

Em Thu, Jun 03, 2021 at 01:08:23PM +0530, Deepak Kumar Mishra escreveu:

Quoted 14 lines

Hi Arnaldo,

Quoted 7 lines · Arnaldo Carvalho de Melo

Em Wed, Jun 02, 2021 at 11:26:24AM +0530, Deepak Kumar Mishra escreveu:

Quoted 2 lines

added a section in README to give details about use of -DBUILD_SHARED_LIBS cmake option and existing documentation reformatted to accomodate this.

So are you changing the default to build as static? Please keep the existing default and make building statically the opt-in mode, ok?

As per Cmake documentation if -DBUILD_SHARED_LIBS is present and true, cmake will cause all libraries to be built shared.
https://cmake.org/cmake/help/latest/variable/BUILD_SHARED_LIBS.html

Quoted 6 lines
Quoted 2 lines

If you still suggest, I can override the default behavior to SHARED and only when -DBUILD_SHARED_LIBS=OFF is provided, it will make STATIC.

Please keep the pre-existing default, i.e. people building pahole all these years expect the shared library to be produced, if after this change that isn't the case, some confusion will ensue.

I got your point. I am sending a v2 of the patch set which will retain the previous behavior. (Shared library by default if no cmake options provided) -Deepak

Quoted 45 lines

Now if you could provide numbers for, say, 'pahole -J' liked statically, that would be great and would help understand what decision to make.

- Arnaldo

Quoted 38 lines

Kindly confirm.
-Deepak

Quoted 35 lines

- Arnaldo

Quoted 32 lines
---
 README | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
README +11 -2
index 576cd42..40ca984 100644
@@ -6,8 +6,17 @@ Build instructions:
 4. cmake -D__LIB=lib ..
 5. make install
 
-Default is to install to /usr/local, use -DCMAKE_INSTALL_PREFIX=
-when invoking cmake to specify another install location.
+cmake Options:
+  -DBUILD_SHARED_LIBS
+    By default STATIC libraries are created and applications are linked to it.
+    use -DBUILD_SHARED_LIBS=ON while invoking cmake to create SHARED libraries
+    and link applications to it.
+
+    Ex. cmake -D__LIB=lib -DBUILD_SHARED_LIBS=ON ..
+
+  -DCMAKE_INSTALL_PREFIX
+    Default is to install to /usr/local, use -DCMAKE_INSTALL_PREFIX=
+    when invoking cmake to specify another install location.
 
 Known to work scenarios:
 
Signature · 1 line
2.17.1