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

Add option to install library via cmake #60

Merged
merged 1 commit into from
Nov 30, 2021
Merged
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
49 changes: 47 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.5)
cmake_minimum_required(VERSION 3.8)
project(nanobench LANGUAGES CXX)

# determine whether this is a standalone project or included by other projects
Expand Down Expand Up @@ -53,7 +53,7 @@ if (NANOBENCH_STANDALONE_PROJECT)

# we have to globally set the property here, so it actually works https://cmake.org/pipermail/cmake/2010-March/036020.html
set_source_files_properties(
src/test/tutorial_fast_v1.cpp
src/test/tutorial_fast_v1.cpp
src/test/tutorial_fast_v2.cpp
PROPERTIES COMPILE_FLAGS "-fno-sanitize=integer")

Expand Down Expand Up @@ -81,6 +81,51 @@ if (NANOBENCH_STANDALONE_PROJECT)
add_compile_flags_target(nb)

target_sources_local(nb PUBLIC .clang-tidy)


include(GNUInstallDirs)
set(INSTALL_CONFIGDIR ${CMAKE_INSTALL_LIBDIR}/${PROJECT_NAME}/cmake)
set(INSTALL_LIBDIR ${CMAKE_INSTALL_LIBDIR}/${PROJECT_NAME})

# Install library target
add_library(nanobench STATIC ${PROJECT_SOURCE_DIR}/src/test/app/nanobench.cpp)
target_compile_features(nanobench PUBLIC cxx_std_11)
target_include_directories(nanobench
PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src/include>
$<INSTALL_INTERFACE:include>
)
install(
TARGETS nanobench
EXPORT install_targets
LIBRARY DESTINATION ${INSTALL_LIBDIR}
ARCHIVE DESTINATION ${INSTALL_LIBDIR}
)

# Install targets file
install(EXPORT install_targets
FILE
${PROJECT_NAME}Targets.cmake
NAMESPACE
${PROJECT_NAME}::
DESTINATION
${INSTALL_CONFIGDIR}
)

# Install ${PROJECT_NAME}Config.cmake
include(CMakePackageConfigHelpers)
configure_package_config_file(
${CMAKE_CURRENT_SOURCE_DIR}/cmake/${PROJECT_NAME}Config.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
INSTALL_DESTINATION ${INSTALL_CONFIGDIR}
)
install(FILES
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
DESTINATION ${INSTALL_CONFIGDIR}
)

# Install headers
install(FILES src/include/nanobench.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
else()
add_library(nanobench STATIC ${PROJECT_SOURCE_DIR}/src/test/app/nanobench.cpp)
add_library(nanobench::nanobench ALIAS nanobench)
Expand Down
5 changes: 5 additions & 0 deletions cmake/nanobenchConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
get_filename_component(nanobench_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)

if(NOT TARGET nanobench::nanobench)
include("${nanobench_CMAKE_DIR}/nanobenchTargets.cmake")
endif()