Skip to content

Commit

Permalink
examples: add build system
Browse files Browse the repository at this point in the history
  • Loading branch information
igchor committed Jun 15, 2018
1 parent bff15d4 commit 37ac027
Show file tree
Hide file tree
Showing 55 changed files with 360 additions and 1,116 deletions.
18 changes: 17 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,15 @@ function(join SEP OUT VALUES)
set(${OUT} "${JOIN_TMP}" PARENT_SCOPE)
endfunction()

# prepends prefix to list of strings
function(prepend var prefix)
set(listVar "")
foreach(f ${ARGN})
list(APPEND listVar "${prefix}/${f}")
endforeach(f)
set(${var} "${listVar}" PARENT_SCOPE)
endfunction()

# Checks whether flag is supported by current C++ compiler and appends
# it to the relevant cmake variable.
# 1st argument is a flag
Expand Down Expand Up @@ -264,6 +273,9 @@ endif(DEVELOPER_MODE)
install(DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
FILES_MATCHING PATTERN "*.hpp")

install(DIRECTORY examples/ DESTINATION ${CMAKE_INSTALL_DOCDIR}/examples
FILES_MATCHING PATTERN "*.*pp")

configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
Expand Down Expand Up @@ -343,4 +355,8 @@ if(BUILD_DOC)
add_subdirectory(doc)
endif()

#XXX: examples
if(BUILD_EXAMPLES AND NO_GCC_VARIADIC_TEMPLATE_BUG)
add_subdirectory(examples)
elseif(BUILD_EXAMPLES)
message(WARNING "Skipping build of examples because of compiler issue")
endif()
109 changes: 109 additions & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
#
# Copyright 2018, Intel Corporation
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
#
# * Neither the name of the copyright holder nor the names of its
# contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

include_directories(${PMEMOBJ_INCLUDE_DIRS} .)
link_directories(${PMEMOBJ_LIBRARY_DIRS})

