Contents
Put a copy of type-lite.hpp
located in folder include directly into the project source tree or somewhere reachable from your project, for example in project-root/include. A minimal CMake setup using this header might look as follows.
In project root folder:
cmake_minimum_required( VERSION 3.5 FATAL_ERROR )
project( use-type-lite LANGUAGES CXX )
# Provide #include access to type-lite as 'nonstd/type.hpp':
set( TYPE_LITE_INCLUDE_DIR include ) # adapt as necessary
add_library( type INTERFACE )
target_include_directories( type INTERFACE ${TYPE_LITE_INCLUDE_DIR} )
# Build program from src:
add_subdirectory( src )
In folder src:
cmake_minimum_required( VERSION 3.5 FATAL_ERROR )
project( program-using-type-lite LANGUAGES CXX )
# Make program executable:
set( SOURCES main.cpp)
add_executable( program ${SOURCES} )
target_link_libraries( program PRIVATE type )
Another approach is to automatically fetch the entire type-lite repository from github and configure it as an external project.
cmake_minimum_required( VERSION 3.5 FATAL_ERROR )
project( use-type-lite LANGUAGES CXX )
# Set default ExternalProject root directory and add type-lite:
set( TYPE_LITE_URL https://github.com/martinmoene/type-lite.git )
include( ExternalProject )
find_package( Git REQUIRED )
set_directory_properties( PROPERTIES EP_PREFIX ${CMAKE_BINARY_DIR}/3rd_party )
ExternalProject_Add(
type-extern
GIT_REPOSITORY ${TYPE_LITE_URL}
TIMEOUT 10
UPDATE_COMMAND ${GIT_EXECUTABLE} pull
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
LOG_DOWNLOAD ON
)
# Provide #include access to type-lite as 'nonstd/type.hpp':
ExternalProject_Get_Property( type-extern SOURCE_DIR )
set( TYPE_LITE_INCLUDE_DIR ${SOURCE_DIR}/include CACHE INTERNAL "Include folder for type-lite")
add_library( type INTERFACE )
target_include_directories( type INTERFACE ${TYPE_LITE_INCLUDE_DIR} )
# Build program from src:
add_subdirectory( src )
In folder src:
cmake_minimum_required( VERSION 3.5 FATAL_ERROR )
project( program-using-type-lite LANGUAGES CXX )
# Make program executable:
set( SOURCES main.cpp)
add_executable( program ${SOURCES} )
target_link_libraries( program PRIVATE type )
This setup brings in more than you need, but also makes it easy to update type-lite to the latest version.
-
First install the type-lite CMake package from its source, for example:
cd ./type-lite cmake -H. -B../_build -G"Unix Makefiles" -DCMAKE_INSTALL_PREFIX="~/dev" cmake --build ../_build --target install
-
Next, you can use the type-lite CMake package, for example:
cmake_minimum_required( VERSION 3.5 FATAL_ERROR ) find_package( type-lite "0.2" REQUIRED ) project( program-using-type-lite LANGUAGES CXX ) add_executable( program main.cpp ) target_link_libraries( program PRIVATE nonstd::type-lite )
Configure and build:
cd ./type-lite/example/cmake-pkg cmake -H. -B../_build -G"Unix Makefiles" -DCMAKE_INSTALL_PREFIX=_stage -DCMAKE_PREFIX_PATH="~/dev" cmake --build ../_build
For the conan package manager, follow these steps:
-
Add nonstd-lite to the conan remotes:
conan remote add nonstd-lite https://api.bintray.com/conan/martinmoene/nonstd-lite
-
Add a reference to type-lite to the requires section of your project's
conanfile.txt
file:[requires] type-lite 0.2.0@nonstd-lite/stable
-
Run conan's install command:
conan install