Skip to content

Commit

Permalink
Various updates (#6)
Browse files Browse the repository at this point in the history
* Cleanup CMake
* Update Readme
* Added example
* Added CI
  • Loading branch information
tdegeus authored Nov 21, 2019
1 parent 94b906c commit 6fe8bfd
Show file tree
Hide file tree
Showing 14 changed files with 439 additions and 192 deletions.
55 changes: 55 additions & 0 deletions .appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
build: false

branches:
only:
- master

platform:
- x64

image:
- Visual Studio 2017
- Visual Studio 2015

environment:
matrix:
- MINICONDA: C:\pyxtensor-conda

init:
- "ECHO %MINICONDA%"
- if "%APPVEYOR_BUILD_WORKER_IMAGE%" == "Visual Studio 2015" set VCVARPATH="C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat"
- if "%APPVEYOR_BUILD_WORKER_IMAGE%" == "Visual Studio 2015" set VCARGUMENT=%PLATFORM%
- if "%APPVEYOR_BUILD_WORKER_IMAGE%" == "Visual Studio 2017" set VCVARPATH="C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvars64.bat"
- echo "%VCVARPATH% %VCARGUMENT%"
- "%VCVARPATH% %VCARGUMENT%"
- ps: if($env:Platform -eq "x64"){Start-FileDownload 'http://repo.continuum.io/miniconda/Miniconda3-latest-Windows-x86_64.exe' C:\Miniconda.exe; echo "Done"}
- ps: if($env:Platform -eq "x86"){Start-FileDownload 'http://repo.continuum.io/miniconda/Miniconda3-latest-Windows-x86.exe' C:\Miniconda.exe; echo "Done"}
- cmd: C:\Miniconda.exe /S /D=C:\pyxtensor-conda
- "set PATH=%MINICONDA%;%MINICONDA%\\Scripts;%MINICONDA%\\Library\\bin;%PATH%"

install:
# Set environment using Conda
- conda config --set always_yes yes --set changeps1 no
- conda update -q conda
- conda info -a
- conda install python -c conda-forge
- conda install numpy -c conda-forge
- conda install matplotlib -c conda-forge
- conda install cmake -c conda-forge
- conda install xtensor -c conda-forge
- conda install pyxtensor -c conda-forge
# Install library
- cmake -G "NMake Makefiles" -DCMAKE_INSTALL_PREFIX=%MINICONDA%\\LIBRARY -DCMAKE_BUILD_TYPE=RELEASE .
- nmake
- nmake install
- python setup.py build
- python setup.py install

build_script:
# Run Python example
- python examples\python\match.py
# Compile and run C++ example
- cd examples\cpp
- cmake -G "NMake Makefiles" .
- nmake
- .\example
101 changes: 101 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
language: cpp
dist: trusty
env:
matrix:
fast_finish: true
include:
- os: linux
addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- g++-4.9
env: COMPILER=gcc GCC=4.9
- os: linux
addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- g++-5
env: COMPILER=gcc GCC=5
- os: linux
addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- g++-6
env: COMPILER=gcc GCC=6
- os: linux
addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- g++-7
env: COMPILER=gcc GCC=7
- os: linux
addons:
apt:
sources:
- ubuntu-toolchain-r-test
- llvm-toolchain-trusty-6.0
packages:
- clang-6.0
env: COMPILER=clang CLANG=6.0
- os: osx
osx_image: xcode8
compiler: clang
env:
global:
- MINCONDA_VERSION="latest"
- MINCONDA_LINUX="Linux-x86_64"
- MINCONDA_OSX="MacOSX-x86_64"
before_install:
- |
# Configure build variables
if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then
if [[ "$COMPILER" == "gcc" ]]; then
export CXX=g++-$GCC CC=gcc-$GCC;
fi
if [[ "$COMPILER" == "clang" ]]; then
export CXX=clang++-$CLANG CC=clang-$CLANG;
fi
elif [[ "$TRAVIS_OS_NAME" == "osx" ]]; then
export CXX=clang++ CC=clang;
fi
install:
# Set environment using Conda
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then
MINCONDA_OS=$MINCONDA_LINUX;
elif [[ "$TRAVIS_OS_NAME" == "osx" ]]; then
MINCONDA_OS=$MINCONDA_OSX;
fi
- wget "http://repo.continuum.io/miniconda/Miniconda3-$MINCONDA_VERSION-$MINCONDA_OS.sh" -O miniconda.sh;
- bash miniconda.sh -b -p $HOME/miniconda
- export PATH="$HOME/miniconda/bin:$PATH"
- hash -r
- conda config --set always_yes yes --set changeps1 no
- conda update -q conda
- conda install python -c conda-forge
- conda install numpy -c conda-forge
- conda install matplotlib -c conda-forge
- conda install cmake -c conda-forge
- conda install xtensor -c conda-forge
- conda install pyxtensor -c conda-forge
# Install library
- cmake .
- sudo make install
- python setup.py build
- python setup.py install
script:
# Run Python example
- python examples/python/match.py
# Compile and run C++ example
- cd examples/cpp
- cmake .
- make
- ./example

170 changes: 84 additions & 86 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,103 +1,101 @@
# required to specify the c++ standard
cmake_minimum_required(VERSION 3.0)

# required for install
include(CMakePackageConfigHelpers)
include(GNUInstallDirs)
cmake_minimum_required(VERSION 3.0)

# project settings
# ----------------
# Options
# =======

# name
project(cppcolormap)

# file that contains the version information
set(parse_version include/cppcolormap.h)
# Internals
# =========

set(CPPCOLORMAP_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include)

# Version
# =======

file(
STRINGS "${CPPCOLORMAP_INCLUDE_DIR}/cppcolormap.h" cppcolormap_version_defines
REGEX "#define CPPCOLORMAP_VERSION_(MAJOR|MINOR|PATCH)")

foreach(ver ${cppcolormap_version_defines})
if(ver MATCHES "#define CPPCOLORMAP_VERSION_(MAJOR|MINOR|PATCH) +([^ ]+)$")
set(CPPCOLORMAP_VERSION_${CMAKE_MATCH_1} "${CMAKE_MATCH_2}" CACHE INTERNAL "")
endif()
endforeach()

set(CPPCOLORMAP_VERSION
${CPPCOLORMAP_VERSION_MAJOR}.${CPPCOLORMAP_VERSION_MINOR}.${CPPCOLORMAP_VERSION_PATCH})

message(STATUS "Building cppcolormap v${CPPCOLORMAP_VERSION}")

# header files
set(headers include/cppcolormap.h)
# Build
# =====

# automatically parse the version number
file(READ "${parse_version}" version)
string(REGEX MATCH "define[ \t]+CPPCOLORMAP_WORLD_VERSION[ \t]+([0-9]+)" _ "${version}")
set(world_version "${CMAKE_MATCH_1}")
string(REGEX MATCH "define[ \t]+CPPCOLORMAP_MAJOR_VERSION[ \t]+([0-9]+)" _ "${version}")
set(major_version "${CMAKE_MATCH_1}")
string(REGEX MATCH "define[ \t]+CPPCOLORMAP_MINOR_VERSION[ \t]+([0-9]+)" _ "${version}")
set(minor_version "${CMAKE_MATCH_1}")
set(CPPCOLORMAP_VERSION_NUMBER ${world_version}.${major_version}.${minor_version})
set(CPPCOLORMAP_HEADERS
${CPPCOLORMAP_INCLUDE_DIR}/cppcolormap.h)

# paths
# -----
add_library(${PROJECT_NAME} INTERFACE)

set(CPPCOLORMAP_ROOT_DIR "${CMAKE_INSTALL_PREFIX}")
set(CPPCOLORMAP_INCLUDE_DIR "${CMAKE_INSTALL_INCLUDEDIR}")
set(INCLUDE_INSTALL_DIR "${CMAKE_INSTALL_INCLUDEDIR}")
set(CMAKEPACKAGE_INSTALL_DIR "${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME}")
set(PKGCONFIG_INSTALL_DIR "${CMAKE_INSTALL_DATADIR}/pkgconfig")
set(fcmake "cppcolormapConfig.cmake")
set(fpkg "cppcolormap.pc")
target_include_directories(
${PROJECT_NAME} INTERFACE
$<BUILD_INTERFACE:${CPPCOLORMAP_INCLUDE_DIR}>
$<INSTALL_INTERFACE:include>)

# options
# -------
# Installation
# ============

# configure pkg-config (default: on)
option(PKGCONFIG "Build pkg-config ${fpkg} file" ON)
include(CMakePackageConfigHelpers)
include(GNUInstallDirs)

# disable pkg-config for native Windows builds
if(WIN32 OR CMAKE_HOST_SYSTEM_NAME MATCHES Windows)
option(PKGCONFIG "Build pkg-config ${fpkg} file" OFF)
endif()
install(
TARGETS ${PROJECT_NAME}
EXPORT ${PROJECT_NAME}-targets)

# C++ standard
# ------------
export(
EXPORT ${PROJECT_NAME}-targets
FILE "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Targets.cmake")

set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
if(NOT CMAKE_CXX_STANDARD OR CMAKE_CXX_STANDARD LESS 14)
set(CMAKE_CXX_STANDARD 14)
endif()
install(
FILES ${CPPCOLORMAP_HEADERS}
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})

