Skip to content

Commit

Permalink
Add CMakeLists.txt for the entire project
Browse files Browse the repository at this point in the history
This commit add a CMakeLists allowing to easily
generate native makefile for the tests, exercises
and answers

This commit also update the README.md  and add test harness allowing
to easily run the smoke tests.

Note that currently only python2.7 us supported, to
be able to support python3, a top-level option
named "PYTHON_VERSION_MAJOR" could be introduced
with a default value of 2.
  • Loading branch information
jcfr committed Jul 8, 2014
1 parent bec2acc commit 605e9fa
Show file tree
Hide file tree
Showing 2 changed files with 159 additions and 1 deletion.
91 changes: 91 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
###########################################################################
#
# Copyright (c) Kitware Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0.txt
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# This file was originally developed by Jean-Christophe Fillion-Robin, Kitware Inc.
#
###########################################################################

cmake_minimum_required(VERSION 2.8.9)
project(SciPy2014BoostPython)

include(CTest)

#
# Dependencies
#
find_package(PythonLibs 2.7 REQUIRED)
include_directories(${PYTHON_INCLUDE_DIRS})

find_package(Boost COMPONENTS python REQUIRED)
include_directories(${Boost_INCLUDE_DIRS})

# Convenience function to configure python boost module
function(scipy_workshop_add_module libname sources)
add_library(${libname} MODULE ${sources})
target_link_libraries(${libname} ${PYTHON_LIBRARIES} ${Boost_LIBRARIES})
set_target_properties(${libname} PROPERTIES PREFIX "")
if(WIN32 AND NOT CYGWIN)
set_target_properties(${libname}PythonQt PROPERTIES SUFFIX ".pyd")
endif()
endfunction()

#
# CheckEnv
#
add_executable(plumbing_test exercises/plumbing_test.cpp)
target_link_libraries(plumbing_test ${PYTHON_LIBRARIES} ${Boost_LIBRARIES})

scipy_workshop_add_module(smoke_test exercises/smoke_test.cpp)
scipy_workshop_add_module(hello_world exercises/hello_world.cpp)

#
# CheckEnv tests
#
if(BUILD_TESTING)
find_package(PythonInterp 2.7 REQUIRED)

add_test(NAME plumbing_test COMMAND $<TARGET_FILE:plumbing_test>)
add_test(NAME smoke_test COMMAND ${PYTHON_EXECUTABLE} -c "import smoke_test; print(smoke_test.test())")
set_tests_properties(smoke_test PROPERTIES PASS_REGULAR_EXPRESSION "42")
endif()

#
# Exercises
#
scipy_workshop_add_module(exceptions exercises/exceptions/exceptions.cpp)
scipy_workshop_add_module(rps exercises/rps/rps.cpp)
scipy_workshop_add_module(call_policies exercises/call_policies/call_policies.cpp)

#
# Answers
#
scipy_workshop_add_module(exceptions_answer_01 answers/exceptions/exceptions.01.cpp)
scipy_workshop_add_module(exceptions_answer_02 answers/exceptions/exceptions.02.cpp)
scipy_workshop_add_module(exceptions_answer_03 answers/exceptions/exceptions.03.cpp)

foreach(id RANGE 1 16)
# XXX Pad with an extra zero
string(LENGTH "${id}" _id_len)
if(_id_len EQUAL 1)
set(id "0${id}")
endif()
scipy_workshop_add_module(rps_answer_${id} answers/rps/rps.${id}.cpp)
endforeach()

scipy_workshop_add_module(call_policies_answer_01 answers/call_policies/call_policies.01.cpp)
scipy_workshop_add_module(call_policies_answer_02 answers/call_policies/call_policies.02.cpp)


69 changes: 68 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,73 @@ Note that the Python executable may be `python3` or perhaps even `python2` depen
* On Ubuntu 14 (Trusty) the boost.python package you should install is libboost-python1.55-dev. This can make libraries for Python 2.7, 3.3, and 3.4.
* On Ubuntu 14 you may need to update the `PYTHON_EXTENSION_SUFFIX` in `make.common` to `.so` rather than relying on `python3-config`. This is because `python3-config --extension-suffix` reports `@SO@` rather than `.so` for some reason.


# Setting up the system for Linux, MacOSX or Windows using CMake

## Windows

* Download [Git](http://git-scm.com/download/win) and [CMake](http://www.cmake.org/files/v3.0/cmake-3.0.0-win32-x86.exe)

* Start Git Bash

```
git clone git://github.com/jcfr/scipy2014_boost_python_workshop_student_material.git
mkdir scipy2014_boost_python_workshop_student_material-build && cd $_
cmake -G "Visual Studio 10 2010" ../scipy2014_boost_python_workshop_student_material-build
cmake --build ../ --config Release
```

## Linux

```
sudo apt-get install cmake
sudo apt-get build-essentials
sudo apt-get install libpython-dev
sudo apt-get libboost1.54-dev
git clone git://github.com/jcfr/scipy2014_boost_python_workshop_student_material.git
mkdir scipy2014_boost_python_workshop_student_material-build && cd $_
cmake ../scipy2014_boost_python_workshop_student_material-build
make
```

## MacOSX

* Download [Git](http://git-scm.com/download/mac) and [CMake](http://www.cmake.org/files/v3.0/cmake-3.0.0-Darwin64-universal.dmg)

* Install Boost and Python

```
git clone git://github.com/jcfr/scipy2014_boost_python_workshop_student_material.git
mkdir scipy2014_boost_python_workshop_student_material-build && cd $_
cmake ../scipy2014_boost_python_workshop_student_material-build
make
```

## Running tests

In all three cases, convenience tests have been added and can easily be run:
```
$ cd scipy2014_boost_python_workshop_student_material-build
$ ctest -N
Test project [...]
Test #1: plumbing_test
Test #2: smoke_test
Total Tests: 2
$ ctest
Test project [...]
Start 1: plumbing_test
1/2 Test #1: plumbing_test .................... Passed 0.02 sec
Start 2: smoke_test
2/2 Test #2: smoke_test ....................... Passed 0.02 sec
100% tests passed, 0 tests failed out of 2
```

ProTips: Adding the -V option to ctest will disp


# Setting up a Mac OS X system #

There are a number of ways to set up a Mac OS X system, including compiling everything yourself, [homebrew](http://brew.sh/), and [macports](http://www.macports.org/). The homebrew approach is known to
Expand Down Expand Up @@ -145,4 +212,4 @@ Then in the directory `workshop/vs/BoostPythonWorkshop/Release`, check the two i
42
```

If this all works, then you're ready for the workshop.
If this all works, then you're ready for the workshop.

0 comments on commit 605e9fa

Please sign in to comment.