Salome HOME
Merge from V6_main 11/02/2013
[modules/kernel.git] / salome_adm / cmake_files / FindOMNIORB.cmake
1 # Find OmniORB4 cmake module and Pyhon backends
2 #
3 # sets the following variables:
4 # OMNIORB_FOUND        - TRUE if OmniORB4 installation has been found
5 # OMNIORB_INCLUDE_DIR  - OmniORB4 headers path
6 # OMNIORB_LIBRARIES    - OmniORB4 libraries 
7 # OMNIORB_VERSION      - OmniORB4 version
8 # OMNIORB_IDL_COMPILER - OmniORB4 idl compiler command (omniidl)
9 # OMNIORB_NAMESERVER   - OmniORB4 CORBA naming service (omniNames)
10 #
11 # optional variables:
12 # OMNIORB_DIR          - OmniORB4 local installation path
13 # OMNIORBPY_DIR        - OmniORBpy local installation path
14 #
15 # This module could use OMNIORB_DIR environment variable if set
16 # WARNING: The precedence order is the following:
17 #   1. OMNIORB_DIR cmake variable
18 #   2. OMNIORB_DIR environment variable
19 #   3. default cmake search paths
20 #
21 # This module could use OMNIORBPY_DIR environment variable if set
22 # WARNING: The precedence order is the following:
23 #   1. OMNIORBPY_DIR cmake variable
24 #   2. OMNIORBPY_DIR environment variable
25 #   3. default cmake search paths
26 #
27 # NOTE: this goes against cmake default behavior for Find* macros, 
28 # more on this issue: 
29 # http://www.mail-archive.com/kde-buildsystem@kde.org/msg00589.html
30 #
31
32 # minimum OmniORB4 supported version
33 # 4.0.6 has known bug float/double marshalling using CORBA::Any
34 set(OMNIORB_MINIMUM_VERSION "4.1.2")
35 set(OMNIORB_DIR $ENV{OMNIORB_DIR} CACHE PATH "Path to OmniORB directory")
36
37 ##############################################################################
38 # find headers
39 ##############################################################################
40 find_path(OMNIORB_INCLUDE_DIR omniORB4/CORBA.h
41   PATHS "${OMNIORB_DIR}/include" "$ENV{OMNIORB_DIR}/include"
42   NO_DEFAULT_PATH)
43
44 find_path(OMNIORB_INCLUDE_DIR omniORB4/CORBA.h)
45
46
47 ##############################################################################
48 # find libraries
49 ##############################################################################
50 if (WIN32)
51   find_library(OMNIORB_LIBRARY_omniORB4
52         NAMES
53         ${CMAKE_STATIC_LIBRARY_PREFIX}omniORB4${CMAKE_STATIC_LIBRARY_SUFFIX}
54         PATHS ${OMNIORB_DIR}/lib/x86_win32 $ENV{OMNIORB_DIR}/lib/x86_win32
55         NO_DEFAULT_PATH
56   )
57   find_library(OMNIORB_LIBRARY_omniORB4 NAMES
58     ${CMAKE_STATIC_LIBRARY_PREFIX}omniORB4${CMAKE_STATIC_LIBRARY_SUFFIX}
59   )
60 else (WIN32)
61   find_library(OMNIORB_LIBRARY_omniORB4
62     NAMES omniORB4
63     PATHS "${OMNIORB_DIR}/lib${LIB_SUFFIX}" "$ENV{OMNIORB_DIR}/lib${LIB_SUFFIX}"
64     NO_DEFAULT_PATH)
65
66   find_library(OMNIORB_LIBRARY_omniORB4
67     NAMES omniORB4)
68 endif (WIN32)   
69   
70 if (WIN32)
71   FIND_LIBRARY( OMNIORB_LIBRARY_omnithread
72         NAMES
73         ${CMAKE_STATIC_LIBRARY_PREFIX}omnithread${CMAKE_STATIC_LIBRARY_SUFFIX}
74         PATHS ${OMNIORB_DIR}/lib/x86_win32 $ENV{OMNIORB_DIR}/lib/x86_win32
75         NO_DEFAULT_PATH
76   )
77
78   FIND_LIBRARY( OMNIORB_LIBRARY_omnithread
79         NAMES
80         ${CMAKE_STATIC_LIBRARY_PREFIX}omnithread${CMAKE_STATIC_LIBRARY_SUFFIX}
81   )
82 else (WIN32)
83   find_library(OMNIORB_LIBRARY_omnithread
84     NAMES omnithread
85     PATHS "${OMNIORB_DIR}/lib${LIB_SUFFIX}" "$ENV{OMNIORB_DIR}/lib${LIB_SUFFIX}"
86     NO_DEFAULT_PATH)
87
88   find_library(OMNIORB_LIBRARY_omnithread
89     NAMES omnithread)
90 endif (WIN32)
91
92
93 if (WIN32)
94   FIND_LIBRARY( OMNIORB_LIBRARY_omniDynamic4
95     NAMES
96       ${CMAKE_STATIC_LIBRARY_PREFIX}omniDynamic4${CMAKE_STATIC_LIBRARY_SUFFIX}
97     PATHS ${OMNIORB_DIR}/lib/x86_win32 $ENV{OMNIORB_DIR}/lib/x86_win32
98     NO_DEFAULT_PATH
99   )
100
101   FIND_LIBRARY( OMNIORB_LIBRARY_omniDynamic4
102     NAMES
103       ${CMAKE_STATIC_LIBRARY_PREFIX}omniDynamic4${CMAKE_STATIC_LIBRARY_SUFFIX}
104   )
105 else (WIN32)
106   find_library(OMNIORB_LIBRARY_omniDynamic4
107     NAMES omniDynamic4
108     PATHS "${OMNIORB_DIR}/lib${LIB_SUFFIX}" "$ENV{OMNIORB_DIR}/lib${LIB_SUFFIX}"
109     NO_DEFAULT_PATH)
110
111   find_library(OMNIORB_LIBRARY_omniDynamic4
112     NAMES omniDynamic4)
113 endif (WIN32)    
114
115 # optional libraries
116
117 if (WIN32)
118   FIND_LIBRARY( OMNIORB_LIBRARY_COS4
119     NAMES
120       ${CMAKE_STATIC_LIBRARY_PREFIX}COS4${CMAKE_STATIC_LIBRARY_SUFFIX}
121     PATHS ${OMNIORB_DIR}/lib/x86_win32 $ENV{OMNIORB_DIR}/lib/x86_win32
122     NO_DEFAULT_PATH 
123   )
124
125   FIND_LIBRARY( OMNIORB_LIBRARY_COS4
126     NAMES
127       ${CMAKE_STATIC_LIBRARY_PREFIX}COS4${CMAKE_STATIC_LIBRARY_SUFFIX}
128   )
129 else (WIN32)
130   find_library(OMNIORB_LIBRARY_COS4
131     NAMES COS4
132     PATHS "${OMNIORB_DIR}/lib${LIB_SUFFIX}" "$ENV{OMNIORB_DIR}/lib${LIB_SUFFIX}"
133     NO_DEFAULT_PATH)
134
135   find_library(OMNIORB_LIBRARY_COS4
136     NAMES COS4)
137 endif (WIN32)
138
139 if (WIN32)
140   FIND_LIBRARY( OMNIORB_LIBRARY_COSDynamic4
141     NAMES
142       ${CMAKE_STATIC_LIBRARY_PREFIX}COSDynamic4${CMAKE_STATIC_LIBRARY_SUFFIX}
143     PATHS ${OMNIORB_DIR}/lib/x86_win32 $ENV{OMNIORB_DIR}/lib/x86_win32
144     NO_DEFAULT_PATH
145   )
146
147   FIND_LIBRARY( OMNIORB_LIBRARY_COSDynamic4
148     NAMES
149       ${CMAKE_STATIC_LIBRARY_PREFIX}COSDynamic4${CMAKE_STATIC_LIBRARY_SUFFIX}
150   )
151
152 else (WIN32)
153   find_library(OMNIORB_LIBRARY_COSDynamic4
154     NAMES COSDynamic4
155     PATHS "${OMNIORB_DIR}/lib${LIB_SUFFIX}" "$ENV{OMNIORB_DIR}/lib${LIB_SUFFIX}"
156     NO_DEFAULT_PATH)
157
158   find_library(OMNIORB_LIBRARY_COSDynamic4
159     NAMES COSDynamic4)
160 endif (WIN32)
161 ##############################################################################
162 # find command line tools
163 ##############################################################################
164 IF (WIN32)
165 FIND_PROGRAM( OMNIORB_IDL_COMPILER
166   NAMES omniidl
167   PATHS ${OMNIORB_DIR}/bin/x86_win32 $ENV{OMNIORB_DIR}/bin/x86_win32
168   DOC "What is the path where omniidl (the idl compiler) can be found"
169   NO_DEFAULT_PATH
170 )
171 FIND_PROGRAM( OMNIORB_IDL_COMPILER
172   NAMES omniidl
173   DOC "What is the path where omniidl (the idl compiler) can be found"
174 )
175
176 FIND_PROGRAM( OMNIORB_OMNINAMES_COMMAND
177   NAMES omniNames
178   PATHS ${OMNIORB_DIR}/bin/x86_win32 $ENV{OMNIORB_DIR}/bin/x86_win32
179   DOC "What is the path where omniNames (the ORB server) can be found"
180   NO_DEFAULT_PATH
181 )
182 FIND_PROGRAM( OMNIORB_OMNINAMES_COMMAND
183   NAMES omniNames
184   DOC "What is the path where omniNames (the ORB server) can be found"
185 )
186 ELSE(WIN32)
187   find_program(OMNIORB_IDL_COMPILER
188     NAMES omniidl
189     PATHS "${OMNIORB_DIR}/bin" "$ENV{OMNIORB_DIR}/bin"
190     NO_DEFAULT_PATH)
191     
192   find_program(OMNIORB_IDL_COMPILER
193     NAMES omniidl)
194
195   find_program(OMNIORB_NAMESERVER
196     NAMES omniNames
197     PATHS "${OMNIORB_DIR}/bin" "$ENV{OMNIORB_DIR}/bin"
198     NO_DEFAULT_PATH)
199     
200   find_program(OMNIORB_NAMESERVER
201     NAMES omniNames)
202 ENDIF (WIN32)
203
204 ##############################################################################
205 # find python back-end
206 ##############################################################################
207 FIND_PATH( OMNIORB_PYTHON_BACKEND
208   NAMES python.py
209   PATHS $ENV{OMNIORB_DIR}/lib/python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}/site-packages/omniidl_be $ENV{OMNIORBPY_DIR}/lib/python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}/site-packages/omniidl_be
210         ${OMNIORB_DIR}/lib/python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}/site-packages/omniidl_be ${OMNIORBPY_DIR}/lib/python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}/site-packages/omniidl_be
211   DOC "Path to python-backend directory (omniidl_be) including python.py file"
212   NO_DEFAULT_PATH )
213
214 FIND_PATH( OMNIORB_PYTHON_BACKEND
215   NAMES python.py
216   DOC "Path to python-backend directory (omniidl_be) including python.py file" )
217 ##############################################################################
218 # cook our stuff
219 ##############################################################################
220 set(OMNIORB_FOUND "FALSE")
221
222 if(OMNIORB_INCLUDE_DIR AND
223     OMNIORB_LIBRARY_omniORB4 AND
224     OMNIORB_LIBRARY_omnithread AND
225     OMNIORB_LIBRARY_omniDynamic4 AND
226     OMNIORB_IDL_COMPILER)
227   set(OMNIORB_FOUND "TRUE")
228   mark_as_advanced(OMNIORB_DIR)
229   mark_as_advanced(OMNIORB_INCLUDE_DIR)
230   mark_as_advanced(OMNIORB_LIBRARY_omniORB4)
231   mark_as_advanced(OMNIORB_LIBRARY_omnithread)
232   mark_as_advanced(OMNIORB_LIBRARY_omniDynamic4)
233   mark_as_advanced(OMNIORB_IDL_COMPILER)
234   mark_as_advanced(OMNIORB_NAMESERVER)
235   mark_as_advanced(OMNIORB_VERSION)
236   mark_as_advanced(OMNIORB_LIBRARY_COS4)
237   mark_as_advanced(OMNIORB_LIBRARY_COSDynamic4)
238   mark_as_advanced(OMNIORB_PYTHON_BACKEND)
239
240   set(OMNIORB_LIBRARIES
241     ${OMNIORB_LIBRARY_omniORB4}
242     ${OMNIORB_LIBRARY_omnithread}
243     ${OMNIORB_LIBRARY_omniDynamic4})
244
245   if(OMNIORB_LIBRARY_COS4)
246     set(OMNIORB_LIBRARIES ${OMNIORB_LIBRARIES} ${OMNIORB_LIBRARY_COS4})
247   endif()
248   if(OMNIORB_LIBRARY_COSDynamic4)
249     set(OMNIORB_LIBRARIES ${OMNIORB_LIBRARIES} ${OMNIORB_LIBRARY_COSDynamic4})
250   endif()
251
252   # Optionaly, extract the the version number from the acconfig.h file:
253   if( EXISTS ${OMNIORB_INCLUDE_DIR}/omniORB4/acconfig.h )
254     file( READ ${OMNIORB_INCLUDE_DIR}/omniORB4/acconfig.h OMNIORB_ACCONFIG_H )
255     string( REGEX MATCH "#define[\t ]+PACKAGE_VERSION[\t ]+\"([0-9]+.[0-9]+.[0-9]+)\"" OMNIORB_ACCONFIG_H "${OMNIORB_ACCONFIG_H}" )
256     string( REGEX REPLACE ".*\"([0-9]+.[0-9]+.[0-9]+)\".*" "\\1" OMNIORB_VERSION "${OMNIORB_ACCONFIG_H}" )
257
258     if( ${OMNIORB_VERSION} VERSION_LESS ${OMNIORB_MINIMUM_VERSION} )
259       message( "WARNING: your version of omniORB is older than the minimum required one (${OMNIORB_MINIMUM_VERSION}), using DIET with this version may result in undetermined behaviors." )
260     endif()
261
262
263   else( EXISTS ${OMNIORB_INCLUDE_DIR}/omniORB4/acconfig.h )
264     set( OMNIORB_VERSION "NOT-FOUND" )
265   endif( EXISTS ${OMNIORB_INCLUDE_DIR}/omniORB4/acconfig.h )
266   set( OMNIORB_VERSION ${OMNIORB_VERSION}
267       CACHE STRING "OmniORB version number." )
268   
269   SET(OMNIORB_IDLCXXFLAGS -Wba -nf)
270   SET(OMNIORB_IDLPYFLAGS -bpython)
271   IF (OMNIORB_PYTHON_BACKEND) 
272     SET(OMNIORB_IDLPYFLAGS "-p ${OMNIORB_PYTHON_BACKEND} ${OMNIORB_IDLPYFLAGS}")
273   ENDIF(OMNIORB_PYTHON_BACKEND)
274   SET(IDLCXXFLAGS ${OMNIORB_IDLCXXFLAGS})
275   SET(IDLPYFLAGS ${OMNIORB_IDLPYFLAGS})
276   SET(IDL_CLN_H .hh)
277   SET(IDL_SRV_H .hh)
278   SET(OMNIORB_DEFINITIONS "-D__x86__ -DCOMP_CORBA_DOUBLE -DCOMP_CORBA_LONG")
279   IF(WINDOWS)
280     SET(OMNIORB_DEFINITIONS "${OMNIORB_DEFINITIONS} -D__WIN32__")
281   ENDIF(WINDOWS)
282   IF(APPLE)
283     SET(OMNIORB_DEFINITIONS "${OMNIORB_DEFINITIONS} -D__macos__")#for omnithread.h to be checked...
284   ENDIF(APPLE)
285
286
287 else()
288   message(FATAL_ERROR "OmniORB is required, please define OMNIORB_DIR as environment or cmake variable")
289 endif()