Skip to content

Commit

Permalink
Refactor boost/test_package to make it pass on Linux
Browse files Browse the repository at this point in the history
Propagate Python version to the test scripts.
  • Loading branch information
klimkin committed Oct 28, 2020
1 parent b23563e commit 1c3384d
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 50 deletions.
86 changes: 39 additions & 47 deletions recipes/boost/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ cmake_minimum_required(VERSION 3.1)
project(test_package)
enable_testing()

set(Boost_DEBUG 1)
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)

if(CONAN_SETTINGS_OS STREQUAL "Android")
Expand All @@ -11,79 +10,72 @@ endif()

conan_basic_setup()

IF(NOT HEADER_ONLY)
if(NOT HEADER_ONLY)
set(boost_components)
if (WITH_COROUTINE)
if(WITH_COROUTINE)
list(APPEND boost_components coroutine)
list(APPEND boost_components thread)
endif()
if (WITH_PYTHON)
list(APPEND boost_components python)
if(WITH_PYTHON)
list(APPEND boost_components python${WITH_PYTHON_VERSION})
endif()
if (WITH_RANDOM)
if(WITH_RANDOM)
list(APPEND boost_components random)
endif()
if (WITH_REGEX)
if(WITH_REGEX)
list(APPEND boost_components regex)
endif()
if (WITH_CHRONO)
if(WITH_CHRONO)
list(APPEND boost_components chrono)
endif()
if(WITH_TEST)
list(APPEND boost_components unit_test_framework)
endif()

find_package(Boost COMPONENTS ${boost_components} REQUIRED)

include_directories(${Boost_INCLUDE_DIRS})

MESSAGE("LIBS=> ${CONAN_LIBS}")

if (WITH_RANDOM)
ADD_EXECUTABLE(random_exe random.cpp)
TARGET_LINK_LIBRARIES(random_exe ${Boost_LIBRARIES})
if(WITH_RANDOM)
add_executable(random_exe random.cpp)
target_link_libraries(random_exe Boost::random ${CONAN_SYSTEM_LIBS_BOOST})
endif()
if (WITH_REGEX)
ADD_EXECUTABLE(regex_exe regex.cpp)
TARGET_LINK_LIBRARIES(regex_exe ${Boost_LIBRARIES})

if(WITH_REGEX)
add_executable(regex_exe regex.cpp)
target_link_libraries(regex_exe Boost::regex ${CONAN_SYSTEM_LIBS_BOOST})
add_test(NAME TestRegex
COMMAND ${CMAKE_CROSSCOMPILING_EMULATOR} "$<TARGET_FILE:regex_exe>" ${TEST_ARGS})
endif()

if (WITH_TEST)
ADD_EXECUTABLE(test_exe test.cpp)
TARGET_LINK_LIBRARIES(test_exe ${CONAN_LIBS})
if(WITH_TEST)
add_executable(test_exe test.cpp)
target_link_libraries(test_exe Boost::unit_test_framework ${CONAN_SYSTEM_LIBS_BOOST})
endif()

if (WITH_COROUTINE)
ADD_EXECUTABLE(coroutine_exe coroutine.cpp)
TARGET_LINK_LIBRARIES(coroutine_exe ${Boost_LIBRARIES})
if(WITH_COROUTINE)
add_executable(coroutine_exe coroutine.cpp)
target_link_libraries(coroutine_exe Boost::coroutine Boost::thread ${CONAN_SYSTEM_LIBS_BOOST})
endif()

if (WITH_CHRONO)
ADD_EXECUTABLE(chrono_exe chrono.cpp)
TARGET_LINK_LIBRARIES(chrono_exe ${CONAN_LIBS})
if(WITH_CHRONO)
add_executable(chrono_exe chrono.cpp)
target_link_libraries(chrono_exe Boost::chrono ${CONAN_SYSTEM_LIBS_BOOST})
endif()

if(WITH_PYTHON)
find_package(Python ${WITH_PYTHON_VERSION} COMPONENTS Development REQUIRED)
target_link_libraries(Boost::python${WITH_PYTHON_VERSION} INTERFACE Python::Python)

add_library(hello_ext SHARED python.cpp)
target_link_libraries(hello_ext Boost::python${WITH_PYTHON_VERSION} ${CONAN_SYSTEM_LIBS_BOOST})
if(WIN32)
set_target_properties(hello_ext PROPERTIES SUFFIX ".pyd")
target_include_directories(hello_ext PRIVATE C:/Python27/include)
target_link_libraries(hello_ext C:/Python27/libs/python27.lib ${CONAN_LIBS})
else()
set_target_properties(hello_ext PROPERTIES PREFIX "")
endif()
endif()
endif()

if (WITH_REGEX)
ADD_TEST(NAME TestRegex
COMMAND ${CMAKE_CROSSCOMPILING_EMULATOR} "$<TARGET_FILE:regex_exe>")
endif()
ENDIF()

ADD_EXECUTABLE(lambda_exe lambda.cpp)

ADD_TEST(NAME TestLambda
COMMAND ${CMAKE_CROSSCOMPILING_EMULATOR} "$<TARGET_FILE:lambda_exe>" ${TEST_ARGS})

IF(NOT HEADER_ONLY AND WITH_REGEX)
# Test a different exe linking with the CONAN_LIBS to actually test the package_info
ADD_EXECUTABLE(newregex regex.cpp)
TARGET_LINK_LIBRARIES(newregex ${CONAN_LIBS})
ADD_TEST(NAME TestRegexNew
COMMAND ${CMAKE_CROSSCOMPILING_EMULATOR} "$<TARGET_FILE:newregex>" ${TEST_ARGS})
ENDIF()
add_executable(lambda_exe lambda.cpp)
target_link_libraries(lambda_exe ${CONAN_SYSTEM_LIBS_BOOST})
add_test(NAME TestLambda
COMMAND ${CMAKE_CROSSCOMPILING_EMULATOR} "$<TARGET_FILE:lambda_exe>" ${TEST_ARGS})
6 changes: 3 additions & 3 deletions recipes/boost/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def build(self):
cmake.definitions["Boost_USE_STATIC_LIBS"] = not self.options["boost"].shared
if not self.options["boost"].without_python:
cmake.definitions["WITH_PYTHON"] = "TRUE"
cmake.definitions["WITH_PYTHON_VERSION"] = self.options["boost"].python_version
if not self.options["boost"].without_random:
cmake.definitions["WITH_RANDOM"] = "TRUE"
if not self.options["boost"].without_regex:
Expand Down Expand Up @@ -47,7 +48,6 @@ def test(self):
if not self.options["boost"].without_chrono:
self.run(os.path.join("bin", "chrono_exe"), run_environment=True)
if not self.options["boost"].without_python:
os.chdir("bin")
sys.path.append(".")
sys.path.append("lib")
import hello_ext
hello_ext.greet()
print(hello_ext.greet())

0 comments on commit 1c3384d

Please sign in to comment.