Imported Upstream version 1.72.0
[platform/upstream/boost.git] / tools / boost_install / test / python / CMakeLists.txt
1 # Copyright 2018, 2019 Peter Dimov
2 # Distributed under the Boost Software License, Version 1.0.
3 # (See accompanying file LICENSE_1_0.txt or copy at http://boost.org/LICENSE_1_0.txt)
4
5 cmake_minimum_required(VERSION 3.5)
6
7 if(POLICY CMP0074)
8   cmake_policy(SET CMP0074 NEW)
9 endif()
10
11 project(CmakeConfigPythonTest LANGUAGES CXX)
12
13 include(${CMAKE_CURRENT_LIST_DIR}/../BoostVersion.cmake)
14
15 find_package(PythonLibs 2.7 REQUIRED)
16
17 set(BOOST_HINTS)
18
19 if(USE_STAGED_BOOST)
20   set(BOOST_HINTS HINTS ../../../../stage)
21 endif()
22
23 set(component python)
24
25 if(USE_BOOST_PACKAGE)
26
27   # test the versioned pythonXY component for backward compatibility
28
29   string(REPLACE "." ";" PYTHONLIBS_VERSION_LIST ${PYTHONLIBS_VERSION_STRING})
30
31   list(GET PYTHONLIBS_VERSION_LIST 0 PYTHONLIBS_VERSION_MAJOR)
32   list(GET PYTHONLIBS_VERSION_LIST 1 PYTHONLIBS_VERSION_MINOR)
33
34   set(component python${PYTHONLIBS_VERSION_MAJOR}${PYTHONLIBS_VERSION_MINOR})
35
36   find_package(Boost ${BOOST_VERSION} EXACT REQUIRED COMPONENTS ${component} ${BOOST_HINTS})
37
38 else()
39
40   # use the found Python version in case more than one Boost.Python is installed
41   set(Boost_PYTHON_VERSION ${PYTHONLIBS_VERSION_STRING})
42
43   find_package(boost_python ${BOOST_VERSION} EXACT CONFIG REQUIRED ${BOOST_HINTS})
44
45 endif()
46
47 add_executable(main quick.cpp)
48 target_link_libraries(main Boost::${component} ${PYTHON_LIBRARIES})
49 target_include_directories(main PRIVATE ${PYTHON_INCLUDE_DIRS})
50
51 enable_testing()
52 add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure -C $<CONFIG>)
53
54 add_test(main main)