Skip to content

Instantly share code, notes, and snippets.

@kwk
Created February 9, 2015 13:37
Show Gist options
  • Save kwk/20a73f918e4c8b4bec7a to your computer and use it in GitHub Desktop.
Save kwk/20a73f918e4c8b4bec7a to your computer and use it in GitHub Desktop.
Use boost from Git repo together with CMake External Project
project(regex)
cmake_minimum_required(VERSION 2.8)
# For some external project macros
include(ExternalProject)
# Download boost from git and build regex module
ExternalProject_Add(
boost
PREFIX ${CMAKE_CURRENT_BINARY_DIR}/boost
GIT_REPOSITORY https://github.com/ryppl/boost-svn.git
GIT_TAG "Boost_1_41_0"
CONFIGURE_COMMAND ""
BUILD_COMMAND bjam --with-regex toolset=gcc variant=debug link=static install --prefix=${CMAKE_CURRENT_BINARY_DIR}/boostinstall
BUILD_IN_SOURCE 1
INSTALL_COMMAND ""
)
set(Boost_INCLUDE_DIRS ${CMAKE_CURRENT_BINARY_DIR}/boostinstall/include)
set(Boost_LIBRARIES ${CMAKE_CURRENT_BINARY_DIR}/boostinstall/lib/libboost_regex.a)
# Configure app
include_directories(${Boost_INCLUDE_DIRS})
add_executable(regex regex.cpp)
add_dependencies(regex boost)
target_link_libraries(regex ${Boost_LIBRARIES})
#include "boost/regex.hpp"
#include "boost/version.hpp"
#include <iostream>
int main(int argc, char **argv) {
static const std::string regex("YOUR_REGEX");
static const std::string str("foo");
std::cerr << std::endl << "Boost Version = " << BOOST_VERSION << std::endl;
std::cerr << std::endl << "Regex = " << regex << std::endl;
std::cerr << std::endl << "Search string = " << str << std::endl << std::endl;
try {
static const boost::regex e(regex);
std::cerr << "Match result = " << boost::regex_match("foo", e ) << std::endl;
} catch (boost::regex_error const & ex) {
std::cerr << "exception = " << ex.what() << std::endl;
} catch (...) {
std::cerr << "unknown exception" << std::endl;
}
return 0;
}
@LeeRuns
Copy link

LeeRuns commented Nov 7, 2018

this is a flipping awesome example!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment