Fixed a few issues, everything now works again.
[fail.git] / libs / lqt / CMakeLists.txt
blobe21ab6b9d15e6c05070a8c8a000e66af6ccb279e
1 #  Copyright (c) 2008 Peter Kuemmel 
2 #  Copyright (c) 2008 Mauro Iazzi
3 #  
4 #  Permission is hereby granted, free of charge, to any person
5 #  obtaining a copy of this software and associated documentation
6 #  files (the "Software"), to deal in the Software without
7 #  restriction, including without limitation the rights to use,
8 #  copy, modify, merge, publish, distribute, sublicense, and/or sell
9 #  copies of the Software, and to permit persons to whom the
10 #  Software is furnished to do so, subject to the following
11 #  conditions:
12 #  
13 #  The above copyright notice and this permission notice shall be
14 #  included in all copies or substantial portions of the Software.
15 #  
16 #  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 #  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18 #  OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 #  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20 #  HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21 #  WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 #  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 #  OTHER DEALINGS IN THE SOFTWARE.
25 cmake_minimum_required(VERSION 2.6)
27 project(lqt)
30 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY  ${CMAKE_CURRENT_BINARY_DIR}/bin) 
31 set(CMAKE_LIBRARY_OUTPUT_DIRECTORY  ${CMAKE_CURRENT_BINARY_DIR}/lib) 
32 set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY  ${CMAKE_CURRENT_BINARY_DIR}/lib) 
34 set( INSTALL_LIB_DIR "lib/lua/5.1" )
36 #set(CMAKE_VERBOSE_MAKEFILE TRUE)
39 find_package(Qt4 REQUIRED)
40 set(QT_USE_QTCORE 1)
41 set(QT_USE_QTGUI 1)
42 set(QT_USE_QTNETWORK 1)
43 set(QT_USE_QTWEBKIT 1)
44 set(QT_USE_QTOPENGL 1)
45 set(QT_USE_QTSCRIPT 1)
46 set(QT_USE_QTSVG 1)
47 set(QT_USE_QTXML 1)
48 set(QT_USE_QTUITOOLS 1)
49 #set(QT_USE_QTSQL 1)
50 #set(QT_USE_QTXMLPATTERNS 1)
51 include(${QT_USE_FILE})
53 if(noqt)
54         set(QT_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/test)
55         #set(nomerge TRUE)
56 endif()
58 if(SYSTEM_LUA)
59         find_package(Lua51 REQUIRED)
60         set(LUA_CMD lua)
61 else()
62         #add_subdirectory(lua)
63         set(LUA_CMD fail-lua-exe)
64         #set(LUA_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/lua/lua/src)
65         set(LUA_LIBRARIES fail-lua)
66 endif()
68 if(MSVC)
69         set(CMAKE_SUPPRESS_REGENERATION TRUE) 
70         add_definitions(-D_CRT_SECURE_NO_WARNINGS -D_SCL_SECURE_NO_WARNINGS -DLUA_BUILD_AS_DLL)
71         set(CMAKE_DEBUG_POSTFIX)
72 endif()
74 if(MINGW)
75         set(CMAKE_SHARED_LINKER_FLAGS "-Wl,-add-stdcall-alias")
76         SET(CMAKE_VERBOSE_MAKEFILE ON)
77 endif()
80 macro(lqt_files name folder)
81         file(GLOB ${name}_sources ${folder}/*.cpp) 
82         file(GLOB ${name}_headers ${folder}/*.hpp) 
83         qt4_wrap_cpp(${name}_moc ${${name}_headers})
84         qt4_automoc(${${name}_sources})
85         set(${name}_src ${${name}_sources} ${${name}_moc})      
86         set(${name}_h ${${name}_headers})
87         source_group(generated FILES ${${name}_moc})
88         project_source_group("${GROUP_CODE}" ${name}_sources ${name}_headers)
89 endmacro()
92 # folders in the msvc projects 
93 # mode==flat  : headers and sources not in folders 
94 # mode==split : standard behavior of cmake, split headers and sources 
95 # mode==<other values> : code is in this folder 
96 macro(project_source_group mode sources headers) 
97         if(${mode} MATCHES "flat") 
98                 source_group("Source Files" Files) 
99                 source_group("Header Files" Files) 
100                 source_group("cmake" FILES CMakeLists.txt) 
101         else() 
102                 if(NOT ${mode} MATCHES "split") 
103                         source_group("${mode}" FILES ${${sources}} ${${headers}}) 
104                 endif() 
105         endif() 
106 endmacro()
107 set(GROUP_CODE "Source Files")
109 set(LQT_BUILDIN_CPPTOXML 1)
110 if(LQT_BUILDIN_CPPTOXML)
111         add_subdirectory(cpptoxml)
112 else()
113 #TODO find cpptpxml
114 endif()
117 function(build_qt_lib_binding BINDING_HEADER)
119         string(TOLOWER ${BINDING_HEADER} BINDING_NAME)
121         # hardcoded in generator.lua
122         set (LQT_GEN_DIR ${CMAKE_CURRENT_BINARY_DIR}/${BINDING_NAME}_src)
123         file(MAKE_DIRECTORY ${LQT_GEN_DIR})
125         set (BINDING_SRC ${LQT_GEN_DIR}/${BINDING_NAME}_merged_build.cpp)
126         set_source_files_properties(${BINDING_SRC} PROPERTIES  GENERATED TRUE)
128         if (UNIX)
129                 set (PP_CONFIG ${CMAKE_CURRENT_SOURCE_DIR}/cpptoxml/parser/rpp/pp-qt-configuration)
130         else()
131                 set (PP_CONFIG ${CMAKE_CURRENT_SOURCE_DIR}/cpptoxml/parser/rpp/pp-qt-configuration-win)
132         endif()
134         set (GEN_XML ${LQT_GEN_DIR}/${BINDING_NAME}.xml)
135         
136         add_custom_command(
137                 OUTPUT ${GEN_XML}
138                 COMMAND cpptoxml
139                 ARGS ${BINDING_HEADER} -C ${PP_CONFIG} -Q ${QT_INCLUDE_DIR} -o ${GEN_XML}
140                 DEPENDS cpptoxml ${PP_CONFIG}
141                 COMMENT "Generating XML: running cpptoxml on ${BINDING_NAME}"
142         )
143                 
144         add_custom_target( generate_${BINDING_NAME}_xml DEPENDS ${GEN_XML} )
145                 
146         #add_custom_target(generate_${BINDING_NAME}_xml         COMMAND cpptoxml 
147         #                                               ${BINDING_HEADER} 
148         #                                               -C ${PP_CONFIG}
149         #                                               -Q ${QT_INCLUDE_DIR} 
150         #                                               -o ${GEN_XML}
151         #                                       COMMENT "Generating XML: running cpptoxml on ${BINDING_NAME} "
152         #                                       VERBATIM)
155         math(EXPR MAX ${ARGC}-1)
156         if(MAX)
157         foreach(I RANGE 1 ${MAX})
158                 string(TOLOWER ${ARGV${I}} DEPNAME)
159                 set(${BINDING_NAME}_TYPES ${${BINDING_NAME}_TYPES} -t ${DEPNAME}_src/${DEPNAME}_types.lua)
160                 set(${BINDING_NAME}_DEPENDS ${${BINDING_NAME}_DEPENDS} generate_${DEPNAME}_cpp)
161         endforeach()
162         endif(MAX)
163         
164         set(${BINDING_NAME}_GENERATED ${LQT_GEN_DIR}/${BINDING_NAME}_enum.cpp
165                                                                 ${LQT_GEN_DIR}/${BINDING_NAME}_meta.cpp
166                                                                 ${LQT_GEN_DIR}/${BINDING_NAME}_slot.cpp)
167         
168         add_custom_command(
169                 OUTPUT ${${BINDING_NAME}_GENERATED}
170                 COMMAND ${LUA_CMD}
171                 
172                 ARGS ${CMAKE_CURRENT_SOURCE_DIR}/generator/generator.lua ${GEN_XML}
173                         -i ${BINDING_HEADER} -i lqt_qt.hpp
174                         -n ${BINDING_NAME}
175                         -t ${CMAKE_CURRENT_SOURCE_DIR}/generator/qtypes.lua
176                         ${${BINDING_NAME}_TYPES}
177                         -f ${CMAKE_CURRENT_SOURCE_DIR}/generator/qt_internal.lua
178                         
179                 DEPENDS ${GEN_XML}
180                         generator/classes.lua generator/generator.lua generator/qt_internal.lua generator/qtypes.lua
181                         generator/types.lua generator/xml.lua
182                         
183                 COMMENT "Generating binding code with Lua"
184         )
185         
186         add_custom_target( generate_${BINDING_NAME}_cpp DEPENDS ${${BINDING_NAME}_GENERATED} )
187         
188         #add_custom_target(generate_${BINDING_NAME}_cpp  COMMAND cmake -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/common ${LQT_GEN_DIR}
189         #                                       COMMAND ${LUA_CMD}
190         #                                               "${CMAKE_CURRENT_SOURCE_DIR}/generator/generator.lua" 
191         #                                               ${GEN_XML} 
192         #                                               -i ${BINDING_HEADER} -i lqt_qt.hpp 
193         #                                               -n ${BINDING_NAME} 
194         #                                               -t ${CMAKE_CURRENT_SOURCE_DIR}/generator/qtypes.lua
195         #                                               ${${BINDING_NAME}_TYPES}
196         #                                               -f ${CMAKE_CURRENT_SOURCE_DIR}/generator/qt_internal.lua
197         #                                       COMMENT "Generating binding code with Lua"
198         #                                       VERBATIM)
200         set(COMMON COMMON_${BINDING_NAME})
202         file(GLOB ${COMMON}_SRC ${CMAKE_CURRENT_SOURCE_DIR}/common/*.cpp) 
203         file(GLOB ${COMMON}_HPP ${CMAKE_CURRENT_SOURCE_DIR}/common/*.hpp) 
205         set(${BINDING_NAME}_GENERATED ${LQT_GEN_DIR}/${BINDING_NAME}_enum.cpp
206                                                                         ${LQT_GEN_DIR}/${BINDING_NAME}_meta.cpp
207                                                                         ${LQT_GEN_DIR}/${BINDING_NAME}_slot.cpp)
209         set_source_files_properties(${${BINDING_NAME}_GENERATED} PROPERTIES GENERATED TRUE)
211         if(nomerge)
212                 #TODO fix this build process:
213                 #       1. cmake ../lqt -Dnomerge=1
214                 #       2. make -> will generate cpp files but they are not part of the Makefile (GLOB was at 1.)
215                 #       3. cmake ../lqt -Dnomerge=1 -> GLOB now finds the generated cpp files
216                 #       4. make
217                 file(GLOB BINDING_SRC ${LQT_GEN_DIR}/*.cpp) 
218                 set(${COMMON}_SRC)
219                 list(REMOVE_ITEM BINDING_SRC ${LQT_GEN_DIR}/${BINDING_NAME}_merged_build.cpp)
220         else()                          
221                 set(${COMMON}_SRC ${${COMMON}_SRC}      ${${BINDING_NAME}_GENERATED})
222         endif()
224         qt4_wrap_cpp(${COMMON}_MOC ${LQT_GEN_DIR}/${BINDING_NAME}_slot.hpp)
225         
226         include_directories(${CMAKE_CURRENT_SOURCE_DIR}/common ${LUA_INCLUDE_DIR} ${QT_INCLUDES})
228         add_library(${BINDING_NAME} SHARED  ${BINDING_SRC}
229                                                                                         ${${COMMON}_SRC}
230                                                                                         ${${COMMON}_HPP} 
231                                                                                         ${${COMMON}_MOC})
232                                                                                         
233         set_target_properties( ${BINDING_NAME} PROPERTIES PREFIX "" OUTPUT_NAME ${BINDING_NAME} )
234                                                                                         
235         target_link_libraries(${BINDING_NAME} ${QT_LIBRARIES} ${LUA_LIBRARIES})         
237         if(LQT_BUILDIN_CPPTOXML)
238                 add_dependencies(generate_${BINDING_NAME}_xml  cpptoxml)
239         endif()
241         add_dependencies(generate_${BINDING_NAME}_cpp  generate_${BINDING_NAME}_xml ${${BINDING_NAME}_DEPENDS})
242         add_dependencies(${BINDING_NAME} generate_${BINDING_NAME}_cpp)
243         if(NOT SYSTEM_LUA)
244                 add_dependencies(generate_${BINDING_NAME}_cpp luaexec)
245         endif()
247         install( TARGETS ${BINDING_NAME} DESTINATION ${LUA_MODULES_CDIR} )
248 endfunction()
250 if(MSVC)
251                 add_definitions(-D_CRT_SECURE_NO_DEPRECATE)
252 endif()
254 if(noqt)
255         include_directories(${CMAKE_CURRENT_SOURCE_DIR}/test/noqt)
256         build_qt_lib_binding(noqt)
257 else()
258 build_qt_lib_binding(QtCore)
259 build_qt_lib_binding(QtNetwork QtCore)
260 build_qt_lib_binding(QtGui QtNetwork QtCore)
261 build_qt_lib_binding(QtScript QtGui QtNetwork QtCore)
262 build_qt_lib_binding(QtOpenGL QtGui QtNetwork QtCore)
263 build_qt_lib_binding(QtSvg QtScript QtGui QtNetwork QtCore)
264 build_qt_lib_binding(QtWebKit QtSvg QtScript QtOpenGL QtGui QtNetwork QtCore)
265 build_qt_lib_binding(QtXml QtWebKit QtSvg QtScript QtOpenGL QtGui QtNetwork QtCore)
266 build_qt_lib_binding(QtUiTools QtXml QtWebKit QtSvg QtScript QtOpenGL QtGui QtNetwork QtCore)
267 endif()
270 # needs testing
271 #build_qt_lib_binding(QtSql)
272 #build_qt_lib_binding(QtXmlPatterns)
273 #build_qt_lib_binding(Phonon)