diff --git a/.appveyor.yml b/.appveyor.yml new file mode 100644 index 0000000..999e1f1 --- /dev/null +++ b/.appveyor.yml @@ -0,0 +1,16 @@ +environment: + CONAN_RUN_TESTS: True + matrix: + - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019 + PATH: C:\\Python37;C:\\Python37\Scripts;C:\Users\appveyor\AppData\Roaming\Python\Python37\Scripts;%PATH% + # - APPVEYOR_BUILD_WORKER_IMAGE: Ubuntu + # PATH: /home/appveyor/.local/bin:$PATH + # - APPVEYOR_BUILD_WORKER_IMAGE: macOS + +install: + - python --version + - python -m pip install conan --upgrade --user + - conan user + +build_script: + - conan create . diff --git a/CMakeLists.txt b/CMakeLists.txt index 056c2eb..528bcfd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,8 +1,21 @@ cmake_minimum_required(VERSION 3.8) -project(indicators VERSION 1.7.0 LANGUAGES CXX DESCRIPTION "Activity Indicators for Modern C++") -option(INDICATORS_BUILD_TESTS OFF) -option(SAMPLES "Build Samples" OFF) -option(DEMO "Build Demo" OFF) + +if(DEFINED PROJECT_NAME) + set(INDICATORS_SUBPROJECT ON) +endif() + +project(indicators VERSION 1.7.0 LANGUAGES CXX + HOMEPAGE_URL "https://github.com/p-ranav/indicators" + DESCRIPTION "Activity Indicators for Modern C++") + +if(EXISTS "${CMAKE_BINARY_DIR}/conanbuildinfo.cmake") + include("${CMAKE_BINARY_DIR}/conanbuildinfo.cmake") + conan_basic_setup() +endif() + +option(INDICATORS_BUILD_TESTS "Build indicators tests + enable CTest") +option(INDICATORS_SAMPLES "Build indicators samples") +option(INDICATORS_DEMO "Build indicators demo" OFF) include(CMakePackageConfigHelpers) include(GNUInstallDirs) @@ -18,33 +31,68 @@ target_include_directories(indicators INTERFACE $) target_link_libraries(indicators INTERFACE Threads::Threads) - -if( DEMO ) - add_subdirectory(demo) +if(INDICATORS_DEMO) + add_subdirectory(demo) endif() -if( SAMPLES ) - add_subdirectory(samples) +if(INDICATORS_SAMPLES) + add_subdirectory(samples) endif() -configure_package_config_file(indicatorsConfig.cmake.in - ${CMAKE_CURRENT_BINARY_DIR}/indicatorsConfig.cmake - INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/indicators) +if(NOT INDICATORS_SUBPROJECT) + configure_package_config_file(indicatorsConfig.cmake.in + ${CMAKE_CURRENT_BINARY_DIR}/indicatorsConfig.cmake + INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/indicators) + write_basic_package_version_file(indicatorsConfigVersion.cmake + COMPATIBILITY AnyNewerVersion) -configure_file(indicators.pc.in - "${CMAKE_CURRENT_BINARY_DIR}/pkgconfig/indicators.pc" - @ONLY) + configure_file(indicators.pc.in indicators.pc @ONLY) -install(TARGETS indicators EXPORT indicatorsTargets) -install(EXPORT indicatorsTargets - FILE indicatorsTargets.cmake - NAMESPACE indicators:: - DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/indicators) -install(FILES ${CMAKE_CURRENT_BINARY_DIR}/indicatorsConfig.cmake - DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/indicators) -install(FILES ${CMAKE_CURRENT_BINARY_DIR}/pkgconfig/indicators.pc - DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/pkgconfig/) -install(DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/include/indicators - DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} - USE_SOURCE_PERMISSIONS - PATTERN "*.hpp") + install(TARGETS indicators EXPORT indicatorsTargets) + install(EXPORT indicatorsTargets + FILE indicatorsTargets.cmake + NAMESPACE indicators:: + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/indicators) + install(FILES ${CMAKE_CURRENT_BINARY_DIR}/indicatorsConfig.cmake + ${CMAKE_CURRENT_BINARY_DIR}/indicatorsConfigVersion.cmake + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/indicators) + install(FILES ${CMAKE_CURRENT_BINARY_DIR}/indicators.pc + DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) + install(DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/include/indicators + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + USE_SOURCE_PERMISSIONS + PATTERN "*.hpp") + install(FILES LICENSE LICENSE.termcolor + DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/licenses/indicators) + + if(EXISTS "${PROJECT_SOURCE_DIR}/.gitignore") + # Simple glob to regex conversion (.gitignore => CPACK_SOURCE_IGNORE_FILES) + file(READ ".gitignore" DOT_GITIGNORE) + string(REPLACE ";" "RANDOMSEQUENCE" DOT_GITIGNORE "${DOT_GITIGNORE}") + string(REPLACE "\n" ";" DOT_GITIGNORE "${DOT_GITIGNORE}") + string(REPLACE "RANDOMSEQUENCE" "\\;" DOT_GITIGNORE "${DOT_GITIGNORE}") + foreach(IGNORE_LINE ${DOT_GITIGNORE}) + if(NOT IGNORE_LINE OR IGNORE_LINE MATCHES "^#") + continue() + endif() + string(REPLACE "\\" "\\\\" IGNORE_LINE "${IGNORE_LINE}") + string(REPLACE "." "\\\\." IGNORE_LINE "${IGNORE_LINE}") + string(REPLACE "*" ".*" IGNORE_LINE "${IGNORE_LINE}") + string(REPLACE "+" "\\\\+" IGNORE_LINE "${IGNORE_LINE}") + list(APPEND CPACK_SOURCE_IGNORE_FILES "${IGNORE_LINE}") + endforeach() + endif() + + # extra ignored files + list(APPEND CPACK_SOURCE_IGNORE_FILES + .editorconfig + .git + .gitignore + .travis.yml + .appveyor.yml + ) + set(CPACK_SOURCE_PACKAGE_FILE_NAME "${PROJECT_NAME}-${PROJECT_VERSION}") + set(CPACK_GENERATOR "TGZ;TXZ") + set(CPACK_SOURCE_GENERATOR "TGZ;TXZ") + include(CPack) +endif() diff --git a/conanfile.py b/conanfile.py new file mode 100644 index 0000000..e0e1278 --- /dev/null +++ b/conanfile.py @@ -0,0 +1,78 @@ +from conans import CMake, ConanFile, tools +from conans.errors import ConanException +from contextlib import contextmanager +import os + + +class IndicatorsConan(ConanFile): + name = "indicators" + description = "Activity Indicators for Modern C++" + topics = ("indicators", "progress", "activity", "indicator", "header-only", "c++11") + homepage = "https://github.com/p-ranav/indicators" + url = "https://github.com/p-ranav/indicators" + license = ("MIT", "BSD-3-Clause") + exports_sources = "demo/**", "include/**", "samples/**", "CMakeLists.txt", "LICENSE*", \ + "indicators.pc.in", "indicatorsConfig.cmake.in", "README*", "img/**" + exports = "LICENSE" + no_copy_source = True + settings = "os", "arch", "compiler", "build_type" + generators = "cmake" + + def set_version(self): + import re + m = re.search(r"project\(.*VERSION ([0-9a-zA-Z.-]+)[ )]", + open(os.path.join(self.recipe_folder, "CMakeLists.txt")).read()) + if not m: + raise ConanException("Could not extract version from CMakeLists.txt") + self.version = m.group(1) + + _cmake = None + + def _configure_cmake(self): + if self._cmake: + return self._cmake + generator = None + if self.settings.compiler == "Visual Studio": + generator = "NMake Makefiles" + self._cmake = CMake(self, generator=generator) + if tools.get_env("CONAN_RUN_TESTS", default=False): + self._cmake.definitions["INDICATORS_DEMO"] = True + self._cmake.definitions["INDICATORS_SAMPLES"] = True + self._cmake.configure() + return self._cmake + + @property + def _test_programs(self): + programs = [] + import re + for subdir in ("demo", "samples", ): + for match in re.finditer(r"add_executable\((\S+)", + open(os.path.join(self.source_folder, subdir, "CMakeLists.txt")).read()): + programs.append(os.path.join(self.build_folder, "bin", match.group(1))) + return programs + + @contextmanager + def _build_context(self): + with tools.vcvars(self.settings) if self.settings.compiler == "Visual Studio" else tools.no_op(): + yield + + def build(self): + with self._build_context(): + cmake = self._configure_cmake() + cmake.build() + cmake.build(target="package_source") + # if tools.get_env("CONAN_RUN_TESTS", default=False): + # for program in self._test_programs: + # self.output.info("Running program '{}'".format(program)) + # self.run(program, run_environment=True) + + def package(self): + with self._build_context(): + cmake = self._configure_cmake() + cmake.install() + + def package_id(self): + self.info.header_only() + + def package_info(self): + self.cpp_info.includedirs.append(os.path.join("include", "indicators")) diff --git a/include/indicators/block_progress_bar.hpp b/include/indicators/block_progress_bar.hpp index ca35042..3857320 100644 --- a/include/indicators/block_progress_bar.hpp +++ b/include/indicators/block_progress_bar.hpp @@ -29,7 +29,6 @@ SOFTWARE. #include #include -#define NOMINMAX #include #include #include diff --git a/include/indicators/progress_bar.hpp b/include/indicators/progress_bar.hpp index 02cceb9..7235f54 100644 --- a/include/indicators/progress_bar.hpp +++ b/include/indicators/progress_bar.hpp @@ -28,7 +28,6 @@ SOFTWARE. #include -#define NOMINMAX #include #include #include diff --git a/include/indicators/progress_spinner.hpp b/include/indicators/progress_spinner.hpp index c39ec5c..9a4d7c2 100644 --- a/include/indicators/progress_spinner.hpp +++ b/include/indicators/progress_spinner.hpp @@ -28,7 +28,6 @@ SOFTWARE. #include -#define NOMINMAX #include #include #include diff --git a/include/indicators/termcolor.hpp b/include/indicators/termcolor.hpp index c2eda0d..a0238a4 100644 --- a/include/indicators/termcolor.hpp +++ b/include/indicators/termcolor.hpp @@ -32,6 +32,9 @@ #if defined(TERMCOLOR_OS_MACOS) || defined(TERMCOLOR_OS_LINUX) #include #elif defined(TERMCOLOR_OS_WINDOWS) +#if !defined(NOMINMAX) +#define NOMINMAX +#endif #include #include #endif diff --git a/indicators.pc.in b/indicators.pc.in index 4e20701..58e8f5c 100644 --- a/indicators.pc.in +++ b/indicators.pc.in @@ -1,6 +1,7 @@ includedir=@CMAKE_INSTALL_FULL_INCLUDEDIR@ -Name: indicators -Description: Activity Indicators for Modern C++ +Name: @PROJECT_NAME@ +Description: @PROJECT_DESCRIPTION@ +URL: @PROJECT_HOMEPAGE_URL@ Version: @PROJECT_VERSION@ Cflags: -I${includedir} diff --git a/indicatorsConfig.cmake.in b/indicatorsConfig.cmake.in index ff85be8..edbe144 100644 --- a/indicatorsConfig.cmake.in +++ b/indicatorsConfig.cmake.in @@ -2,7 +2,7 @@ include(CMakeFindDependencyMacro) -find_dependency(Threads) +find_dependency(Threads REQUIRED) if (NOT TARGET indicators::indicators) include(${CMAKE_CURRENT_LIST_DIR}/indicatorsTargets.cmake) diff --git a/single_include/indicators/indicators.hpp b/single_include/indicators/indicators.hpp index 777fc4e..42453cb 100644 --- a/single_include/indicators/indicators.hpp +++ b/single_include/indicators/indicators.hpp @@ -46,7 +46,6 @@ SOFTWARE. #include #include #include -#define NOMINMAX namespace indicators { enum class Color { grey, red, green, yellow, blue, magenta, cyan, white }; @@ -86,6 +85,9 @@ enum class Color { grey, red, green, yellow, blue, magenta, cyan, white }; #if defined(TERMCOLOR_OS_MACOS) || defined(TERMCOLOR_OS_LINUX) #include #elif defined(TERMCOLOR_OS_WINDOWS) +#if !defined(NOMINMAX) +#define NOMINMAX +#endif #include #include #endif