Skip to content

Commit

Permalink
Make building python bindings optional
Browse files Browse the repository at this point in the history
  • Loading branch information
tammojan committed May 6, 2020
1 parent c48f5a8 commit f984931
Showing 1 changed file with 37 additions and 34 deletions.
71 changes: 37 additions & 34 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ include_directories(${CASACORE_INCLUDE_DIR})

add_compile_options(-std=c++11 -Wall -DNDEBUG -Wl,--no-undefined)

option (BUILD_PYTHON "Build the python bindings" YES)

add_library(stationresponse SHARED
AntennaField.cc
AntennaFieldHBA.cc
Expand Down Expand Up @@ -65,37 +67,38 @@ elseif(DOXYGEN_FOUND)

endif(DOXYGEN_FOUND)

find_package (Python COMPONENTS Development)
message("Compiling Python ${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR} support. If this is not the intended target use 'DPYTHON_EXECUTABLE' to control.")
# bind against boost-python for compilation of the python API
# depending on major release version of the python libraries
if (${PYTHON_VERSION_MAJOR} VERSION_LESS "3")
find_package (Boost REQUIRED COMPONENTS python numpy)
find_package (Casacore REQUIRED COMPONENTS python)
message(STATUS "Boost python library: ${Boost_PYTHON_LIBRARY}")
message(STATUS "Boost numpy library: ${Boost_NUMPY_LIBRARY}")
message(STATUS "Python library ${PYTHON_LIBRARIES}")
set(BOOST_PY_FOUND TRUE)
else (${PYTHON_VERSION_MAJOR} VERSION_LESS "3")
find_package (Boost REQUIRED COMPONENTS python3 numpy3)
find_package (Casacore REQUIRED COMPONENTS python3)
message(STATUS "Boost python library: ${Boost_PYTHON3_LIBRARY}")
message(STATUS "Boost numpy library: ${Boost_NUMPY3_LIBRARY}")
message(STATUS "Python library ${PYTHON_LIBRARIES}")
set(BOOST_PY_FOUND TRUE)
endif (${PYTHON_VERSION_MAJOR} VERSION_LESS "3")


if(BOOST_PY_FOUND)
add_library(_stationresponse MODULE pystationresponse.cc)
set_target_properties(_stationresponse PROPERTIES PREFIX "")
target_include_directories(_stationresponse PRIVATE ${PYTHON_INCLUDE_DIR} ${Boost_INCLUDE_DIRS})
if (${PYTHON_VERSION_MAJOR} VERSION_LESS "3")
target_link_libraries(_stationresponse stationresponse ${CASA_PYTHON_LIBRARY} ${Boost_PYTHON_LIBRARY} ${Boost_NUMPY_LIBRARY} ${PYTHON_LIBRARIES})
else (${PYTHON_VERSION_MAJOR} VERSION_LESS "3")
target_link_libraries(_stationresponse stationresponse ${CASA_PYTHON3_LIBRARY} ${Boost_PYTHON3_LIBRARY} ${Boost_NUMPY3_LIBRARY} ${PYTHON_LIBRARIES})
endif (${PYTHON_VERSION_MAJOR} VERSION_LESS "3")
install(TARGETS _stationresponse DESTINATION ${PYTHON_INSTALL_DIR}/lofar/stationresponse)
install(FILES __init__.py DESTINATION ${PYTHON_INSTALL_DIR}/lofar/stationresponse)
endif(BOOST_PY_FOUND)

if (BUILD_PYTHON)
find_package (Python COMPONENTS Development)
message("Compiling Python ${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR} support. If this is not the intended target use 'DPYTHON_EXECUTABLE' to control.")
# bind against boost-python for compilation of the python API
# depending on major release version of the python libraries
if (${PYTHON_VERSION_MAJOR} VERSION_LESS "3")
find_package (Boost REQUIRED COMPONENTS python numpy)
find_package (Casacore REQUIRED COMPONENTS python)
message(STATUS "Boost python library: ${Boost_PYTHON_LIBRARY}")
message(STATUS "Boost numpy library: ${Boost_NUMPY_LIBRARY}")
message(STATUS "Python library ${PYTHON_LIBRARIES}")
set(BOOST_PY_FOUND TRUE)
else (${PYTHON_VERSION_MAJOR} VERSION_LESS "3")
find_package (Boost REQUIRED COMPONENTS python3 numpy3)
find_package (Casacore REQUIRED COMPONENTS python3)
message(STATUS "Boost python library: ${Boost_PYTHON3_LIBRARY}")
message(STATUS "Boost numpy library: ${Boost_NUMPY3_LIBRARY}")
message(STATUS "Python library ${PYTHON_LIBRARIES}")
set(BOOST_PY_FOUND TRUE)
endif (${PYTHON_VERSION_MAJOR} VERSION_LESS "3")


if(BOOST_PY_FOUND)
add_library(_stationresponse MODULE pystationresponse.cc)
set_target_properties(_stationresponse PROPERTIES PREFIX "")
target_include_directories(_stationresponse PRIVATE ${PYTHON_INCLUDE_DIR} ${Boost_INCLUDE_DIRS})
if (${PYTHON_VERSION_MAJOR} VERSION_LESS "3")
target_link_libraries(_stationresponse stationresponse ${CASA_PYTHON_LIBRARY} ${Boost_PYTHON_LIBRARY} ${Boost_NUMPY_LIBRARY} ${PYTHON_LIBRARIES})
else (${PYTHON_VERSION_MAJOR} VERSION_LESS "3")
target_link_libraries(_stationresponse stationresponse ${CASA_PYTHON3_LIBRARY} ${Boost_PYTHON3_LIBRARY} ${Boost_NUMPY3_LIBRARY} ${PYTHON_LIBRARIES})
endif (${PYTHON_VERSION_MAJOR} VERSION_LESS "3")
install(TARGETS _stationresponse DESTINATION ${PYTHON_INSTALL_DIR}/lofar/stationresponse)
install(FILES __init__.py DESTINATION ${PYTHON_INSTALL_DIR}/lofar/stationresponse)
endif(BOOST_PY_FOUND)
endif (BUILD_PYTHON)

0 comments on commit f984931

Please sign in to comment.