Skip to content
90 changes: 63 additions & 27 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@ cmake_minimum_required(VERSION 3.12)
project(libdwarf VERSION 2.3.3
DESCRIPTION "Library to access DWARF debugging information"
HOMEPAGE_URL "https://github.com/davea42/libdwarf-code.git"
LANGUAGES C CXX)
LANGUAGES C)

# libdwarf
option(BUILD_NON_SHARED "build archive library libdwarf[p].a" TRUE)
option(BUILD_SHARED "build shared library libdwarf[p].so and use it" FALSE)
option(BUILD_MMAP "build library allowing mmap" TRUE)

option(ENABLE_DECOMPRESSION
Expand All @@ -16,12 +14,20 @@ option(ENABLE_DECOMPRESSION

# This adds compiler option -Wall (gcc compiler warnings)
option(WALL "Add -Wall" FALSE)
option(LIBDWARF_STATIC "add -DLIBDWARF_STATIC" FALSE)

option(INSTALL_STATIC_LIBRARIES "Install the static libraries" FALSE)
option(BUILD_DWARFDUMP "Build dwarfdump (default is YES)" TRUE)

option(BUILD_DWARFGEN "Build dwarfgen (default is NO)" FALSE)
message(STATUS "Building dwarfgen ... ${BUILD_DWARFGEN}")
if(BUILD_DWARFGEN)
include(CheckLanguage)
check_language(CXX)
if(CMAKE_CXX_COMPILER)
enable_language(CXX)
else()
message(STATUS "No C++ compiler available; disabling dwarfgen")
set(BUILD_DWARFGEN OFF CACHE BOOL "Build dwarfgen" FORCE)
endif()
message(STATUS "Building dwarfgen ... ${BUILD_DWARFGEN}")
endif()

option(BUILD_DWARFEXAMPLE "Build dwarfexample (default is NO)" FALSE)
message(STATUS "Building dwarfexample... ${BUILD_DWARFEXAMPLE}")
Expand All @@ -33,7 +39,6 @@ message(STATUS "Building api tests ... ${DOTESTS}")
option(PIC_ALWAYS "Build libdwarf with position-independent code for both static and shared (default is NO)" FALSE)

list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
include_directories( ${PROJECT_BINARY_DIR} )

# used to compile on MSVC upto 2013 where snprintf is not available
macro(msvc_posix target)
Expand Down Expand Up @@ -258,30 +263,61 @@ endif ()

message(STATUS "CMAKE_SIZEOF_VOID_P ... : ${CMAKE_SIZEOF_VOID_P}")

# DW_FWALLXX are gnu C++ options.
if (WALL)
set(DW_FWALLXX -Wall -Wextra -Wno-unused-private-field -Wpointer-arith -Wmissing-declarations -Wcomment -Wformat -Wpedantic -Wuninitialized -Wshadow -Wno-long-long -Werror)
set(DW_FWALL ${DW_FWALLXX} -Wpointer-arith -Wmissing-declarations -Wmissing-prototypes -Wdeclaration-after-statement -Wextra -Wcomment -Wformat -Wpedantic -Wuninitialized -Wno-long-long -Wshadow -Werror )
message(STATUS "Compiler warning options... YES ${DW_FWALL}")
if(WALL)
message(STATUS "Compiler warning options... YES")
else()
unset(DW_FWALL )
message(STATUS "Compiler warning options... NO")
endif()
#if (LIBDWARF_STATIC)
# set(DW_LIBDWARF_STATIC -DLIBDWARF_STATIC)
#else()
# unset(DW_LIBDWARF_STATIC)
#endif()

configure_file(cmake/config.h.in config.h)
function(dwarf_common_options TARGET)
get_target_property(TARGET_TYPE ${TARGET} TYPE)
if(TARGET_TYPE STREQUAL "INTERFACE_LIBRARY")
set(VISIBILITY INTERFACE)
else()
set(VISIBILITY PRIVATE)
endif()

if(BUILD_NON_SHARED)
set(DW_LIBDWARF_STATIC -DLIBDWARF_STATIC)
set(BUILD_SHARED_LIBS NO)
else()
unset(DW_LIBDWARF_STATIC)
set(BUILD_SHARED_LIBS YES)
endif()
msvc_posix(${TARGET})

target_compile_definitions(${TARGET} ${VISIBILITY} $<$<PLATFORM_ID:Linux>:_GNU_SOURCE>)

target_compile_options(${TARGET} ${VISIBILITY}

$<$<AND:$<BOOL:${WALL}>,$<COMPILE_LANGUAGE:CXX>,$<CXX_COMPILER_ID:GNU,Clang,AppleClang>>:
-Wall
-Wextra
-Wno-unused-private-field
-Wpointer-arith
-Wmissing-declarations
-Wcomment
-Wformat
-Wpedantic
-Wuninitialized
-Wshadow
-Wno-long-long
-Werror
>

$<$<AND:$<BOOL:${WALL}>,$<COMPILE_LANGUAGE:C>,$<C_COMPILER_ID:GNU,Clang,AppleClang>>:
-Wall
-Wextra
-Wpointer-arith
-Wmissing-declarations
-Wcomment
-Wformat
-Wpedantic
-Wuninitialized
-Wshadow
-Wno-long-long
-Werror
-Wmissing-prototypes
-Wdeclaration-after-statement
>
)
endfunction()


configure_file(cmake/config.h.in config.h)

include(GNUInstallDirs)

Expand Down
166 changes: 99 additions & 67 deletions src/bin/dwarfdump/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,77 +1,109 @@

set_source_group(SOURCES "Source Files" dd_addrmap.c
dd_all_srcfiles.c
dd_checkutil.c dd_common.c dd_regex.c dd_safe_strcpy.c
dwarfdump.c dd_dwconf.c dd_helpertree.c
dd_glflags.c dd_command_options.c dd_compiler_info.c
dd_macrocheck.c
dd_opscounttab.c
print_abbrevs.c print_aranges.c
dd_attr_form.c
dd_canonical_append.c
dd_check_attr_encoding.c
dd_lvn_table.c
print_debugfission.c print_die.c
dd_trace_abstract_origin_etc.c
print_debug_addr.c
print_debug_gnu.c
print_debug_names.c print_debug_sup.c
print_frames.c print_gdbindex.c
print_hipc_lopc_attr.c
print_lines.c
print_llex_codes.c print_origloclist_codes.c
print_loclists_codes.c
print_loclists.c
print_macro.c print_macinfo.c
print_pubnames.c print_ranges.c
print_rnglists.c
print_str_offsets.c
print_sections.c print_section_groups.c
print_strings.c
print_tag_attributes_usage.c
dd_sanitized.c dd_strstrnocase.c
dd_true_section_name.c dd_uri.c dd_utf8.c
dd_getopt.c dd_makename.c
dd_naming.c dd_esb.c dd_tsearchbal.c)
set_source_group(SOURCES "Source Files"
dd_addrmap.c
dd_all_srcfiles.c
dd_checkutil.c
dd_common.c
dd_regex.c
dd_safe_strcpy.c
dwarfdump.c
dd_dwconf.c
dd_helpertree.c
dd_glflags.c
dd_command_options.c
dd_compiler_info.c
dd_macrocheck.c
dd_opscounttab.c
print_abbrevs.c
print_aranges.c
dd_attr_form.c
dd_canonical_append.c
dd_check_attr_encoding.c
dd_lvn_table.c
print_debugfission.c
print_die.c
dd_trace_abstract_origin_etc.c
print_debug_addr.c
print_debug_gnu.c
print_debug_names.c
print_debug_sup.c
print_frames.c
print_gdbindex.c
print_hipc_lopc_attr.c
print_lines.c
print_llex_codes.c
print_origloclist_codes.c
print_loclists_codes.c
print_loclists.c
print_macro.c
print_macinfo.c
print_pubnames.c
print_ranges.c
print_rnglists.c
print_str_offsets.c
print_sections.c
print_section_groups.c
print_strings.c
print_tag_attributes_usage.c
dd_sanitized.c
dd_strstrnocase.c
dd_true_section_name.c
dd_uri.c
dd_utf8.c
dd_getopt.c
dd_makename.c
dd_naming.c
dd_esb.c
dd_tsearchbal.c)

set_source_group(HEADERS "Header Files"
dd_addrmap.h dd_all_srcfiles.h
dd_attr_form.h dd_checkutil.h dd_common.h dd_regex.h
dd_safe_strcpy.h dd_dwconf.h
dd_minimal.h
dd_command_options.h dd_compiler_info.h
dd_opscounttab.h
print_debug_gnu.h
dd_dwconf_using_functions.h dd_esb_using_functions.h
dd_elf_cputype.h
dd_pe_cputype.h
dd_helpertree.h
dd_canonical_append.h
dwarfdump-af-table-ext.h dwarfdump-af-table-std.h
dwarfdump-ta-ext-table.h dwarfdump-ta-table.h
dwarfdump-tt-ext-table.h dwarfdump-tt-table.h
dd_getopt.h dd_esb.h dd_glflags.h dd_globals.h
dd_mac_cputype.h
dd_macrocheck.h dd_defined_types.h
dd_sanitized.h
dd_naming.h dd_makename.h dd_tsearchbal.h print_frames.h
dd_uri.h dd_utf8.h
../../lib/libdwarf/libdwarf_private.h)

set_source_group(CONFIGURATION_FILES "Configuration Files"
${PROJECT_SOURCE_DIR}/cmake/config.h.in
${PROJECT_BINARY_DIR}/config.h)
dd_addrmap.h
dd_all_srcfiles.h
dd_attr_form.h
dd_checkutil.h
dd_common.h
dd_regex.h
dd_safe_strcpy.h
dd_dwconf.h
dd_minimal.h
dd_command_options.h
dd_compiler_info.h
dd_opscounttab.h
print_debug_gnu.h
dd_dwconf_using_functions.h
dd_esb_using_functions.h
dd_elf_cputype.h
dd_pe_cputype.h
dd_helpertree.h
dd_canonical_append.h
dwarfdump-af-table-ext.h
dwarfdump-af-table-std.h
dwarfdump-ta-ext-table.h
dwarfdump-ta-table.h
dwarfdump-tt-ext-table.h
dwarfdump-tt-table.h
dd_getopt.h
dd_esb.h
dd_glflags.h
dd_globals.h
dd_mac_cputype.h
dd_macrocheck.h
dd_defined_types.h
dd_sanitized.h
dd_naming.h
dd_makename.h
dd_tsearchbal.h
print_frames.h
dd_uri.h dd_utf8.h
)

add_executable(dwarfdump ${SOURCES} ${HEADERS} ${CONFIGURATION_FILES})

add_executable(dwarfdump ${SOURCES} ${HEADERS})
dwarf_common_options(dwarfdump)
set_folder(dwarfdump src/bin/dwarfdump)

target_compile_definitions(dwarfdump PRIVATE
"CONFPREFIX=${CMAKE_INSTALL_PREFIX}/lib" ${DW_LIBDWARF_STATIC}
_GNU_SOURCE)
target_compile_options(dwarfdump PRIVATE ${DW_FWALL})
target_compile_definitions(dwarfdump PRIVATE "CONFPREFIX=${CMAKE_INSTALL_PREFIX}/lib")

target_link_libraries(dwarfdump PRIVATE dwarf)
target_link_libraries(dwarfdump PRIVATE dwarf-static)

install(TARGETS dwarfdump DESTINATION
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
Expand Down
6 changes: 3 additions & 3 deletions src/bin/dwarfexample/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@

add_library(dwarf_example INTERFACE)
target_compile_definitions(dwarf_example INTERFACE CONFPREFIX={CMAKE_INSTALL_PREFIX}/lib ${DW_LIBDWARF_STATIC} _GNU_SOURCE)
target_compile_options(dwarf_example INTERFACE ${DW_FWALL})
target_link_libraries(dwarf_example INTERFACE dwarf)
dwarf_common_options(dwarf_example)
target_compile_definitions(dwarf_example INTERFACE CONFPREFIX={CMAKE_INSTALL_PREFIX}/lib)
target_link_libraries(dwarf_example INTERFACE dwarf-shared)

add_executable(simplereader simplereader.c)
set_folder(simplereader src/bin/dwarfexample)
Expand Down
55 changes: 27 additions & 28 deletions src/bin/dwarfgen/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,34 +1,33 @@
set_source_group(SOURCES "Source Files" createirepformfrombinary.cc
createirepfrombinary.cc
dwarfgen.cc irepattrtodbg.cc ireptodbg.cc
dg_getopt.cc)

set_source_group(HEADERS "Header Files" createirepfrombinary.h
general.h irepattrtodbg.h
irepdie.h irepform.h irepframe.h
irepline.h irepmacro.h ireppubnames.h
irepresentation.h ireptodbg.h strtabdata.h
../../lib/libdwarf/libdwarf_private.h
dg_getopt.h
../../lib/libdwarf/dwarf.h
../../lib/libdwarfp/libdwarfp.h)

set_source_group(CONFIGURATION_FILES "Configuration Files"
${PROJECT_SOURCE_DIR}/cmake/config.h.in
${PROJECT_BINARY_DIR}/config.h)

add_executable(dwarfgen ${SOURCES} ${HEADERS} ${CONFIGURATION_FILES})
set_source_group(SOURCES "Source Files"
createirepformfrombinary.cc
createirepfrombinary.cc
dwarfgen.cc
irepattrtodbg.cc
ireptodbg.cc
dg_getopt.cc)

set_source_group(HEADERS "Header Files"
createirepfrombinary.h
general.h
irepattrtodbg.h
irepdie.h
irepform.h
irepframe.h
irepline.h
irepmacro.h
ireppubnames.h
irepresentation.h
ireptodbg.h
strtabdata.h
dg_getopt.h
)

add_executable(dwarfgen ${SOURCES} ${HEADERS})

set_folder(dwarfgen src/bin/dwarfgen)
dwarf_common_options(dwarfgen)

target_compile_options(dwarfgen PRIVATE ${DW_FWALLXX})
target_compile_definitions(dwarfgen PRIVATE ${DW_LIBDWARF_STATIC})
message("Current cmake src dir ${CMAKE_CURRENT_SOURCE_DIR}")
target_include_directories(dwarfgen PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/../../lib/libdwarf
${CMAKE_CURRENT_SOURCE_DIR}/../../lib/libdwarfp)

target_link_libraries(dwarfgen PRIVATE dwarfp dwarf)
target_link_libraries(dwarfgen PRIVATE dwarfp-static dwarf-static)

install(TARGETS dwarfgen DESTINATION
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
Expand Down
Loading