Skip to content

Commit

Permalink
Added CMake options for building examples
Browse files Browse the repository at this point in the history
  • Loading branch information
gtremper committed Jul 30, 2014
1 parent 7331f82 commit 8f5c842
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 12 deletions.
11 changes: 10 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,17 @@ include(CMakeModules/pch.cmake)
get_filename_component(AUTOWIRING_ROOT_DIR . ABSOLUTE)
if(CMAKE_SOURCE_DIR STREQUAL AUTOWIRING_ROOT_DIR)
set(AUTOWIRING_BUILD_TESTS_DEFAULT ON)
set(AUTOWIRING_BUILD_EXAMPLES_DEFAULT ON)
set(AUTOWIRING_BUILD_AUTONET_DEFAULT ON)

# All of our binaries go to one place: The binaries output directory. We only want to tinker
# with this if we're building by ourselves, otherwise we just do whatever the enclosing project
# wants us to do.
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
else()
set(AUTOWIRING_BUILD_TESTS_DEFAULT OFF)
set(AUTOWIRING_BUILD_EXAMPLES_DEFAULT OFF)
set(AUTOWIRING_BUILD_AUTONET_DEFAULT OFF)
endif()

option(AUTOWIRING_BUILD_TESTS "Build Autowiring unit tests" ${AUTOWIRING_BUILD_TESTS_DEFAULT})
Expand All @@ -53,8 +57,13 @@ include_directories(
)
add_subdirectory(src)
add_subdirectory(contrib)
add_subdirectory(examples)
# Build examples
option(AUTOWIRING_BUILD_EXAMPLES "Build Autowiring examples" ${AUTOWIRING_BUILD_EXAMPLES_DEFAULT})
if(AUTOWIRING_BUILD_EXAMPLES)
add_subdirectory(examples)
endif()

# CMake configurations
configure_file(autowiring-config.cmake.in autowiring-config.cmake @ONLY)
configure_file(autowiring-configVersion.cmake.in autowiring-configVersion.cmake @ONLY)

Expand Down
4 changes: 3 additions & 1 deletion examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@

add_executable(ContextExample ContextExample.cpp)
target_link_libraries(ContextExample Autowiring)
set_property(TARGET ContextExample PROPERTY FOLDER "Examples")
55 changes: 45 additions & 10 deletions examples/ContextExample.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,54 @@
#include <autowiring/Autowired.h>
#include <iostream>
#include <cassert>
#include <memory>

int main() {
// The CoreContext is the basic unit of organization. They are organized
// in a tree structure, the root of which is the GlobalCoreContext. Each
// thread keeps track of its current context, which defaults to
// GlobalCoreContext
// pretty print boolean with desciption
#define check(desc,val) std::cout << desc << (val ? ": True" : ": False") << std::endl

// This creates a shared_ptr to the global context
AutoGlobalContext global;
int main() {
///////////////////////////
//// GlobalCoreContext ////
///////////////////////////
{
// The CoreContext is the basic unit of organization. They are organized
// in a tree structure, the root of which is the GlobalCoreContext. Each
// thread keeps track of its current context, which defaults to
// GlobalCoreContext

// This creates a shared_ptr to the global context
AutoGlobalContext global;

// This is the a shared_ptr to the current context
AutoCurrentContext ctxt;

// Since we default to the current context, they should be the same
check("Current context is global", global==ctxt);
}

// This is the a shared_ptr to the current context
AutoCurrentContext ctxt;
/////////////////////////////////////////////////
//// Context Creation and Switching Contexts ////
/////////////////////////////////////////////////
{
// New contexts can be created using the 'Create' factory method on a context.
// The factory will create a child context to 'this' contxt

AutoGlobalContext global; //same as AutoCurrentContext

assert(global == ctxt)
// Create's a chile of the current context
AutoCreateContext childCtxt; // Same as childCtxt = global->Create<void>();

// Even though we've created a child context, we're still in the global context
check("Are we in the GlobalCoreContext", AutoCurrentContext()->IsGlobalContext());

// CurrentContextPusher can be used to switch contexts using RAII patterns
{
CurrentContextPusher pshr(childCtxt);
check("Now in child context", AutoCurrentContext() == childCtxt);
}
// Back in global context
}



}
5 changes: 5 additions & 0 deletions src/autonet/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ if(NOT Boost_FOUND)
return()
endif()

option(AUTOWIRING_BUILD_AUTONET "Build Autonet debugging server" ${AUTOWIRING_BUILD_AUTONET_DEFAULT})
if(NOT AUTOWIRING_BUILD_AUTONET)
return()
endif()

add_googletest(test)
include_directories(
${Boost_INCLUDE_DIR}
Expand Down

0 comments on commit 8f5c842

Please sign in to comment.