Skip to content

Commit

Permalink
Merge pull request #244 from jamiesnape/various-cmake-pack-fixes
Browse files Browse the repository at this point in the history
Various CMake and CPack fixes/improvements.
  • Loading branch information
SimonKagstrom authored Apr 30, 2018
2 parents de72c77 + 4cf3fa9 commit 2e56d54
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 36 deletions.
25 changes: 19 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,31 @@ cmake_minimum_required (VERSION 2.6)
# ====================================
project (kcov)

if(NOT CMAKE_BUILD_TYPE)
set (CMAKE_BUILD_TYPE Release)
endif(NOT CMAKE_BUILD_TYPE)
set (PROJECT_VERSION_MAJOR 35)
set (PROJECT_VERSION_MINOR 0)
set (PROJECT_VERSION_PATCH 0)
set (PROJECT_VERSION
"${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}")

if(POLICY CMP0042)
# MACOSX_RPATH is enabled by default.
cmake_policy (SET CMP0042 NEW)
endif()

if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
set (CMAKE_BUILD_TYPE Release CACHE STRING
"Choose the type of build, options are None Debug Release RelWithDebInfo MinSizeRel"
FORCE)
set_property (CACHE CMAKE_BUILD_TYPE PROPERTY
STRINGS None Debug Release RelWithDebInfo MinSizeRel)
endif (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)

