Merge pull request #31 from madebr/cmake

Update cmake + add conan + fix msvc + add appveyor
This commit is contained in:
Pranav
2020-02-21 13:24:43 +05:30
committed by GitHub
10 changed files with 180 additions and 35 deletions

16
.appveyor.yml Normal file
View 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 .

View File

@@ -1,8 +1,21 @@
cmake_minimum_required(VERSION 3.8) 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) if(DEFINED PROJECT_NAME)
option(SAMPLES "Build Samples" OFF) set(INDICATORS_SUBPROJECT ON)
option(DEMO "Build Demo" OFF) 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(CMakePackageConfigHelpers)
include(GNUInstallDirs) include(GNUInstallDirs)
@@ -18,33 +31,68 @@ target_include_directories(indicators INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>) $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>)
target_link_libraries(indicators INTERFACE Threads::Threads) target_link_libraries(indicators INTERFACE Threads::Threads)
if(INDICATORS_DEMO)
if( DEMO ) add_subdirectory(demo)
add_subdirectory(demo)
endif() endif()
if( SAMPLES ) if(INDICATORS_SAMPLES)
add_subdirectory(samples) add_subdirectory(samples)
endif() endif()
configure_package_config_file(indicatorsConfig.cmake.in if(NOT INDICATORS_SUBPROJECT)
${CMAKE_CURRENT_BINARY_DIR}/indicatorsConfig.cmake configure_package_config_file(indicatorsConfig.cmake.in
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/indicators) ${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 configure_file(indicators.pc.in indicators.pc @ONLY)
"${CMAKE_CURRENT_BINARY_DIR}/pkgconfig/indicators.pc"
@ONLY)
install(TARGETS indicators EXPORT indicatorsTargets) install(TARGETS indicators EXPORT indicatorsTargets)
install(EXPORT indicatorsTargets install(EXPORT indicatorsTargets
FILE indicatorsTargets.cmake FILE indicatorsTargets.cmake
NAMESPACE indicators:: NAMESPACE indicators::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/indicators) DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/indicators)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/indicatorsConfig.cmake install(FILES ${CMAKE_CURRENT_BINARY_DIR}/indicatorsConfig.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/indicators) ${CMAKE_CURRENT_BINARY_DIR}/indicatorsConfigVersion.cmake
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/pkgconfig/indicators.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/indicators)
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/pkgconfig/) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/indicators.pc
install(DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/include/indicators DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} install(DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/include/indicators
USE_SOURCE_PERMISSIONS DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
PATTERN "*.hpp") 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
View 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"))

View File

@@ -29,7 +29,6 @@ SOFTWARE.
#include <indicators/color.hpp> #include <indicators/color.hpp>
#include <indicators/details/stream_helper.hpp> #include <indicators/details/stream_helper.hpp>
#define NOMINMAX
#include <algorithm> #include <algorithm>
#include <atomic> #include <atomic>
#include <chrono> #include <chrono>

View File

@@ -28,7 +28,6 @@ SOFTWARE.
#include <indicators/details/stream_helper.hpp> #include <indicators/details/stream_helper.hpp>
#define NOMINMAX
#include <algorithm> #include <algorithm>
#include <atomic> #include <atomic>
#include <chrono> #include <chrono>

View File

@@ -28,7 +28,6 @@ SOFTWARE.
#include <indicators/details/stream_helper.hpp> #include <indicators/details/stream_helper.hpp>
#define NOMINMAX
#include <algorithm> #include <algorithm>
#include <atomic> #include <atomic>
#include <chrono> #include <chrono>

View File

@@ -32,6 +32,9 @@
#if defined(TERMCOLOR_OS_MACOS) || defined(TERMCOLOR_OS_LINUX) #if defined(TERMCOLOR_OS_MACOS) || defined(TERMCOLOR_OS_LINUX)
#include <unistd.h> #include <unistd.h>
#elif defined(TERMCOLOR_OS_WINDOWS) #elif defined(TERMCOLOR_OS_WINDOWS)
#if !defined(NOMINMAX)
#define NOMINMAX
#endif
#include <io.h> #include <io.h>
#include <windows.h> #include <windows.h>
#endif #endif

View File

@@ -1,6 +1,7 @@
includedir=@CMAKE_INSTALL_FULL_INCLUDEDIR@ includedir=@CMAKE_INSTALL_FULL_INCLUDEDIR@
Name: indicators Name: @PROJECT_NAME@
Description: Activity Indicators for Modern C++ Description: @PROJECT_DESCRIPTION@
URL: @PROJECT_HOMEPAGE_URL@
Version: @PROJECT_VERSION@ Version: @PROJECT_VERSION@
Cflags: -I${includedir} Cflags: -I${includedir}

View File

@@ -2,7 +2,7 @@
include(CMakeFindDependencyMacro) include(CMakeFindDependencyMacro)
find_dependency(Threads) find_dependency(Threads REQUIRED)
if (NOT TARGET indicators::indicators) if (NOT TARGET indicators::indicators)
include(${CMAKE_CURRENT_LIST_DIR}/indicatorsTargets.cmake) include(${CMAKE_CURRENT_LIST_DIR}/indicatorsTargets.cmake)

View File

@@ -46,7 +46,6 @@ SOFTWARE.
#include <type_traits> #include <type_traits>
#include <utility> #include <utility>
#include <vector> #include <vector>
#define NOMINMAX
namespace indicators { namespace indicators {
enum class Color { grey, red, green, yellow, blue, magenta, cyan, white }; 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) #if defined(TERMCOLOR_OS_MACOS) || defined(TERMCOLOR_OS_LINUX)
#include <unistd.h> #include <unistd.h>
#elif defined(TERMCOLOR_OS_WINDOWS) #elif defined(TERMCOLOR_OS_WINDOWS)
#if !defined(NOMINMAX)
#define NOMINMAX
#endif
#include <io.h> #include <io.h>
#include <windows.h> #include <windows.h>
#endif #endif