# configure CMake
# ---------------
set(CPPCOLORMAP_CMAKECONFIG_INSTALL_DIR
"${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" CACHE
STRING "install path for ${PROJECT_NAME}Config.cmake")

configure_package_config_file(
${CMAKE_CURRENT_SOURCE_DIR}/cppcolormapConfig.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/cppcolormapConfig.cmake
PATH_VARS CPPCOLORMAP_INCLUDE_DIR CPPCOLORMAP_ROOT_DIR
INSTALL_DESTINATION ${CMAKEPACKAGE_INSTALL_DIR}
NO_CHECK_REQUIRED_COMPONENTS_MACRO
)

# install
# -------

# pkg-config
if(PKGCONFIG)
configure_file(${fpkg}.in ${fpkg} @ONLY)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${fpkg} DESTINATION ${PKGCONFIG_INSTALL_DIR})
endif()

# CMake
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${fcmake} DESTINATION ${CMAKEPACKAGE_INSTALL_DIR})

# header files
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${headers} DESTINATION ${INCLUDE_INSTALL_DIR})

# print information to screen
# ---------------------------

message(STATUS "")
message(STATUS "+---------------------------------------------------------------------------------")
message(STATUS "|")
message(STATUS "| Use 'make install' to install in")
message(STATUS "| ${CMAKE_INSTALL_PREFIX}")
message(STATUS "|")
message(STATUS "| To specify a custom directory call")
message(STATUS "| cmake /path/to/${PROJECT_NAME} -DCMAKE_INSTALL_PREFIX=yourprefix")
message(STATUS "|")
message(STATUS "| For custom paths, add the following line to your '~/.bashrc'")
message(STATUS "| export PKG_CONFIG_PATH=${CMAKE_INSTALL_PREFIX}/share/pkgconfig:$PKG_CONFIG_PATH")
message(STATUS "|")
message(STATUS "+---------------------------------------------------------------------------------")
message(STATUS "")
"cppcolormapConfig.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
INSTALL_DESTINATION ${CPPCOLORMAP_CMAKECONFIG_INSTALL_DIR})

set(_CPPCOLORMAP_CMAKE_SIZEOF_VOID_P ${CMAKE_SIZEOF_VOID_P})

unset(CMAKE_SIZEOF_VOID_P)

write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
VERSION ${CPPCOLORMAP_VERSION}
COMPATIBILITY AnyNewerVersion)

set(CMAKE_SIZEOF_VOID_P ${_CPPCOLORMAP_CMAKE_SIZEOF_VOID_P})

install(
FILES
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
DESTINATION ${CPPCOLORMAP_CMAKECONFIG_INSTALL_DIR})

install(
EXPORT ${PROJECT_NAME}-targets
FILE "${PROJECT_NAME}Targets.cmake"
DESTINATION ${CPPCOLORMAP_CMAKECONFIG_INSTALL_DIR})

configure_file(
"cppcolormap.pc.in"
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc"
@ONLY)

install(
FILES "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig/")
Loading

0 comments on commit 6fe8bfd

Please sign in to comment.