Created
February 9, 2015 13:37
-
-
Save kwk/20a73f918e4c8b4bec7a to your computer and use it in GitHub Desktop.
Use boost from Git repo together with CMake External Project
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
this is a flipping awesome example!!!