Skip to content

Commit

Permalink
Merge pull request #184 from stefanbuettner/fix-cmake-installation
Browse files Browse the repository at this point in the history
Fix cmake installation
  • Loading branch information
emeryberger committed May 24, 2021
2 parents 47a3fca + 8f8ce2c commit cfe3e34
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 25 deletions.
21 changes: 19 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.4)
project(coz C CXX)
project(coz VERSION 0.2.2 LANGUAGES C CXX)

enable_testing()

Expand All @@ -18,9 +18,26 @@ option(INSTALL_COZ "Enable installation of coz. (Projects embedding coz may want

if(INSTALL_COZ)
include(GNUInstallDirs)
include(CMakePackageConfigHelpers)
install(PROGRAMS coz DESTINATION bin)
install(FILES LICENSE.md DESTINATION licenses)
install(FILES cmake/coz-profilerConfig.cmake DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake)
configure_package_config_file(
cmake/coz-profilerConfig.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/coz-profilerConfig.cmake
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake)
write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/coz-profilerConfigVersion.cmake
COMPATIBILITY ExactVersion) # SameMajor only applies to versions >= 1.0. Versions 0.x have to match exactly according to semver.org
install(
FILES
${CMAKE_CURRENT_BINARY_DIR}/coz-profilerConfig.cmake
${CMAKE_CURRENT_BINARY_DIR}/coz-profilerConfigVersion.cmake
DESTINATION
${CMAKE_INSTALL_LIBDIR}/cmake)
install(
EXPORT coz-profilerTargets
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake
NAMESPACE coz::)
endif()

add_subdirectory(libcoz)
Expand Down
21 changes: 0 additions & 21 deletions cmake/coz-profilerConfig.cmake

This file was deleted.

21 changes: 21 additions & 0 deletions cmake/coz-profilerConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
@PACKAGE_INIT@

message(INFO " ${COZ_INCLUDE_DIR} ${COZ_LIBRARY} ${COZ_FOUND}")

# Use find_dependency to find dependend packages.

include(${CMAKE_CURRENT_LIST_DIR}/coz-profilerTargets.cmake)

add_executable(coz::profiler IMPORTED)

# This includes the lib file
get_target_property(_COZ_LIBARRY_PATH coz::coz IMPORTED_LOCATION)
# {INSTALLATION}/lib/libcoz.so
get_filename_component(_IMPORT_PREFIX "${_COZ_LIBRARY_PATH}" PATH)
# {INSTALLATION}/lib
get_filename_component(_IMPORT_PREFIX "${_COZ_LIBARRY_PATH}" PATH)
# {INSTALLATION}
set_property(TARGET coz::profiler PROPERTY IMPORTED_LOCATION ${_COZ_LIBARRY_PATH})
# Cleanup temporary variables
set(_COZ_LIBARRY_PATH)

5 changes: 3 additions & 2 deletions libcoz/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,19 @@ endif()
target_include_directories(coz
PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include/coz>)
$<INSTALL_INTERFACE:include>)
target_link_libraries(coz PRIVATE ${CMAKE_DL_LIBS} rt Threads::Threads libelfin::libelfin)

add_library(coz-instrumentation INTERFACE)
target_include_directories(coz-instrumentation
INTERFACE
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include/coz>)
$<INSTALL_INTERFACE:include>)
target_link_libraries(coz-instrumentation INTERFACE -Wl,--push-state,--no-as-needed ${CMAKE_DL_LIBS} -Wl,--pop-state)

if(INSTALL_COZ)
install(TARGETS coz
EXPORT coz-profilerTargets
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
Expand Down

0 comments on commit cfe3e34

Please sign in to comment.