Salome HOME
CMake: IF(WINDOWS) is deprecated - please always use IF(WIN32)
[modules/kernel.git] / salome_adm / cmake_files / UseOmniORB.cmake
1 # Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
2 #
3 # This library is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU Lesser General Public
5 # License as published by the Free Software Foundation; either
6 # version 2.1 of the License.
7 #
8 # This library is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 # Lesser General Public License for more details.
12 #
13 # You should have received a copy of the GNU Lesser General Public
14 # License along with this library; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 #
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 #
19
20 INSTALL( CODE "
21 SET(INSTALL_PYIDL_DIR lib/python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}/site-packages/salome) # R1 CHECK
22 IF(WIN32)
23   SET(INSTALL_PYIDL_DIR bin/salome) # R1 CHECK
24 ENDIF(WIN32)
25
26 MACRO(OMNIORB_COMPILE_IDL_FORPYTHON_ON_INSTALL MYOMNIORBIDLPYTHON MYIDLPYFLAGS MYIDLFILE MYFULLDIR)
27   FILE(MAKE_DIRECTORY \${MYFULLDIR})
28   STRING(REPLACE \" \" \";\" MYIDLPYFLAGS2 \${MYIDLPYFLAGS})
29   MESSAGE(STATUS \"Compiling \${MYIDLFILE} into \${MYFULLDIR}\")
30   EXECUTE_PROCESS(COMMAND \${MYOMNIORBIDLPYTHON} \${MYIDLPYFLAGS2} -C\${MYFULLDIR} \${MYIDLFILE})
31 ENDMACRO(OMNIORB_COMPILE_IDL_FORPYTHON_ON_INSTALL)
32 ")
33
34 #----------------------------------------------------------------------------
35 # OMNIORB_ADD_MODULE macro: generate CORBA wrappings for a module.
36 #
37 # USAGE: OMNIORB_ADD_MODULE(module idlfiles incdirs [linklibs])
38 #
39 # ARGUMENTS:
40 #   module    : module name
41 #   idlfiles  : list of IDL files to be compiled into module
42 #   incdirs   : additional include dirs for IDL staff
43 #   linklibs  : additional libraries the module to be linked to (optional)
44 #
45 # For example, to build CORBA staff from MyModule.idl for module MyModule
46 # (that depends only on SALOME KERNEL interfaces), use the following code:
47 #
48 #   INCLUDE(UseOmniORB)
49 #   INCLUDE_DIRECTORIES(${OMNIORB_INCLUDE_DIR} ${KERNEL_INCLUDE_DIRS})
50 #   OMNIORB_ADD_MODULE(SalomeIDLMyModule MyModule.idl ${KERNEL_ROOT_DIR}/idl/salome ${KERNEL_SalomeIDLKernel})
51 #   INSTALL(TARGETS SalomeIDLMyModule EXPORT ${PROJECT_NAME}TargetGroup DESTINATION ${SALOME_INSTALL_LIBS})
52
53 # This macro uses the following variables:
54 # - From FindOmniORB.cmake
55 #     OMNIORB_IDL            : the path to the omniidl tool
56 #     OMNIORB_IDLCXXFLAGS    : the options to give to omniidl generator for C++ backend
57 #     OMNIORB_DEFINITIONS    : additional compile options for C++
58 # - From FindOmniORBPy.cmake
59 #     OMNIORB_IDLPYFLAGS     : the options to give to omniidl generator for Python backend
60 #     OMNIORB_PYTHON_BACKEND : Python backend
61 #
62 # TODO:
63 #   1. Replace hardcoded dirpaths bin/salome, idl/salome, etc by corresponding configuration options.
64 #   2. Revise/improve OMNIORB_COMPILE_IDL_FORPYTHON_ON_INSTALL macro usage.
65 #   3. Add proper handling of INCLUDE_DIRECTORIES to minimize this macro usage in target CMakeLists.txt files.
66 #
67 #----------------------------------------------------------------------------
68 MACRO(OMNIORB_ADD_MODULE module idlfiles incdirs)
69   # process additional libraries the module to be linked to
70   SET(_linklibs ${OMNIORB_LIBRARIES})
71   FOREACH(_arg ${ARGN})
72     SET(_linklibs ${_linklibs} ${_arg})
73   ENDFOREACH()
74   
75   # module sources
76   SET(_sources)
77   # type of the libraries: SHARED for Linux, STATIC for Windows
78   SET(_type SHARED)
79   IF(WIN32)
80     SET(_type STATIC)
81   ENDIF()
82   IF(NOT WIN32 AND (_type STREQUAL STATIC)) 
83     SET(CMAKE_POSITION_INDEPENDENT_CODE ON)
84   ENDIF()
85
86   # add additional include dirs to the C++ and Python backend options
87   SET(_cxx_flags ${OMNIORB_IDLCXXFLAGS})
88   SET(_py_flags "${OMNIORB_IDLPYFLAGS}")
89   FOREACH(_f ${incdirs})
90     LIST(APPEND _cxx_flags "-I${_f}")
91     LIST(APPEND _py_flags  "-I${_f}")
92   ENDFOREACH()
93
94   FOREACH(_input ${idlfiles})
95     GET_FILENAME_COMPONENT(_base ${_input} NAME_WE)
96     GET_FILENAME_COMPONENT(_path ${_input} PATH)
97     IF(NOT _path)
98       SET(_input ${CMAKE_CURRENT_SOURCE_DIR}/${_input})
99     ENDIF()
100
101     SET(_inc     ${CMAKE_CURRENT_BINARY_DIR}/${_base}.hh)
102     SET(_src     ${CMAKE_CURRENT_BINARY_DIR}/${_base}SK.cc)
103     SET(_dynsrc  ${CMAKE_CURRENT_BINARY_DIR}/${_base}DynSK.cc)
104
105     LIST(APPEND _sources ${_src})
106     LIST(APPEND _sources ${_dynsrc})
107     SET(_outputs ${_inc} ${_src} ${_dynsrc})
108
109     ADD_CUSTOM_COMMAND(OUTPUT ${_outputs}
110       COMMAND ${OMNIORB_IDL_COMPILER} ${_cxx_flags} ${_input}
111       MAIN_DEPENDENCY ${_input})
112     
113     INSTALL(FILES ${_input} DESTINATION idl/salome)
114     INSTALL(FILES ${_inc}   DESTINATION include/salome)
115
116     IF(OMNIORB_PYTHON_BACKEND)
117       STRING(REPLACE ";" " " _tmp "${_py_flags}")
118       INSTALL(CODE "OMNIORB_COMPILE_IDL_FORPYTHON_ON_INSTALL( \"${OMNIORB_IDL_COMPILER}\" \"${_tmp}\" \"${_input}\" \"${CMAKE_INSTALL_PREFIX}/\${INSTALL_PYIDL_DIR}\" )")
119     ENDIF()
120   ENDFOREACH()
121
122   ADD_LIBRARY(${module} ${_type} ${_sources})
123   TARGET_LINK_LIBRARIES(${module} ${_linklibs})
124   SET_TARGET_PROPERTIES(${module} PROPERTIES COMPILE_FLAGS "${OMNIORB_DEFINITIONS}")
125
126 ENDMACRO(OMNIORB_ADD_MODULE)