mirror of
https://github.com/p-ranav/indicators.git
synced 2025-12-16 04:18:51 +08:00
Merge pull request #31 from madebr/cmake
Update cmake + add conan + fix msvc + add appveyor
This commit is contained in:
16
.appveyor.yml
Normal file
16
.appveyor.yml
Normal file
@@ -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 .
|
||||
104
CMakeLists.txt
104
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
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>)
|
||||
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()
|
||||
|
||||
78
conanfile.py
Normal file
78
conanfile.py
Normal file
@@ -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"))
|
||||
@@ -29,7 +29,6 @@ SOFTWARE.
|
||||
#include <indicators/color.hpp>
|
||||
#include <indicators/details/stream_helper.hpp>
|
||||
|
||||
#define NOMINMAX
|
||||
#include <algorithm>
|
||||
#include <atomic>
|
||||
#include <chrono>
|
||||
|
||||
@@ -28,7 +28,6 @@ SOFTWARE.
|
||||
|
||||
#include <indicators/details/stream_helper.hpp>
|
||||
|
||||
#define NOMINMAX
|
||||
#include <algorithm>
|
||||
#include <atomic>
|
||||
#include <chrono>
|
||||
|
||||
@@ -28,7 +28,6 @@ SOFTWARE.
|
||||
|
||||
#include <indicators/details/stream_helper.hpp>
|
||||
|
||||
#define NOMINMAX
|
||||
#include <algorithm>
|
||||
#include <atomic>
|
||||
#include <chrono>
|
||||
|
||||
@@ -32,6 +32,9 @@
|
||||
#if defined(TERMCOLOR_OS_MACOS) || defined(TERMCOLOR_OS_LINUX)
|
||||
#include <unistd.h>
|
||||
#elif defined(TERMCOLOR_OS_WINDOWS)
|
||||
#if !defined(NOMINMAX)
|
||||
#define NOMINMAX
|
||||
#endif
|
||||
#include <io.h>
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
@@ -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}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -46,7 +46,6 @@ SOFTWARE.
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
#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 <unistd.h>
|
||||
#elif defined(TERMCOLOR_OS_WINDOWS)
|
||||
#if !defined(NOMINMAX)
|
||||
#define NOMINMAX
|
||||
#endif
|
||||
#include <io.h>
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user