Skip to content

Commit

Permalink
infra: add install script for cmake
Browse files Browse the repository at this point in the history
  • Loading branch information
SGSSGene committed Jul 26, 2023
1 parent 6b0af4d commit 297b1ce
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 12 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ if (NOT DEFINED PROJECT_NAME)
set(TDL_ROOT_PROJECT TRUE)
endif ()

include (cmake/version.cmake)

project (tdl LANGUAGES CXX VERSION "${TDL_PROJECT_VERSION}"
DESCRIPTION "tdl -- tool description library")

Expand Down
38 changes: 38 additions & 0 deletions cmake/install.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# -----------------------------------------------------------------------------------------------------
# Copyright (c) 2006-2023, Knut Reinert & Freie Universität Berlin
# Copyright (c) 2016-2023, Knut Reinert & MPI für molekulare Genetik
# This file may be used, modified and/or redistributed under the terms of the 3-clause BSD-License
# shipped with this file.
# -----------------------------------------------------------------------------------------------------

cmake_minimum_required (VERSION 3.12)

include (${CMAKE_CURRENT_LIST_DIR}/version.cmake)
include (GNUInstallDirs)

if (yaml-cpp_FOUND)
set (TDL_INSTALL_TARGETS "")
else ()
set (TDL_INSTALL_TARGETS "yaml-cpp")
endif ()
install (TARGETS tdl ${TDL_INSTALL_TARGETS}
EXPORT tdl_targets
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
FRAMEWORK DESTINATION ${CMAKE_INSTALL_LIBDIR})
install (DIRECTORY "${CMAKE_CURRENT_LIST_DIR}/../src/tdl" TYPE INCLUDE)
install (EXPORT tdl_targets
NAMESPACE tdl::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/tdl
FILE tdl-config.cmake)

include (CMakePackageConfigHelpers)
set (version_file "${CMAKE_CURRENT_BINARY_DIR}/cmake/tdl-config-version.cmake")
write_basic_package_version_file (
${version_file}
VERSION "${TDL_VERSION}"
COMPATIBILITY AnyNewerVersion)
install (FILES ${version_file} DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/tdl)

install (FILES "${CMAKE_CURRENT_LIST_DIR}/../LICENSE.md" "${CMAKE_CURRENT_LIST_DIR}/../README.md" TYPE DOC)
8 changes: 8 additions & 0 deletions cmake/version.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# -----------------------------------------------------------------------------------------------------
# Copyright (c) 2006-2023, Knut Reinert & Freie Universität Berlin
# Copyright (c) 2016-2023, Knut Reinert & MPI für molekulare Genetik
# This file may be used, modified and/or redistributed under the terms of the 3-clause BSD-License
# shipped with this file.
# -----------------------------------------------------------------------------------------------------

set (TDL_VERSION "1.0.0")
36 changes: 24 additions & 12 deletions tdl-config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,44 @@

cmake_minimum_required (VERSION 3.12)
if (TARGET tdl)
return()
endif()
return ()
endif ()

find_package (yaml-cpp QUIET)
option (INSTALL_TDL "Enable installation of TDL. (Projects embedding TDL may want to turn this OFF.)" ON)

find_package (yaml-cpp QUIET)
if (NOT yaml-cpp_FOUND)
message (STATUS "Fetching yaml-cpp")
if (NOT ${CMAKE_FIND_PACKAGE_NAME}_FIND_QUIETLY)
message (STATUS "Fetching yaml-cpp")
endif ()

include (FetchContent)
FetchContent_Declare (
yaml-cpp_fetch_content
GIT_REPOSITORY "https://github.com/jbeder/yaml-cpp.git"
GIT_TAG "35b4498026b6293bfadc75f9ee325cb16d6975af") # 0.7.0 can't be properly installed
# !WORKAROUND git tag 0.7.0 can't be properly installed
GIT_TAG "35b4498026b6293bfadc75f9ee325cb16d6975af")
option (YAML_CPP_BUILD_CONTRIB "" OFF)
option (YAML_CPP_BUILD_TOOLS "" OFF)
option (YAML_BUILD_SHARED_LIBS "" OFF)
option (YAML_CPP_INSTALL "" ON)
option (YAML_CPP_INSTALL "" ${INSTALL_TDL})
option (YAML_CPP_BUILD_TESTS "" OFF)
set_property (GLOBAL PROPERTY CTEST_TARGETS_ADDED 1)
FetchContent_MakeAvailable (yaml-cpp_fetch_content)
else ()
message (STATUS "Found yaml-cpp ${yaml-cpp_VERSION}")
if (NOT ${CMAKE_FIND_PACKAGE_NAME}_FIND_QUIETLY)
message (STATUS "Found yaml-cpp")
endif ()
endif ()

add_library(tdl INTERFACE)
target_include_directories(tdl INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/src>
$<INSTALL_INTERFACE:include>)
target_link_libraries(tdl INTERFACE yaml-cpp)
add_library (tdl INTERFACE)
target_include_directories (tdl INTERFACE
"$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/src>"
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>")
# !WORKAROUND yaml-cpp::yaml-cpp does not work for 0.7.0 if installed on system
target_link_libraries (tdl INTERFACE yaml-cpp)
add_library (tdl::tdl ALIAS tdl)

if (INSTALL_TDL)
include (${CMAKE_CURRENT_LIST_DIR}/cmake/install.cmake)
endif ()

0 comments on commit 297b1ce

Please sign in to comment.