add_cppstyle(examples-common ${CMAKE_CURRENT_SOURCE_DIR}/*.hpp)
add_check_whitespace(examples-common ${CMAKE_CURRENT_SOURCE_DIR}/*.hpp)

function(add_example name srcs)
prepend(srcs ${CMAKE_CURRENT_SOURCE_DIR} ${srcs})
add_executable(example-${name} ${srcs})
add_cppstyle(examples-${name} ${srcs})
add_check_whitespace(examples-${name} ${srcs})
endfunction()

if(PKG_CONFIG_FOUND)
pkg_check_modules(CURSES QUIET ncurses)
else()
# Specifies that we want FindCurses to find ncurses and not just any
# curses library
set(CURSES_NEED_NCURSES TRUE)
find_package(Curses QUIET)
endif()

if(PKG_CONFIG_FOUND)
pkg_check_modules(SFML QUIET sfml-all>=2.4)
else()
find_package(SFML 2.4 QUIET all)
endif()

add_example(queue queue/queue.cpp)
target_link_libraries(example-queue ${PMEMOBJ_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})

if(CURSES_FOUND)
add_example(pman pman/pman.cpp)
target_include_directories(example-pman PUBLIC ${CURSES_INCLUDE_DIR})
target_link_libraries(example-pman ${PMEMOBJ_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ${CURSES_LIBRARIES})
else()
message(WARNING "ncurses not found - pman won't be build")
endif()

if(SFML_FOUND)
add_example(pmpong pmpong/Ball.cpp pmpong/GameController.cpp pmpong/GameOverView.cpp
pmpong/GameView.cpp pmpong/MainGame.cpp pmpong/MenuView.cpp pmpong/Paddle.cpp
pmpong/PongGameStatus.cpp pmpong/Pool.cpp)
target_include_directories(example-pmpong PUBLIC ${SFML_INCLUDE_DIR})
target_link_libraries(example-pmpong ${PMEMOBJ_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ${SFML_LIBRARIES})

if(NOT WIN32)
execute_process(COMMAND uname -s OUTPUT_VARIABLE SYSTEM_TYPE)
if(SYSTEM_TYPE STREQUAL "FreeBSD")
set(FONTDIR "/usr/local/share/fonts")
else()
set(FONTDIR "/usr/share/fonts")
endif()
file(GLOB_RECURSE fonts ${FONTDIR}/*.ttf)
list(GET fonts 0 font)
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/fontConf ${font})
endif()
else()
message(WARNING "SFML 2.4 or newer not found - pmpong won't be build")
endif()

if(CURSES_FOUND)
add_example(panaconda panaconda/panaconda.cpp)
target_include_directories(example-panaconda PUBLIC ${CURSES_INCLUDE_DIR})
target_link_libraries(example-panaconda ${PMEMOBJ_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ${CURSES_LIBRARIES})
else()
message(WARNING "ncurses not found - panaconda won't be build")
endif()

add_example(map_cli map_cli/map_cli.cpp)
target_link_libraries(example-map_cli ${PMEMOBJ_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})

#XXX : fix compile error on clang
#add_library(doc_snippets_persistent OBJECT doc_snippets/persistent.cpp)
add_library(doc_snippets_make_persistent OBJECT doc_snippets/make_persistent.cpp)
add_library(doc_snippets_mutex OBJECT doc_snippets/mutex.cpp)
add_library(doc_snippets_pool OBJECT doc_snippets/pool.cpp)
add_library(doc_snippets_transaction OBJECT doc_snippets/transaction.cpp)
12 changes: 1 addition & 11 deletions examples/README
Original file line number Diff line number Diff line change
@@ -1,17 +1,7 @@
Persistent Memory Development Kit

This is examples/libpmemobj++/README.

This directory contains examples for libpmemobj++, the library providing
This directory contains examples for libpmemobj-cpp, the library providing
a transactional object store for pmem. Some of these examples are explained
in more detail here: http://pmem.io/pmdk/cpp_obj/

To build these examples:
make

These examples can be built against an installed system using:
make LIBDIR=/usr/lib INCDIR=/usr/include

If you're looking for documentation to get you started using PMDK,
start here: http://pmem.io/pmdk and follow the links to examples and
man pages.
69 changes: 0 additions & 69 deletions examples/doc_snippets/doc_snippets.vcxproj

This file was deleted.

26 changes: 0 additions & 26 deletions examples/doc_snippets/doc_snippets.vcxproj.filters

This file was deleted.

1 change: 0 additions & 1 deletion examples/map_cli/.gitignore

This file was deleted.

11 changes: 6 additions & 5 deletions examples/map_cli/ctree_map_persistent.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2017, Intel Corporation
* Copyright 2016-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
Expand Down Expand Up @@ -30,10 +30,10 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#ifndef EXAMPLES_CTREE_MAP_PERSISTENT_HPP
#define EXAMPLES_CTREE_MAP_PERSISTENT_HPP
#ifndef OBJCPP_EXAMPLES_CTREE_MAP_PERSISTENT_HPP
#define OBJCPP_EXAMPLES_CTREE_MAP_PERSISTENT_HPP

#include <cstdint>
#include <ex_common.h>
#include <functional>
#include <stdlib.h>

Expand All @@ -44,6 +44,7 @@
#include <libpmemobj++/pool.hpp>
#include <libpmemobj++/transaction.hpp>
#include <libpmemobj++/utils.hpp>
#include <objcpp_examples_common.hpp>

#define BIT_IS_SET(n, i) (!!((n) & (1ULL << (i))))

Expand Down Expand Up @@ -442,4 +443,4 @@ class ctree_map_p {

} /* namespace examples */

#endif /* EXAMPLES_CTREE_MAP_PERSISTENT_HPP */
#endif /* OBJCPP_EXAMPLES_CTREE_MAP_PERSISTENT_HPP */
11 changes: 6 additions & 5 deletions examples/map_cli/ctree_map_transient.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2017, Intel Corporation
* Copyright 2016-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
Expand Down Expand Up @@ -30,12 +30,13 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#ifndef EXAMPLES_CTREE_MAP_VOLATILE_HPP
#define EXAMPLES_CTREE_MAP_VOLATILE_HPP
#ifndef OBJCPP_EXAMPLES_CTREE_MAP_VOLATILE_HPP
#define OBJCPP_EXAMPLES_CTREE_MAP_VOLATILE_HPP

#include <cstdint>
#include <ex_common.h>
#include <functional>
#include <stdlib.h>
#include <objcpp_examples_common.hpp>
#ifdef _WIN32
#include <windows.h>
#endif
Expand Down Expand Up @@ -411,4 +412,4 @@ class ctree_map_transient {

} /* namespace examples */

#endif /* EXAMPLES_CTREE_MAP_VOLATILE_HPP */
#endif /* OBJCPP_EXAMPLES_CTREE_MAP_VOLATILE_HPP */
4 changes: 2 additions & 2 deletions examples/map_cli/map_cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#include "ctree_map_persistent.hpp"
#include "ctree_map_transient.hpp"
#include <ctree_map_persistent.hpp>
#include <ex_common.h>
#include <iostream>
#include <libpmemobj++/pool.hpp>
#include <memory>
#include <objcpp_examples_common.hpp>
#include <string.h>

namespace
Expand Down
Loading

0 comments on commit 37ac027

Please sign in to comment.