add_definitions(-DPACKAGE)
add_definitions(-DPACKAGE_VERSION)
# ====================================
# configuring
# ====================================
set (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH}
${CMAKE_CURRENT_SOURCE_DIR}/cmake)
find_package (PkgConfig REQUIRED)
list (APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")

set (SPECIFY_RPATH OFF CACHE BOOL "Specify RPATH for installed executables")

Expand Down
4 changes: 4 additions & 0 deletions CPack.local.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,8 @@ set (CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION
/usr/share/man /usr/share/man/man1
/usr/local/share/man /usr/local/share/man/man1)

set (CPACK_DEBIAN_FILE_NAME DEB-DEFAULT)
set (CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON)
set (CPACK_DEBIAN_PACKAGE_HOMEPAGE https://simonkagstrom.github.io/kcov/)

include (CPack)
13 changes: 13 additions & 0 deletions cmake/FindElfutils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,18 @@ if (LIBDWARF_LIBRARIES AND LIBDWARF_INCLUDE_DIRS)
set (LibDwarf_FIND_QUIETLY TRUE)
endif (LIBDWARF_LIBRARIES AND LIBDWARF_INCLUDE_DIRS)

find_package(PkgConfig QUIET)

if(PKG_CONFIG_FOUND)
set(PKG_CONFIG_USE_CMAKE_PREFIX_PATH ON)
pkg_check_modules(PC_LIBDW QUIET libdw)
endif()

find_path (DWARF_INCLUDE_DIR
NAMES
dwarf.h
HINTS
${PC_LIBDW_INCLUDE_DIRS}
PATHS
/usr/include
/usr/local/include
Expand All @@ -28,6 +37,8 @@ find_path (DWARF_INCLUDE_DIR
find_path (LIBDW_INCLUDE_DIR
NAMES
elfutils/libdw.h
HINTS
${PC_LIBDW_INCLUDE_DIRS}
PATHS
/usr/include
/usr/local/include
Expand All @@ -41,6 +52,8 @@ endif (DWARF_INCLUDE_DIR AND LIBDW_INCLUDE_DIR)
find_library (LIBDW_LIBRARY
NAMES
dw
HINTS
${PC_LIBDW_LIBRARY_DIRS}
PATHS
/usr/lib
/usr/local/lib
Expand Down
12 changes: 11 additions & 1 deletion cmake/FindLibElf.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,22 @@
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
#


if (LIBELF_LIBRARIES AND LIBELF_INCLUDE_DIRS)
set (LibElf_FIND_QUIETLY TRUE)
endif (LIBELF_LIBRARIES AND LIBELF_INCLUDE_DIRS)

find_package(PkgConfig QUIET)

if(PKG_CONFIG_FOUND)
set(PKG_CONFIG_USE_CMAKE_PREFIX_PATH ON)
pkg_check_modules(PC_LIBELF QUIET libelf)
endif()

find_path (LIBELF_INCLUDE_DIR
NAMES
libelf.h
HINTS
${PC_LIBELF_INCLUDE_DIRS}
PATHS
/usr/include
/usr/include/libelf
Expand All @@ -35,6 +43,8 @@ find_path (LIBELF_INCLUDE_DIR
find_library (LIBELF_LIBRARY
NAMES
elf
HINTS
${PC_LIBELF_LIBRARY_DIRS}
PATHS
/usr/lib
/usr/local/lib
Expand Down
46 changes: 24 additions & 22 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
cmake_minimum_required (VERSION 2.6)

# ====================================
# project name and version
# ====================================
project (kcov)
set (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH}
${CMAKE_CURRENT_SOURCE_DIR}/../../cmake)
list (APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../cmake")

if(POLICY CMP0042)
# MACOSX_RPATH is enabled by default.
cmake_policy (SET CMP0042 NEW)
endif()

find_package (Threads)
find_package (Bfd)

include(TargetArch)
target_architecture(CMAKE_TARGET_ARCHITECTURES)
message(STATUS "Target architectures: ${CMAKE_TARGET_ARCHITECTURES}")

pkg_check_modules(LIBZ REQUIRED zlib)
pkg_check_modules(LIBCURL libcurl)
find_package (ZLIB REQUIRED)
find_package (CURL)

# ====================================
# project name and version
# ====================================
project (kcov)
set (KCOV kcov)


Expand Down Expand Up @@ -69,14 +73,14 @@ endif()

set (coveralls_SRCS writers/dummy-coveralls-writer.cc)

if (LIBCURL_FOUND)
if (CURL_FOUND)
set (coveralls_SRCS writers/coveralls-writer.cc)
endif()

if ("${KCOV_STATIC_BUILD}" STREQUAL "1")
message(STATUS "Building a static binary (no coveralls support)")

set (LIBCURL_LIBRARIES "")
set (CURL_LIBRARIES "")
# Coveralls doesn't work in a static setting
set (coveralls_SRCS writers/dummy-coveralls-writer.cc)
set (CMAKE_EXE_LINKER_FLAGS "-static")
Expand Down Expand Up @@ -118,6 +122,7 @@ else()
"/usr/local/lib64"
"/opt/local/lib"
"/opt/usr/lib64"
"/Library/Developer/CommandLineTools/Library/PrivateFrameworks"
"/Applications/Xcode.app/Contents/SharedFrameworks"
ENV LIBRARY_PATH
ENV LD_LIBRARY_PATH
Expand Down Expand Up @@ -218,7 +223,7 @@ set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x -g -Wall -D_GLIBCXX_USE_NANO
include_directories(
include/
../external/lldb/include/
${LIBZ_INCLUDE_DIRS}
${ZLIB_INCLUDE_DIR}
)

if (LIBDW_FOUND)
Expand All @@ -233,22 +238,19 @@ include_directories(
)
endif()

if (LIBCURL_FOUND)
if (CURL_FOUND)
include_directories(
${LIBCURL_INCLUDE_DIRS}
${CURL_INCLUDE_DIRS}
)
endif()


link_directories (/home/ska/local/lib)

add_library (bash_execve_redirector SHARED engines/bash-execve-redirector.c)
set_target_properties(bash_execve_redirector PROPERTIES SUFFIX ".so")
target_link_libraries(bash_execve_redirector dl)

add_library (kcov_system_lib SHARED engines/system-mode-binary-lib.cc utils.cc system-mode/registration.cc)
set_target_properties(kcov_system_lib PROPERTIES SUFFIX ".so")
target_link_libraries(kcov_system_lib dl ${LIBZ_LIBRARIES})
target_link_libraries(kcov_system_lib dl ${ZLIB_LIBRARIES})


add_custom_command(
Expand Down Expand Up @@ -336,15 +338,15 @@ if (LIBELF_FOUND)
${LIBDW_LIBRARIES}
${LIBELF_LIBRARIES}
stdc++
${LIBCURL_LIBRARIES}
${CURL_LIBRARIES}
m
${DISASSEMBLER_LIBRARIES}
${LIBZ_LIBRARIES}
${ZLIB_LIBRARIES}
${CMAKE_THREAD_LIBS_INIT}
dl
${LLDB_LIBRARY}
)
install (TARGETS ${KCOV} ${INSTALL_TARGETS_PATH})
install (TARGETS ${KCOV} DESTINATION ${INSTALL_TARGETS_PATH})
endif()

if (${CMAKE_SYSTEM_NAME} MATCHES Linux)
Expand All @@ -353,9 +355,9 @@ if (${CMAKE_SYSTEM_NAME} MATCHES Linux)
target_link_libraries(kcov-system-daemon
stdc++
m
${LIBZ_LIBRARIES}
${ZLIB_LIBRARIES}
${CMAKE_THREAD_LIBS_INIT}
dl
)
install (TARGETS kcov-system-daemon ${INSTALL_TARGETS_PATH})
install (TARGETS kcov-system-daemon DESTINATION ${INSTALL_TARGETS_PATH})
endif()
2 changes: 0 additions & 2 deletions tests/unit-tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,6 @@ include_directories(
${LIBDW_INCLUDE_DIRS}
)

link_directories (/home/ska/local/lib)

add_executable (${TGT} ${${TGT}_SRCS} html-data-files.cc)

target_link_libraries(${TGT}
Expand Down
15 changes: 10 additions & 5 deletions tools/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
cmake_minimum_required (VERSION 2.6)

project (kcov-tools)
set (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH}
${CMAKE_CURRENT_SOURCE_DIR}/../cmake)
list (APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../cmake")

if(POLICY CMP0042)
# MACOSX_RPATH is enabled by default.
cmake_policy (SET CMP0042 NEW)
endif()

find_package (LibElf REQUIRED)
find_package (Elfutils REQUIRED)
find_package (PkgConfig REQUIRED)
find_package (Threads)
pkg_check_modules(LIBZ REQUIRED zlib)
find_package (ZLIB REQUIRED)

# ====================================
# project name and version
Expand Down Expand Up @@ -35,7 +40,7 @@ include_directories(
../src/include/
${LIBELF_INCLUDE_DIRS}
${LIBDW_INCLUDE_DIRS}
${LIBZ_INCLUDE_DIRS}
${ZLIB_INCLUDE_DIR}
)

# Reference: http://www.cmake.org/Wiki/CMake_RPATH_handling
Expand All @@ -59,7 +64,7 @@ target_link_libraries(${LINE2ADDR}
dl
${CMAKE_THREAD_LIBS_INIT}
m
${LIBZ_LIBRARIES})
${ZLIB_LIBRARIES})

file ( GLOB kcov-merge kcov-merge )

Expand Down

0 comments on commit 2e56d54

Please sign in to comment.