PageRenderTime 47ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/modules/matlab/compile.cmake

https://github.com/praveenkishor123/opencv
CMake | 49 lines | 29 code | 3 blank | 17 comment | 4 complexity | 388dd6f24b9cdb268d7a768e9eaada77 MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-3.0
  1. # LISTIFY
  2. # Given a string of space-delimited tokens, reparse as a string of
  3. # semi-colon delimited tokens, which in CMake land is exactly equivalent
  4. # to a list
  5. macro(listify OUT_LIST IN_STRING)
  6. string(REPLACE " " ";" ${OUT_LIST} ${IN_STRING})
  7. endmacro()
  8. # listify multiple-argument inputs
  9. listify(MEX_INCLUDE_DIRS_LIST ${MEX_INCLUDE_DIRS})
  10. if (${CONFIGURATION} MATCHES "Debug")
  11. listify(MEX_LIBS_LIST ${MEX_DEBUG_LIBS})
  12. else()
  13. listify(MEX_LIBS_LIST ${MEX_LIBS})
  14. endif()
  15. # if it's MSVC building a Debug configuration, don't build bindings
  16. if ("${CONFIGURATION}" MATCHES "Debug")
  17. message(STATUS "Matlab bindings are only available in Release configurations. Skipping...")
  18. return()
  19. endif()
  20. # -----------------------------------------------------------------------------
  21. # Compile
  22. # -----------------------------------------------------------------------------
  23. # for each generated source file:
  24. # 1. check if the file has already been compiled
  25. # 2. attempt compile if required
  26. # 3. if the compile fails, throw an error and cancel compilation
  27. file(GLOB SOURCE_FILES "${CMAKE_CURRENT_BINARY_DIR}/src/*.cpp")
  28. foreach(SOURCE_FILE ${SOURCE_FILES})
  29. # strip out the filename
  30. get_filename_component(FILENAME ${SOURCE_FILE} NAME_WE)
  31. # compile the source file using mex
  32. if (NOT EXISTS ${CMAKE_CURRENT_BINARY_DIR}/+cv/${FILENAME}.${MATLAB_MEXEXT})
  33. execute_process(
  34. COMMAND ${MATLAB_MEX_SCRIPT} ${MEX_OPTS} "CXXFLAGS=\$CXXFLAGS ${MEX_CXXFLAGS}" ${MEX_INCLUDE_DIRS_LIST}
  35. ${MEX_LIB_DIR} ${MEX_LIBS_LIST} ${SOURCE_FILE}
  36. WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/+cv
  37. OUTPUT_QUIET
  38. ERROR_VARIABLE FAILED
  39. )
  40. endif()
  41. # TODO: If a mex file fails to compile, should we error out?
  42. # TODO: Warnings are currently treated as errors...
  43. if (FAILED)
  44. message(FATAL_ERROR "Failed to compile ${FILENAME}: ${FAILED}")
  45. endif()
  46. endforeach()