diff --git a/CMakeLists.txt b/CMakeLists.txt index 7339cd0..f5d38bc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,67 @@ -cmake_minimum_required(VERSION 2.8.9) +cmake_minimum_required(VERSION 2.8...3.13) project(tqdm) +# Find version + +file(STRINGS "${CMAKE_CURRENT_SOURCE_DIR}/include/tqdm/tqdm.h" tqdm_version_defines + REGEX "#define TQDM_VERSION_(MAJOR|MINOR|PATCH)") + +foreach(ver ${tqdm_version_defines}) + if(ver MATCHES "#define TQDM_VERSION_(MAJOR|MINOR|PATCH) +([^ ]+)$") + set(TQDM_VERSION_${CMAKE_MATCH_1} + "${CMAKE_MATCH_2}" + CACHE INTERNAL "") + endif() +endforeach() + +set(TQDM_VERSION ${TQDM_VERSION_MAJOR}.${TQDM_VERSION_MINOR}.${TQDM_VERSION_PATCH}) + +message(STATUS "Building tqdm v${TQDM_VERSION}") + +# Set target + +add_library(tqdm.cpp INTERFACE) + +# set_target_properties(tdqm.cpp PROPERTIES OUTPUT_NAME tqdm) + +target_include_directories(tqdm.cpp INTERFACE + $ + $) + +# Installation + +include(CMakePackageConfigHelpers) +include(GNUInstallDirs) + +install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/include/" DESTINATION include) + +install(TARGETS tqdm.cpp EXPORT tqdm-targets) + +install( + EXPORT tqdm-targets + FILE tqdmTargets.cmake + DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/tqdm") + +set(_TQDM ${CMAKE_SIZEOF_VOID_P}) +unset(CMAKE_SIZEOF_VOID_P) + +write_basic_package_version_file("${CMAKE_CURRENT_BINARY_DIR}/tqdmConfigVersion.cmake" + VERSION ${TQDM_VERSION} + COMPATIBILITY AnyNewerVersion) + +set(CMAKE_SIZEOF_VOID_P ${_TQDM}) + +install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/tqdmConfig.cmake" + "${CMAKE_CURRENT_BINARY_DIR}/tqdmConfigVersion.cmake" + DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/tqdm") + +configure_file("${CMAKE_CURRENT_SOURCE_DIR}/tqdm.pc.in" + "${CMAKE_CURRENT_BINARY_DIR}/tqdm.pc" @ONLY) + +install(FILES "${CMAKE_CURRENT_BINARY_DIR}/tqdm.pc" + DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig/") + # so we can set up visual studio "folders" set_property(GLOBAL PROPERTY USE_FOLDERS ON) @@ -124,7 +184,7 @@ endif() ## target_link_libraries(tqdm) -if(UNIX) +if(UNIX AND NOT APPLE) macro(STRIP_FMT TARG STRIP_FMT_TARG STRIP_FMT_DEPS) if(CMAKE_COMPILER_IS_GNUCXX) @@ -147,7 +207,7 @@ STRIP_FMT( tqdm "$" "${TQDM_BIN_FILES}") STRIP_FMT(test_tqdm "$" "${TQDM_TEST_FILES}") STRIP_FMT(tqdmlib "$" "${TQDM_LIB_FILES}") -endif(UNIX) +endif() add_custom_command( TARGET test_tqdm diff --git a/include/tqdm/tqdm.h b/include/tqdm/tqdm.h index 2594d16..7dfd20c 100644 --- a/include/tqdm/tqdm.h +++ b/include/tqdm/tqdm.h @@ -36,6 +36,10 @@ Includes a default range iterator printing to stderr. #include // swap #include "tqdm/utils.h" +#define TQDM_VERSION_MAJOR 0 +#define TQDM_VERSION_MINOR 0 +#define TQDM_VERSION_PATCH 0 + #ifndef SIZE_T_MAX constexpr size_t SIZE_T_MAX = std::numeric_limits::max(); #endif diff --git a/tqdm.pc.in b/tqdm.pc.in new file mode 100644 index 0000000..527eb71 --- /dev/null +++ b/tqdm.pc.in @@ -0,0 +1,7 @@ +prefix=@CMAKE_INSTALL_PREFIX@ +includedir=${prefix}/include + +Name: @PROJECT_NAME@ +Description: C++ equivalent of tqdm +Version: @TQDM_VERSION@ +Cflags: -I${includedir} diff --git a/tqdmConfig.cmake b/tqdmConfig.cmake new file mode 100644 index 0000000..ba84ff1 --- /dev/null +++ b/tqdmConfig.cmake @@ -0,0 +1,21 @@ +# tqdm cmake module +# +# This module sets the target: +# +# tqdm.cpp +# +# In addition, it sets the following variables: +# +# tqdm_FOUND - true if tqdm found +# tqdm_VERSION - tqdm's version +# tqdm_INCLUDE_DIRS - the directory containing tqdm headers +# + +include(CMakeFindDependencyMacro) + +# Define target "tqdm" + +if(NOT TARGET tqdm.cpp) + include("${CMAKE_CURRENT_LIST_DIR}/tqdmTargets.cmake") + get_target_property(tqdm_INCLUDE_DIRS tqdm.cpp INTERFACE_INCLUDE_DIRECTORIES) +endif()