Skip to content
Snippets Groups Projects
CMakeLists.txt 5.36 KiB
Newer Older
###########################################################################
###########################################################################

###########################################################################
# Set local dependencies
###########################################################################
set ( old_boost ${Boost_LIBRARIES} )
set ( Boost_LIBRARIES ) # Empty out the variable after previous use
find_package ( BoostPython REQUIRED )
set ( Boost_LIBRARIES ${Boost_LIBRARIES} ${old_boost})

include_directories ( SYSTEM ${PYTHON_INCLUDE_PATH} )
include_directories ( SYSTEM ${PYTHON_NUMPY_INCLUDE_DIR} )

# Base of the subproject include dir
set ( HEADER_DIR ${CMAKE_CURRENT_SOURCE_DIR}/inc/MantidPythonInterface )
add_definitions ( -DBOOST_PYTHON_NO_LIB -DNPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION )
if ( CMAKE_COMPILER_IS_GNUCXX AND Boost_MAJOR_VERSION EQUAL "1" AND
     Boost_MINOR_VERSION GREATER "63" AND Boost_MINOR_VERSION LESS "66" )
  # Several bugs in boost 1.64-1.65 prevent python modues from loading on gcc without
  # this definition:   https://github.com/boostorg/python/issues/131
  add_definitions ( -DBOOST_PYTHON_USE_GCC_SYMBOL_VISIBILITY )
endif ()
set ( PYTHON_DEPS ${MPI_CXX_LIBRARIES} )
# First, common Python code
add_subdirectory ( core )

####################################################################################
# A function for generating the exports
#  - MODULE_TEMPLATE: The file containing the @EXPORT_FUNCTIONS@ and @EXPORT_DECLARE@ flags to replace
#  - OUTPUT_FILE: The path to the generated output file
#  - ... The list of export files
####################################################################################
function ( CREATE_MODULE MODULE_TEMPLATE OUTPUT_FILE )
  set ( _fwd_declarations )
  set ( _function_calls )
  foreach( _cppfile ${ARGN} )
    # pull out all functions named 'void export...'
    file ( STRINGS ${_cppfile} _definitions REGEX "( *)?void *export.*().*" )
    foreach ( _func_definition ${_definitions} )
      # create a forward declaration and function call
      string ( STRIP "${_func_definition}" _func_definition )
      string ( REGEX REPLACE "(void *export.*\\(\\)).*" "\\1" _func_declaration "${_func_definition}" )
      # add to list of declarations
      set ( _fwd_declarations "${_fwd_declarations}\n${_func_declaration}\;" )
      # strip void and add to call list
      string( REGEX REPLACE "void *" "" _func_call "${_func_declaration}" )
      set ( _function_calls "${_function_calls}\n${_func_call}\;" )
    endforeach ()
  endforeach ()
  string ( STRIP "${_fwd_declarations}" _fwd_declarations )
  string ( STRIP "${_function_calls}" _function_calls )
  set ( EXPORT_DECLARE ${_fwd_declarations} )
  set ( EXPORT_FUNCTIONS ${_function_calls} )

  configure_file( ${MODULE_TEMPLATE} ${OUTPUT_FILE} )

####################################################################################
# A function for setting the correct properties on the individual targets
####################################################################################
function ( SET_PYTHON_PROPERTIES TARGET TARGET_NAME )
  # No library prefixes
  set_target_properties( ${TARGET} PROPERTIES PREFIX "" )
  # Library name needs to end in .pyd for Windows
  if ( MSVC )
    set_target_properties ( ${TARGET} PROPERTIES SUFFIX .pyd
                            COMPILE_FLAGS "/bigobj /w44005 /w44244") # bigobj required for intensive templating
  elseif ( APPLE )
    # and in .so on the Mac
    set_target_properties ( ${TARGET} PROPERTIES SUFFIX .so )
  endif ()
  # Set the name
  set_target_properties ( ${TARGET} PROPERTIES OUTPUT_NAME ${TARGET_NAME} )
  # Debug python library expects imported module names to end in _d
  if ( PYTHON_DEBUG_LIBRARY )
    set_target_properties ( ${TARGET} PROPERTIES DEBUG_OUTPUT_NAME ${TARGET_NAME}_d )
  endif ()
  # Group within VS
  set_property ( TARGET ${TARGET} PROPERTY FOLDER "MantidFramework/Python" )
###########################################################################
# mantid package
###########################################################################
# All targets can see these includes
include_directories ( core/inc )
# TODO: Move all common code to the core library to
# remove the need for linking submodules together
include_directories ( inc )
###########################################################################
# Python algorithms
###########################################################################
clean_orphaned_pyc_files ( ${CMAKE_CURRENT_SOURCE_DIR}/plugins )
###########################################################################
###########################################################################
set ( PYTHONINTERFACE_PLUGINS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/plugins )
###########################################################################
# Installation settings
###########################################################################

install ( DIRECTORY plugins/ DESTINATION ${PLUGINS_DIR}/python
          PATTERN "*.pyc" EXCLUDE
          PATTERN ".svn" EXCLUDE )

install ( DIRECTORY plugins/ DESTINATION ${WORKBENCH_PLUGINS_DIR}/python
          PATTERN "*.pyc" EXCLUDE
          PATTERN ".svn" EXCLUDE )