From ae87734faf10a39eff0369709b814c33debd7884 Mon Sep 17 00:00:00 2001 From: Roberto Di Remigio Date: Tue, 13 Oct 2015 10:26:16 +0200 Subject: [PATCH] Streamline Boost tests for compiled libraries and add documentation on Boost module usage --- modules/boost/boost.cmake | 16 ++++++++- test/boost_libs/cmake/autocmake.cfg | 11 ++++++- test/boost_libs/src/CMakeLists.txt | 9 ++--- test/boost_libs/src/example.cpp | 31 ++++++++++++++---- test/boost_mpi_libs/cmake/autocmake.cfg | 19 ----------- test/boost_mpi_libs/src/CMakeLists.txt | 7 ---- test/boost_mpi_libs/src/example.cpp | 26 --------------- test/boost_python_libs/cmake/autocmake.cfg | 22 ------------- test/boost_python_libs/src/CMakeLists.txt | 7 ---- test/boost_python_libs/src/example.cpp | 38 ---------------------- test/test.py | 10 +----- 11 files changed, 52 insertions(+), 144 deletions(-) delete mode 100644 test/boost_mpi_libs/cmake/autocmake.cfg delete mode 100644 test/boost_mpi_libs/src/CMakeLists.txt delete mode 100644 test/boost_mpi_libs/src/example.cpp delete mode 100644 test/boost_python_libs/cmake/autocmake.cfg delete mode 100644 test/boost_python_libs/src/CMakeLists.txt delete mode 100644 test/boost_python_libs/src/example.cpp diff --git a/modules/boost/boost.cmake b/modules/boost/boost.cmake index 966a768..8a83c58 100644 --- a/modules/boost/boost.cmake +++ b/modules/boost/boost.cmake @@ -1,7 +1,7 @@ #.rst: # # Detect, build, and link Boost libraries. -# This modules downloads the .zip archive from SourceForge +# This modules downloads the .zip archive from SourceForge at # Autocmake update time. # # Your autocmake.cfg should look like this:: @@ -13,6 +13,19 @@ # Cross-dependencies between required components are not checked for. # For example, Boost.Timer depends on Boost.Chrono and Boost.System thus you # should ask explicitly for all three. +# If the self-build of Boost components is triggered the `BUILD_CUSTOM_BOOST` variable is set +# to `TRUE`. The CMake target `custom_boost` is also added. +# You should use these two to ensure the right dependencies between your targets +# and the Boost headers/libraries, in case the self-build is triggered. +# For example:: +# +# if(BUILD_CUSTOM_BOOST) +# add_dependencies(your_target custom_boost) +# endif() +# +# will ensure that `your_target` is built after `custom_boost` if and only if the self-build +# of Boost took place. This is an important step to avoid race conditions when building +# on multiple processes. # # Dependencies:: # @@ -27,6 +40,7 @@ # PROJECT_BINARY_DIR # CMAKE_BUILD_TYPE # MPI_FOUND +# BUILD_CUSTOM_BOOST # # autocmake.cfg configuration:: # diff --git a/test/boost_libs/cmake/autocmake.cfg b/test/boost_libs/cmake/autocmake.cfg index 9ff39de..02d73b0 100644 --- a/test/boost_libs/cmake/autocmake.cfg +++ b/test/boost_libs/cmake/autocmake.cfg @@ -5,8 +5,17 @@ min_cmake_version: 2.8 [cxx] source: ../../../modules/cxx.cmake +[mpi] +source: ../../../modules/mpi.cmake + +[python_interpreter] +source: ../../../modules/python_interpreter.cmake + +[python_libs] +source: ../../../modules/python_libs.cmake + [boost] -override: {'major': 1, 'minor': 59, 'patch': 0, 'components': 'chrono;timer;system'} +override: {'major': 1, 'minor': 59, 'patch': 0, 'components': 'mpi;serialization;python'} source: ../../../modules/boost/boost.cmake [default_build_paths] diff --git a/test/boost_libs/src/CMakeLists.txt b/test/boost_libs/src/CMakeLists.txt index e038c8e..791ed78 100644 --- a/test/boost_libs/src/CMakeLists.txt +++ b/test/boost_libs/src/CMakeLists.txt @@ -4,10 +4,5 @@ if(BUILD_CUSTOM_BOOST) add_dependencies(example custom_boost) endif() -set(_libs ${Boost_TIMER_LIBRARY} ${Boost_CHRONO_LIBRARY} ${Boost_SYSTEM_LIBRARY}) - -if(NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin") - set(_libs ${_libs} rt) -endif() - -target_link_libraries(example ${_libs}) +target_link_libraries(example ${Boost_MPI_LIBRARY} ${Boost_SERIALIZATION_LIBRARY} ${MPI_CXX_LIBRARIES} + ${Boost_PYTHON_LIBRARY} ${PYTHON_LIBRARIES}) diff --git a/test/boost_libs/src/example.cpp b/test/boost_libs/src/example.cpp index 1ba3da3..b5fe3cc 100644 --- a/test/boost_libs/src/example.cpp +++ b/test/boost_libs/src/example.cpp @@ -1,13 +1,14 @@ -#include #include -#include -#include +#include +#include +#include #include int main() { - boost::timer::auto_cpu_timer t; + using namespace boost::python; + namespace mpi = boost::mpi; std::cout << "Boost version: " << BOOST_VERSION / 100000 @@ -17,10 +18,26 @@ int main() << BOOST_VERSION % 100 << std::endl; + try { + Py_Initialize(); - std::cout << "Measuring some timings..." << std::endl; - for (long i = 0; i < 100000000; ++i) - std::sqrt(123.456L); // burn some time + object main_module(( + handle<>(borrowed(PyImport_AddModule("__main__"))))); + + object main_namespace = main_module.attr("__dict__"); + + handle<> ignored(( PyRun_String( "print \"Hello, World\"", + Py_file_input, + main_namespace.ptr(), + main_namespace.ptr() ) )); + } catch( error_already_set ) { + PyErr_Print(); + } + + mpi::environment env; + mpi::communicator world; + std::cout << "I am process " << world.rank() << " of " << world.size() + << "." << std::endl; std::cout << "PASSED" << std::endl; diff --git a/test/boost_mpi_libs/cmake/autocmake.cfg b/test/boost_mpi_libs/cmake/autocmake.cfg deleted file mode 100644 index 4847c0d..0000000 --- a/test/boost_mpi_libs/cmake/autocmake.cfg +++ /dev/null @@ -1,19 +0,0 @@ -[project] -name: example -min_cmake_version: 2.8 - -[cxx] -source: ../../../modules/cxx.cmake - -[mpi] -source: ../../../modules/mpi.cmake - -[boost] -override: {'major': 1, 'minor': 59, 'patch': 0, 'components': 'mpi;serialization'} -source: ../../../modules/boost/boost.cmake - -[default_build_paths] -source: ../../../modules/default_build_paths.cmake - -[src] -source: ../../../modules/src.cmake diff --git a/test/boost_mpi_libs/src/CMakeLists.txt b/test/boost_mpi_libs/src/CMakeLists.txt deleted file mode 100644 index fc63d15..0000000 --- a/test/boost_mpi_libs/src/CMakeLists.txt +++ /dev/null @@ -1,7 +0,0 @@ -add_executable(example example.cpp) - -if(BUILD_CUSTOM_BOOST) - add_dependencies(example custom_boost) -endif() - -target_link_libraries(example ${Boost_MPI_LIBRARY} ${Boost_SERIALIZATION_LIBRARY} ${MPI_CXX_LIBRARIES}) diff --git a/test/boost_mpi_libs/src/example.cpp b/test/boost_mpi_libs/src/example.cpp deleted file mode 100644 index 0829ad1..0000000 --- a/test/boost_mpi_libs/src/example.cpp +++ /dev/null @@ -1,26 +0,0 @@ -#include - -#include -#include -#include - -int main() -{ - namespace mpi = boost::mpi; - std::cout << "Boost version: " - << BOOST_VERSION / 100000 - << "." - << BOOST_VERSION / 100 % 1000 - << "." - << BOOST_VERSION % 100 - << std::endl; - - mpi::environment env; - mpi::communicator world; - std::cout << "I am process " << world.rank() << " of " << world.size() - << "." << std::endl; - - std::cout << "PASSED" << std::endl; - - return 0; -} diff --git a/test/boost_python_libs/cmake/autocmake.cfg b/test/boost_python_libs/cmake/autocmake.cfg deleted file mode 100644 index 6f9a212..0000000 --- a/test/boost_python_libs/cmake/autocmake.cfg +++ /dev/null @@ -1,22 +0,0 @@ -[project] -name: example -min_cmake_version: 2.8 - -[cxx] -source: ../../../modules/cxx.cmake - -[python_interpreter] -source: ../../../modules/python_interpreter.cmake - -[python_libs] -source: ../../../modules/python_libs.cmake - -[boost] -override: {'major': 1, 'minor': 56, 'patch': 0, 'components': 'python'} -source: ../../../modules/boost/boost.cmake - -[default_build_paths] -source: ../../../modules/default_build_paths.cmake - -[src] -source: ../../../modules/src.cmake diff --git a/test/boost_python_libs/src/CMakeLists.txt b/test/boost_python_libs/src/CMakeLists.txt deleted file mode 100644 index 23a33db..0000000 --- a/test/boost_python_libs/src/CMakeLists.txt +++ /dev/null @@ -1,7 +0,0 @@ -add_executable(example example.cpp) - -if(BUILD_CUSTOM_BOOST) - add_dependencies(example custom_boost) -endif() - -target_link_libraries(example ${Boost_PYTHON_LIBRARY} ${PYTHON_LIBRARIES}) diff --git a/test/boost_python_libs/src/example.cpp b/test/boost_python_libs/src/example.cpp deleted file mode 100644 index 979c04b..0000000 --- a/test/boost_python_libs/src/example.cpp +++ /dev/null @@ -1,38 +0,0 @@ -#include - -#include -#include - -int main() -{ - using namespace boost::python; - - std::cout << "Boost version: " - << BOOST_VERSION / 100000 - << "." - << BOOST_VERSION / 100 % 1000 - << "." - << BOOST_VERSION % 100 - << std::endl; - - try { - Py_Initialize(); - - object main_module(( - handle<>(borrowed(PyImport_AddModule("__main__"))))); - - object main_namespace = main_module.attr("__dict__"); - - handle<> ignored(( PyRun_String( "print \"Hello, World\"", - Py_file_input, - main_namespace.ptr(), - main_namespace.ptr() ) )); - } catch( error_already_set ) { - PyErr_Print(); - } - - - std::cout << "PASSED" << std::endl; - - return 0; -} diff --git a/test/test.py b/test/test.py index 438b017..b973cd5 100644 --- a/test/test.py +++ b/test/test.py @@ -175,12 +175,4 @@ def test_boost_header_only(): def test_boost_libs(): - configure_build_and_exe('boost_libs', 'python setup --cxx=g++') - - -def test_boost_mpi_libs(): - configure_build_and_exe('boost_mpi_libs', 'python setup --cxx=g++ --mpi') - - -def test_boost_python_libs(): - configure_build_and_exe('boost_python_libs', 'python setup --cxx=g++') + configure_build_and_exe('boost_libs', 'python setup --cxx=g++ --mpi')