ENDMACRO(OMNIORB_COMPILE_IDL_FORPYTHON_ON_INSTALL)
")
-# This MACRO uses the following vars
-# - OMNIORB_IDL : the idl tool (given by default by FindOMNIORB.cmake)
-# - OMNIORB_IDLCXXFLAGS : the options (include excluded) to give to omniidl generator (given by default by FindOMNIORB.cmake)
+#----------------------------------------------------------------------------
+# OMNIORB_ADD_MODULE macro: generate CORBA wrappings for a module.
#
-# MYMODULE is a string that will be used to create a target with sources containing *.cc coming from the compilation of ${MYIDLFILES}
-# MYIDLFILES containing all idl files to be compiled.
-# MYIDLCXXFLAGS containing all directories (only directories) where to find *.idl which depend ${MYIDLFILES}.
-# TYPE contains type of the library
-MACRO(OMNIORB_ADD_MODULE MYMODULE MYIDLFILES MYIDLCXXFLAGS TYPE)
- SET(MYSOURCES)
- FOREACH(input ${MYIDLFILES})
- GET_FILENAME_COMPONENT(base ${input} NAME_WE)
-# STRING(REGEX REPLACE ".idl" "" base ${input})
- SET(OMNIORB_IDLCXXFLAGS2 "${OMNIORB_IDLCXXFLAGS}")
- SET(src ${CMAKE_CURRENT_BINARY_DIR}/${base}SK.cc)
- SET(MYSOURCES ${MYSOURCES} ${src})
- SET(outputs ${src})
- SET(dynsrc ${CMAKE_CURRENT_BINARY_DIR}/${base}DynSK.cc)
- SET(MYSOURCES ${MYSOURCES} ${dynsrc})
- SET(outputs ${outputs} ${dynsrc})
- SET(inc ${CMAKE_CURRENT_BINARY_DIR}/${base}.hh)
- SET(outputs ${outputs} ${inc})
- GET_FILENAME_COMPONENT(path ${input} PATH)
- IF(NOT path)
- SET(input ${CMAKE_CURRENT_SOURCE_DIR}/${input})
- ENDIF(NOT path)
- SET(flags ${OMNIORB_IDLCXXFLAGS2})
- STRING(REGEX MATCH "-bcxx" ISBCXX ${flags})
- IF(NOT ISBCXX)
- SET(flags -bcxx ${flags})
- ENDIF(NOT ISBCXX)
- FOREACH(f ${MYIDLCXXFLAGS})
- SET(flags ${flags} "-I${f}")
- ENDFOREACH(f ${MYIDLCXXFLAGS})
- ADD_CUSTOM_COMMAND(OUTPUT ${outputs}
- COMMAND ${OMNIORB_IDL_COMPILER} ${flags} ${input}
- MAIN_DEPENDENCY ${input})
- SET(IDLPYFLAGS ${flags})
- INSTALL(FILES ${input} DESTINATION idl/salome)
- SET(IDL_HEADER ${CMAKE_CURRENT_BINARY_DIR}/${base}.hh)
- INSTALL(FILES ${IDL_HEADER} DESTINATION include/salome)
- SET(flags)
- FOREACH(f ${MYIDLCXXFLAGS})
- SET(flags "${flags} -I${f}")
- ENDFOREACH(f ${MYIDLCXXFLAGS})
- STRING(REGEX MATCH "-bpython" ISBPYTHON ${flags})
- IF(NOT ISBPYTHON)
- SET(flags "-bpython ${flags}")
- ENDIF(NOT ISBPYTHON)
- SET(IDLPYFLAGS ${flags})
- STRING(REPLACE "\\" "/" IDLPYFLAGS ${IDLPYFLAGS})
+# USAGE: OMNIORB_ADD_MODULE(module idlfiles incdirs [linklibs])
+#
+# ARGUMENTS:
+# module : module name
+# idlfiles : list of IDL files to be compiled into module
+# incdirs : additional include dirs for IDL staff
+# linklibs : additional libraries the module to be linked to (optional)
+#
+# For example, to build CORBA staff from MyModule.idl for module MyModule
+# (that depends only on SALOME KERNEL interfaces), use the following code:
+#
+# INCLUDE(UseOmniORB)
+# INCLUDE_DIRECTORIES(${OMNIORB_INCLUDE_DIR} ${KERNEL_INCLUDE_DIRS})
+# OMNIORB_ADD_MODULE(SalomeIDLMyModule MyModule.idl ${KERNEL_ROOT_DIR}/idl/salome ${KERNEL_SalomeIDLKernel})
+# INSTALL(TARGETS SalomeIDLMyModule EXPORT ${PROJECT_NAME}TargetGroup DESTINATION ${SALOME_INSTALL_LIBS})
+#
+# This macro uses the following variables:
+# - From FindOmniORB.cmake
+# OMNIORB_IDL : the path to the omniidl tool
+# OMNIORB_IDLCXXFLAGS : the options to give to omniidl generator for C++ backend
+# OMNIORB_DEFINITIONS : additional compile options for C++
+# - From FindOmniORBPy.cmake
+# OMNIORB_IDLPYFLAGS : the options to give to omniidl generator for Python backend
+# OMNIORB_PYTHON_BACKEND : Python backend
+#
+# TODO:
+# 1. Replace hardcoded dirpaths bin/salome, idl/salome, etc by corresponding configuration options.
+# 2. Revise/improve OMNIORB_COMPILE_IDL_FORPYTHON_ON_INSTALL macro usage.
+# 3. Add proper handling of INCLUDE_DIRECTORIES to minimize this macro usage in target CMakeLists.txt files.
+#
+#----------------------------------------------------------------------------
+MACRO(OMNIORB_ADD_MODULE module idlfiles incdirs)
+ # process additional libraries the module to be linked to
+ SET(_linklibs ${OMNIORB_LIBRARIES})
+ FOREACH(_arg ${ARGN})
+ SET(_linklibs ${_linklibs} ${_arg})
+ ENDFOREACH()
+
+ # module sources
+ SET(_sources)
+ # type of the libraries: SHARED for Linux, STATIC for Windows
+ SET(_type SHARED)
+ IF(WINDOWS)
+ SET(_type STATIC)
+ ENDIF()
+ # add additional include dirs to the C++ and Python backend options
+ SET(_cxx_flags ${OMNIORB_IDLCXXFLAGS})
+ SET(_py_flags "${OMNIORB_IDLPYFLAGS}")
+ FOREACH(_f ${incdirs})
+ LIST(APPEND _cxx_flags "-I${_f}")
+ LIST(APPEND _py_flags "-I${_f}")
+ ENDFOREACH()
+
+ FOREACH(_input ${idlfiles})
+ GET_FILENAME_COMPONENT(_base ${_input} NAME_WE)
+ GET_FILENAME_COMPONENT(_path ${_input} PATH)
+ IF(NOT _path)
+ SET(_input ${CMAKE_CURRENT_SOURCE_DIR}/${_input})
+ ENDIF()
+
+ SET(_inc ${CMAKE_CURRENT_BINARY_DIR}/${_base}.hh)
+ SET(_src ${CMAKE_CURRENT_BINARY_DIR}/${_base}SK.cc)
+ SET(_dynsrc ${CMAKE_CURRENT_BINARY_DIR}/${_base}DynSK.cc)
+
+ LIST(APPEND _sources ${_src})
+ LIST(APPEND _sources ${_dynsrc})
+ SET(_outputs ${_inc} ${_src} ${_dynsrc})
+
+ ADD_CUSTOM_COMMAND(OUTPUT ${_outputs}
+ COMMAND ${OMNIORB_IDL_COMPILER} ${_cxx_flags} ${_input}
+ MAIN_DEPENDENCY ${_input})
+
+ INSTALL(FILES ${_input} DESTINATION idl/salome)
+ INSTALL(FILES ${_inc} DESTINATION include/salome)
+
IF(OMNIORB_PYTHON_BACKEND)
- SET(IDLPYFLAGS "${IDLPYFLAGS} -p${OMNIORB_PYTHON_BACKEND}")
- INSTALL(CODE "OMNIORB_COMPILE_IDL_FORPYTHON_ON_INSTALL( \"${OMNIORB_IDL_COMPILER}\" \"${IDLPYFLAGS}\" \"${input}\" \"${CMAKE_INSTALL_PREFIX}/\${INSTALL_PYIDL_DIR}\" )")
- ENDIF(OMNIORB_PYTHON_BACKEND)
- ENDFOREACH(input ${MYIDLFILES})
- ADD_LIBRARY(${MYMODULE} ${TYPE} ${MYSOURCES})
+ STRING(REPLACE ";" " " _tmp "${_py_flags}")
+ INSTALL(CODE "OMNIORB_COMPILE_IDL_FORPYTHON_ON_INSTALL( \"${OMNIORB_IDL_COMPILER}\" \"${_tmp}\" \"${_input}\" \"${CMAKE_INSTALL_PREFIX}/\${INSTALL_PYIDL_DIR}\" )")
+ ENDIF()
+ ENDFOREACH()
+
+ ADD_LIBRARY(${module} ${_type} ${_sources})
+ TARGET_LINK_LIBRARIES(${module} ${_linklibs})
+ SET_TARGET_PROPERTIES(${module} PROPERTIES COMPILE_FLAGS "${OMNIORB_DEFINITIONS}")
ENDMACRO(OMNIORB_ADD_MODULE)