We'll be taking GitLab down for maintenance around 22 in the evening on the 15th of September, so this Sunday. Let us know (tt.mpi-cbg.de) if you experience any issues with it after the maintenance period.

Unverified Commit 5fe753e1 authored by Peter Steinbach's avatar Peter Steinbach Committed by GitHub

Merge pull request #18 from psteinb/better_cmake_support

Better cmake support
parents bd463668 a52bbaef
Pipeline #626 passed with stages
in 1 minute and 20 seconds
......@@ -17,10 +17,17 @@ include(CheckCXXSourceCompiles)
SET (COMPASS_NAME "Compass - drop-in header-only C++ library to detect hardware capabilities at runtime and at compiletime")
SET (COMPASS_CODENAME "${PROJECT_NAME}")
SET (COMPASS_COPYRIGHT_YEARS "2017")
SET (COMPASS_VERSION_MAJOR 0)
SET (COMPASS_VERSION_MINOR 0)
SET (COMPASS_VERSION_PATCH 0)
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake )
include(git_utils)
git_describe(COMPASS_VERSION --tags --abbrev=0)
git_describe(COMPASS_VERSION_HEADREF --always)
string(REPLACE "." ";" COMPASS_VERSION_ASLIST ${COMPASS_VERSION})
list(GET COMPASS_VERSION_ASLIST 0 COMPASS_VERSION_MAJOR)
list(GET COMPASS_VERSION_ASLIST 1 COMPASS_VERSION_MINOR)
list(GET COMPASS_VERSION_ASLIST 2 COMPASS_VERSION_PATCH)
SET (COMPASS_VERSION "${COMPASS_VERSION_MAJOR}.${COMPASS_VERSION_MINOR}.${COMPASS_VERSION_PATCH}")
SET (COMPASS_VENDOR_ID "psteinb")
SET (COMPASS_ID "${COMPASS_VENDOR_ID}.${PROJECT_NAME}")
......@@ -149,21 +156,41 @@ if(WITH_TESTS)
endif()
################################ EXPORT/INSTALL ################################
export(
TARGETS ${COMPASS_TARGET_NAME}
NAMESPACE ${PROJECT_NAME}::
FILE ${COMPASS_CMAKE_PROJECT_TARGETS_FILE}
)
install(
TARGETS ${COMPASS_TARGET_NAME}
EXPORT ${PROJECT_NAME}Targets
EXPORT ${COMPASS_TARGETS_EXPORT_NAME}
INCLUDES DESTINATION ${COMPASS_INCLUDE_INSTALL_DIR}
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin
ARCHIVE DESTINATION lib
)
install(
EXPORT ${COMPASS_TARGETS_EXPORT_NAME}
FILE ${COMPASS_TARGETS_EXPORT_NAME}.cmake
NAMESPACE ${PROJECT_NAME}::
DESTINATION ${COMPASS_CONFIG_INSTALL_DIR}
DESTINATION lib/cmake/${PROJECT_NAME}
)
# install(
# EXPORT ${COMPASS_TARGETS_EXPORT_NAME}
# NAMESPACE ${PROJECT_NAME}::
# DESTINATION ${COMPASS_CONFIG_INSTALL_DIR}
# )
include(CMakePackageConfigHelpers)
configure_package_config_file(
${PROJECT_SOURCE_DIR}/cmake/${PROJECT_NAME}Config.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
INSTALL_DESTINATION ${LIB_INSTALL_DIR}/cmake/${PROJECT_NAME}
PATH_VARS COMPASS_INCLUDE_INSTALL_DIR)
write_basic_package_version_file(${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
VERSION ${COMPASS_VERSION}
COMPATIBILITY SameMajorVersion
)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
DESTINATION lib/cmake/${PROJECT_NAME})
install(DIRECTORY "${COMPASS_INCLUDE_BUILD_DIR}"
DESTINATION include
FILES_MATCHING
......
set(COMPASS_VERSION @COMPASS_VERSION@)
...
@PACKAGE_INIT@
...
set_and_check(COMPASS_INCLUDE_DIR "@PACKAGE_INCLUDE_INSTALL_DIR@")
check_required_components(Compass)
# small cmake module to help extracting the tag and head hash of the current source code tree
#
# find_git_root ... tries to find the .git folder of this repo or any of it's parents
# git_ready ... helper function that checks if the current directory is under version control by git
# git_describe ... interface to git describe command line call, note only stdout is captured in the output variable
#
find_package(Git QUIET)
function(find_git_root _git_root)
set(${_git_root} "GIT_ROOT_DIR-NOTFOUND")
if(GIT_NOTFOUND)
message(INFO "git not found on this system")
return()
endif()
set(GIT_PARENT_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
set(GIT_PROJECT_ROOT "${GIT_PARENT_DIR}/.git")
while(NOT EXISTS "${GIT_PROJECT_ROOT}") # .git dir not found, search parent directories
set(GIT_PREVIOUS_PARENT "${GIT_PARENT_DIR}")
get_filename_component(GIT_PARENT_DIR ${GIT_PARENT_DIR} PATH)
if(GIT_PARENT_DIR STREQUAL GIT_PREVIOUS_PARENT)
# We have reached the root directory, we are not in git
set(${_git_root} "GIT_ROOT_DIR-NOTFOUND" PARENT_SCOPE)
return()
endif()
set(${_git_root} "${GIT_PARENT_DIR}/.git" PARENT_SCOPE)
set(GIT_PROJECT_ROOT "${GIT_PARENT_DIR}/.git")
endwhile()
endfunction()
function(git_ready _var)
find_git_root(GIT_ROOT_DIR)
if(IS_DIRECTORY ${GIT_ROOT_DIR})
set(${_var} "True" PARENT_SCOPE)
else()
set(${_var} "False" PARENT_SCOPE)
endif()
endfunction()
function(git_describe _var)
find_git_root(GIT_ROOT_DIR)
execute_process(COMMAND
"${GIT_EXECUTABLE}"
describe
${hash}
${ARGN}
WORKING_DIRECTORY
"${GIT_ROOT_DIR}"
RESULT_VARIABLE
res
OUTPUT_VARIABLE
out
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE)
set(${_var} "${out}" PARENT_SCOPE)
endfunction()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment