Commit 1ce7e83b authored by Manuel Günther's avatar Manuel Günther
Browse files

Updated documentation

parent fb6a76d1
# author: Manuel Gunther <siebenkopf@googlemail.com>
# date: Wed May 25 10:55:42 MDT 2016
# license: BSD-3, see LICENSE file
cmake_minimum_required(VERSION 2.8)
project(test)
......
# author: Manuel Gunther <siebenkopf@googlemail.com>
# date: Wed May 25 10:55:42 MDT 2016
# license: BSD-3, see LICENSE file
#
# This file can be used to find Bob packages that provide a C++ interface.
# To find Bob libraries, use the CMake find_package command, and list all Bob packages as COMPONENTS, e.g.:
#
# - find_package(Bob COMPONENTS bob.io.base bob.learn.em REQUIRED)
#
# This will search recursively for all Bob packages (and its required Bob packages), which need to be installed beforehand, in this order:
#
# - installed (e.g. by using mr.developer) in the src directory
# - installed (e.g. by buildout) in the eggs directory
# - installed (e.g. via virtualenv) in the BOB_PREFIX_PATH (if given, either as an environment variable or as a CMake variable)
# - installed (e.g. via pip) in the system path
#
# After the successful run of find_package, these CMake variables will be filled:
#
# - Bob_INCLUDE_DIRS: The include directories of all required Bob packages, and their external requirements.
# Use e.g. include_directories(${Bob_INCLUDE_DIRS}) to add them
#
# - Bob_LIBRARY_DIRS: The library directories of all required Bob packages.
# Use e.g. link_directories(${Bob_LIBRARY_DIRS}) to add them
#
# - Bob_LIBRARIES: The C++ libraries of all required Bob packages.
# Use e.g. link_libraries(${Bob_LIBRARIES}) to add them
#
# - Bob_DEFINITIONS: The preprocessor defines required to build your package (already including the "-D").
# Use e.g. add_definitions(${Bob_DEFINITIONS}) to add them
# converts the given package name (including the dots) to a directory and to a variable usable by CMake
macro(_convert_package_to_string package)
string(REPLACE "." "_" PACKAGE_LIB "${package}")
string(REPLACE "." "/" PACKAGE_DIR "${package}")
string(TOUPPER "${PACKAGE_LIB}" PACKAGE)
endmacro()
# finds the python executable, which might be in ./bin, BOB_PREFIX_PATH/bin or in the system path
macro(_find_python)
if (NOT _python)
set(_possible_paths ${CMAKE_SOURCE_DIR}/bin)
......@@ -18,27 +50,28 @@ macro(_find_python)
endif()
endmacro()
# gets the list of external includes required by the Bob package
macro(_get_external_includes package)
_find_python()
execute_process(COMMAND ${_python} -c "exec(\"import ${package},sys\\nif hasattr(${package}, 'get_include_directories'): sys.stdout.write(';'.join(${package}.get_include_directories()))\")" OUTPUT_VARIABLE _external_includes)
endmacro()
macro(_get_external_macros package)
# gets the list of macros required by the Bob package
_find_python()
execute_process(COMMAND ${_python} -c "exec(\"import ${package},sys\\nif hasattr(${package}, 'get_macros'): sys.stdout.write(';'.join('-D%s=%s' % m for m in ${package}.get_macros()))\")" OUTPUT_VARIABLE _external_macros)
endmacro()
# recurses through the requirements and get all bob packages
macro(_recurse_requirements requirements)
# recurses through the requirements and get all bob packages
file(STRINGS ${requirements} _reqs)
# message(STATUS "Read requirements from '${requirements}' to '${_reqs}'")
#TODO: check requirements recursively
foreach (_req IN LISTS _reqs)
# check if string starts with bob
string(FIND ${_req} bob _pos)
if (NOT ${_pos} EQUAL -1)
# message(STATUS "Searching recursively for required Bob package ${_req}")
# find bob package recursively (will not run if pacakge was already found)
find_bob_package(${_req})
endif()
endforeach()
......@@ -59,7 +92,6 @@ function(find_bob_package package)
return()
endif()
# message(STATUS "\n")
message(STATUS "Searching for Bob package '${package}'")
# define possible path
......@@ -79,40 +111,36 @@ function(find_bob_package package)
list(APPEND _possible_paths $ENV{BOB_PREFIX_PATH}/lib/*/site-packages)
endif()
# message(STATUS "Possible paths are '${_possible_paths}'")
# add common path to locations
set(_bob_paths)
foreach(_path IN LISTS _possible_paths)
list(APPEND _bob_paths ${_path}/${PACKAGE_DIR})
endforeach()
# message(STATUS "Bob paths are '${_bob_paths}'")
# check if we find any bob directory
find_path(_package_dir
NAMES __init__.py
HINTS ${_bob_paths}
)
# message(STATUS "Package dir is '${_package_dir}'")
# assert that we have found the package
if (NOT _package_dir)
if (Bob_FIND_REQUIRED)
# if the package was required and we didn't find it, stop here
message(FATAL_ERROR "Could not find bob package '${package}'")
endif()
# otherwise, set the package to NOTFOUND and continue
set(${PACKAGE} ${PACKAGE}-NOTFOUND PARENT_SCOPE)
return()
endif()
set(${PACKAGE}_FOUND TRUE PARENT_SCOPE)
# first, parse the requirements
# TODO: get the requirements file;
# * either from the requirements.txt inside the ${_package_dir - ${PACKAGE_DIR}}
# * or from the requires.txt inside ${_package_dir - ${PACKAGE_DIR}}/${package}*.egg-info
# first, parse the requirements (requires.txt) from the requires.txt inside ${PACKAGE_BASE_DIR}/${package}*.egg-info or ${PACKAGE_BASE_DIR}/EGG-INFO
# get the base directory of the currently found package
string(FIND ${_package_dir} /${PACKAGE_DIR} _pos)
string(SUBSTRING ${_package_dir} 0 ${_pos} _base_dir)
# get the egg info directory (either in package-version.egg-info or in EGG-INFO)
file(GLOB _egg_info_dir ${_base_dir}/${package}*.egg-info ${_base_dir}/EGG-INFO)
find_file(
_requirements
......@@ -120,6 +148,7 @@ function(find_bob_package package)
HINTS ${_egg_info_dir}
NO_CMAKE_PATH
)
# parse the requirements and add packages recursively
if (_requirements)
set(_r ${_requirements})
unset(_requirements CACHE)
......@@ -135,10 +164,6 @@ function(find_bob_package package)
NAMES include
HINTS ${_package_dir}
)
# message(STATUS "Include dir is '${_include_dir}/include'")
# check if we have found an include directory
if (_include_dir)
list(APPEND Bob_INCLUDE_DIRS ${_include_dir}/include)
set(Bob_INCLUDE_DIRS ${Bob_INCLUDE_DIRS} PARENT_SCOPE)
......@@ -146,28 +171,22 @@ function(find_bob_package package)
# find external dependencies
_get_external_includes(${package})
# message(STATUS "External includes are '${_external_includes}'")
if (_external_includes)
list(APPEND Bob_INCLUDE_DIRS ${_external_includes})
set(Bob_INCLUDE_DIRS ${Bob_INCLUDE_DIRS} PARENT_SCOPE)
endif()
# find macros
_get_external_macros(${package})
# message(STATUS "External macros are '${_external_macros}'")
if (_external_includes)
list(APPEND Bob_DEFINITIONS ${_external_macros})
set(Bob_DEFINITIONS ${Bob_DEFINITIONS} PARENT_SCOPE)
endif()
# find library
find_library(_library
NAMES ${PACKAGE_LIB}
HINTS ${_package_dir}
)
# message(STATUS "Library is '${_library}'")
# check if we have found a library
if (_library)
set(Bob_LIBRARY_DIRS ${Bob_LIBRARY_DIRS} ${_package_dir} PARENT_SCOPE)
set(Bob_LIBRARIES ${Bob_LIBRARIES} ${PACKAGE_LIB} PARENT_SCOPE)
......@@ -187,11 +206,15 @@ if (NOT Bob_FIND_COMPONENTS)
message(FATAL_ERROR "Please specify the bob packages that you want to search for as COMPONENTS")
endif()
# TODO: Review this setting. It might overwrite some default settings.
set(CMAKE_CXX_FLAGS "-std=c++0x -pthread" CACHE STRING "Flags used by the compiler during release builds" FORCE)
# iterate over all COMPONENTS and add the packages
foreach (package IN LISTS Bob_FIND_COMPONENTS)
find_bob_package(${package})
endforeach()
# Some debug output; can be disabled if you are annoyed.
message(STATUS "Found Bob include directories '${Bob_INCLUDE_DIRS}'")
message(STATUS "Found Bob library directories '${Bob_LIBRARY_DIRS}'")
message(STATUS "Found Bob libraries '${Bob_LIBRARIES}'")
......
.. vim: set fileencoding=utf-8 :
.. Manuel Gunther <siebenkopf@googlemail.com>
.. Thu 30 Jan 08:46:53 2014 CET
.. Wed May 25 10:55:42 MDT 2016
.. image:: http://img.shields.io/badge/docs-stable-yellow.png
:target: http://pythonhosted.org/bob.example.cmake/index.html
.. image:: http://img.shields.io/badge/docs-latest-orange.png
:target: https://www.idiap.ch/software/bob/docs/latest/bioidiap/bob.example.cmake/master/index.html
.. image:: http://travis-ci.org/bioidiap/bob.example.cmake.svg?branch=master
:target: https://travis-ci.org/bioidiap/bob.example.cmake?branch=master
.. image:: https://img.shields.io/badge/github-master-0000c0.png
......
/**
* author: Manuel Gunther <siebenkopf@googlemail.com>
* date: Wed May 25 10:55:42 MDT 2016
* license: BSD-3, see LICENSE file
*
* This file shows an exemplary usage of the Bob C++ interface, and is just here for test purposes.
*/
// include some Bob header files
#include <bob.io.image/png.h>
#include <bob.io.base/HDF5File.h>
#include <iostream>
......
# author: Manuel Gunther <siebenkopf@googlemail.com>
# date: Wed May 25 10:55:42 MDT 2016
# license: BSD-3, see LICENSE file
def test_package():
# This function tests that the example actually runs
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment