1 # Copyright (c) 2008 Peter Kuemmel
2 # Copyright (c) 2008 Mauro Iazzi
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
13 # The above copyright notice and this permission notice shall be
14 # included in all copies or substantial portions of the Software.
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)
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)
42 set(QT_USE_QTNETWORK 1)
43 set(QT_USE_QTWEBKIT 1)
44 set(QT_USE_QTOPENGL 1)
45 set(QT_USE_QTSCRIPT 1)
48 set(QT_USE_QTUITOOLS 1)
50 #set(QT_USE_QTXMLPATTERNS 1)
51 include(${QT_USE_FILE})
54 set(QT_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/test)
59 find_package(Lua51 REQUIRED)
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)
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)
75 set(CMAKE_SHARED_LINKER_FLAGS "-Wl,-add-stdcall-alias")
76 SET(CMAKE_VERBOSE_MAKEFILE ON)
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)
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)
102 if(NOT ${mode} MATCHES "split")
103 source_group("${mode}" FILES ${${sources}} ${${headers}})
107 set(GROUP_CODE "Source Files")
109 set(LQT_BUILDIN_CPPTOXML 1)
110 if(LQT_BUILDIN_CPPTOXML)
111 add_subdirectory(cpptoxml)
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)
129 set (PP_CONFIG ${CMAKE_CURRENT_SOURCE_DIR}/cpptoxml/parser/rpp/pp-qt-configuration)
131 set (PP_CONFIG ${CMAKE_CURRENT_SOURCE_DIR}/cpptoxml/parser/rpp/pp-qt-configuration-win)
134 set (GEN_XML ${LQT_GEN_DIR}/${BINDING_NAME}.xml)
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}"
144 add_custom_target( generate_${BINDING_NAME}_xml DEPENDS ${GEN_XML} )
146 #add_custom_target(generate_${BINDING_NAME}_xml COMMAND cpptoxml
149 # -Q ${QT_INCLUDE_DIR}
151 # COMMENT "Generating XML: running cpptoxml on ${BINDING_NAME} "
155 math(EXPR MAX ${ARGC}-1)
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)
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)
169 OUTPUT ${${BINDING_NAME}_GENERATED}
172 ARGS ${CMAKE_CURRENT_SOURCE_DIR}/generator/generator.lua ${GEN_XML}
173 -i ${BINDING_HEADER} -i lqt_qt.hpp
175 -t ${CMAKE_CURRENT_SOURCE_DIR}/generator/qtypes.lua
176 ${${BINDING_NAME}_TYPES}
177 -f ${CMAKE_CURRENT_SOURCE_DIR}/generator/qt_internal.lua
180 generator/classes.lua generator/generator.lua generator/qt_internal.lua generator/qtypes.lua
181 generator/types.lua generator/xml.lua
183 COMMENT "Generating binding code with Lua"
186 add_custom_target( generate_${BINDING_NAME}_cpp DEPENDS ${${BINDING_NAME}_GENERATED} )
188 #add_custom_target(generate_${BINDING_NAME}_cpp COMMAND cmake -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/common ${LQT_GEN_DIR}
190 # "${CMAKE_CURRENT_SOURCE_DIR}/generator/generator.lua"
192 # -i ${BINDING_HEADER} -i lqt_qt.hpp
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"
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)
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
217 file(GLOB BINDING_SRC ${LQT_GEN_DIR}/*.cpp)
219 list(REMOVE_ITEM BINDING_SRC ${LQT_GEN_DIR}/${BINDING_NAME}_merged_build.cpp)
221 set(${COMMON}_SRC ${${COMMON}_SRC} ${${BINDING_NAME}_GENERATED})
224 qt4_wrap_cpp(${COMMON}_MOC ${LQT_GEN_DIR}/${BINDING_NAME}_slot.hpp)
226 include_directories(${CMAKE_CURRENT_SOURCE_DIR}/common ${LUA_INCLUDE_DIR} ${QT_INCLUDES})
228 add_library(${BINDING_NAME} SHARED ${BINDING_SRC}
233 set_target_properties( ${BINDING_NAME} PROPERTIES PREFIX "" OUTPUT_NAME ${BINDING_NAME} )
235 target_link_libraries(${BINDING_NAME} ${QT_LIBRARIES} ${LUA_LIBRARIES})
237 if(LQT_BUILDIN_CPPTOXML)
238 add_dependencies(generate_${BINDING_NAME}_xml cpptoxml)
241 add_dependencies(generate_${BINDING_NAME}_cpp generate_${BINDING_NAME}_xml ${${BINDING_NAME}_DEPENDS})
242 add_dependencies(${BINDING_NAME} generate_${BINDING_NAME}_cpp)
244 add_dependencies(generate_${BINDING_NAME}_cpp luaexec)
247 install( TARGETS ${BINDING_NAME} DESTINATION ${LUA_MODULES_CDIR} )
251 add_definitions(-D_CRT_SECURE_NO_DEPRECATE)
255 include_directories(${CMAKE_CURRENT_SOURCE_DIR}/test/noqt)
256 build_qt_lib_binding(noqt)
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)
271 #build_qt_lib_binding(QtSql)
272 #build_qt_lib_binding(QtXmlPatterns)
273 #build_qt_lib_binding(Phonon)