Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make package relocatable (fixes #101) #107

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ addons:
before_script:
- mkdir build
- cd build
- cmake --version
- cmake .. -DLIBTINS_ENABLE_CXX11=1
- make tests

script:
- ctest -V
- ctest -V
19 changes: 12 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CMAKE_MINIMUM_REQUIRED(VERSION 2.8.1)
CMAKE_MINIMUM_REQUIRED(VERSION 2.8.8)
PROJECT(libtins)

# Compile in release mode by default
Expand Down Expand Up @@ -135,10 +135,11 @@ CONFIGURE_FILE(
)

# Support for pkg-config
# use 'pcfiledir' pkg-config variable to avoid absolute paths
SET(CMAKE_INSTALL_LIBDIR lib)
SET(pkgconfig_prefix ${CMAKE_INSTALL_PREFIX})
SET(pkgconfig_exec_prefix ${CMAKE_INSTALL_PREFIX})
SET(pkgconfig_libdir ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR})
SET(pkgconfig_prefix "\${pcfiledir}/../..")
SET(pkgconfig_libdir "\${prefix}/lib")
SET(pkgconfig_includedir "\${prefix}/include")
SET(pkgconfig_version ${LIBTINS_VERSION})
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/libtins.pc.in
${CMAKE_CURRENT_BINARY_DIR}/libtins.pc @ONLY)
Expand Down Expand Up @@ -172,6 +173,8 @@ ENDIF()
# CMake project configuration export
# **********************************

INCLUDE(CMakePackageConfigHelpers)

# Add all targets to the build-tree export set
EXPORT(
TARGETS tins
Expand All @@ -184,10 +187,12 @@ EXPORT(PACKAGE libtins)

# Create the libtinsConfig.cmake and libtinsConfigVersion.cmake files
# for the build tree
SET(CONF_INCLUDE_DIRS "${PROJECT_SOURCE_DIR}/include")
CONFIGURE_FILE(
SET(CONF_INCLUDE_DIRS "include")
CONFIGURE_PACKAGE_CONFIG_FILE(
cmake/libtinsConfig.cmake.in
"${PROJECT_BINARY_DIR}/libtinsConfig.cmake" @ONLY
"${PROJECT_BINARY_DIR}/libtinsConfig.cmake"
INSTALL_DESTINATION CMake
PATH_VARS CONF_INCLUDE_DIRS
)
CONFIGURE_FILE(
cmake/libtinsConfigVersion.cmake.in
Expand Down
9 changes: 8 additions & 1 deletion cmake/Modules/FindPCAP.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ set (HINT_DIR ${PCAP_ROOT_DIR}/lib)

# On x64 windows, we should look also for the .lib at /lib/x64/
# as this is the default path for the WinPcap developer's pack
if (${CMAKE_SIZEOF_VOID_P} EQUAL 8 AND WIN32)
if (WIN32 AND ${CMAKE_SIZEOF_VOID_P} EQUAL 8)
set (HINT_DIR ${PCAP_ROOT_DIR}/lib/x64/ ${HINT_DIR})
endif ()

Expand Down Expand Up @@ -82,3 +82,10 @@ mark_as_advanced(
PCAP_INCLUDE_DIR
PCAP_LIBRARY
)

# create imported target for libpcap dependency
if (PCAP_FOUND AND NOT TARGET PCAP)
add_library(PCAP IMPORTED SHARED)
set_target_properties(PCAP PROPERTIES IMPORTED_LOCATION ${PCAP_LIBRARY})
set(PCAP_LIBRARIES PCAP)
endif()
7 changes: 6 additions & 1 deletion cmake/libtinsConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
# LIBTINS_INCLUDE_DIRS - include directories for libtins
# LIBTINS_LIBRARIES - libraries to link against

@PACKAGE_INIT@

# Compute paths
get_filename_component(LIBTINS_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)
set(LIBTINS_INCLUDE_DIRS "@CONF_INCLUDE_DIRS@")
set_and_check(LIBTINS_INCLUDE_DIRS "@PACKAGE_CONF_INCLUDE_DIRS@")

# Our library dependencies (contains definitions for IMPORTED targets)
if(NOT TARGET libtins AND NOT LIBTINS_BINARY_DIR)
Expand All @@ -14,3 +16,6 @@ endif()

# These are IMPORTED targets created by libtinsTargets.cmake
set(LIBTINS_LIBRARIES tins)

include(CMakeFindDependencyMacro)
find_dependency(PCAP)
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ ADD_LIBRARY(
dot11/dot11_control.cpp
)

TARGET_LINK_LIBRARIES(tins ${PCAP_LIBRARY} ${OPENSSL_LIBRARIES} ${LIBTINS_OS_LIBS})
TARGET_LINK_LIBRARIES(tins PUBLIC ${PCAP_LIBRARIES} ${OPENSSL_LIBRARIES} ${LIBTINS_OS_LIBS})

SET_TARGET_PROPERTIES(tins PROPERTIES OUTPUT_NAME tins )
SET_TARGET_PROPERTIES(tins PROPERTIES VERSION ${LIBTINS_VERSION} SOVERSION ${LIBTINS_VERSION} )
Expand Down