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_BINARY_DIR}/bin)
31 set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
32 set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
34 #set(CMAKE_VERBOSE_MAKEFILE TRUE)
37 find_package(Qt4 REQUIRED)
40 set(QT_USE_QTNETWORK 1)
41 set(QT_USE_QTWEBKIT 1)
42 set(QT_USE_QTOPENGL 1)
43 set(QT_USE_QTSCRIPT 1)
47 #set(QT_USE_QTXMLPATTERNS 1)
48 include(${QT_USE_FILE})
51 set(QT_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/test)
56 find_package(Lua51 REQUIRED)
61 set(LUA_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/lua/lua/src)
62 set(LUA_LIBRARIES lua)
66 set(CMAKE_SUPPRESS_REGENERATION TRUE)
67 add_definitions(-D_CRT_SECURE_NO_DEPRECATE -D_CRT_SECURE_NO_WARNINGS -D_SCL_SECURE_NO_WARNINGS -DLUA_BUILD_AS_DLL)
68 set(CMAKE_DEBUG_POSTFIX)
72 set(CMAKE_SHARED_LINKER_FLAGS "-Wl,-add-stdcall-alias")
73 SET(CMAKE_VERBOSE_MAKEFILE ON)
77 macro(lqt_files name folder)
78 file(GLOB ${name}_sources ${folder}/*.cpp)
79 file(GLOB ${name}_headers ${folder}/*.hpp)
80 qt4_wrap_cpp(${name}_moc ${${name}_headers})
81 qt4_automoc(${${name}_sources})
82 set(${name}_src ${${name}_sources} ${${name}_moc})
83 set(${name}_h ${${name}_headers})
84 source_group(generated FILES ${${name}_moc})
85 project_source_group("${GROUP_CODE}" ${name}_sources ${name}_headers)
89 # folders in the msvc projects
90 # mode==flat : headers and sources not in folders
91 # mode==split : standard behavior of cmake, split headers and sources
92 # mode==<other values> : code is in this folder
93 macro(project_source_group mode sources headers)
94 if(${mode} MATCHES "flat")
95 source_group("Source Files" Files)
96 source_group("Header Files" Files)
97 source_group("cmake" FILES CMakeLists.txt)
99 if(NOT ${mode} MATCHES "split")
100 source_group("${mode}" FILES ${${sources}} ${${headers}})
104 set(GROUP_CODE "Source Files")
106 set(LQT_BUILDIN_CPPTOXML 1)
107 if(LQT_BUILDIN_CPPTOXML)
108 add_subdirectory(cpptoxml)
114 function(build_qt_lib_binding BINDING_HEADER)
116 string(TOLOWER ${BINDING_HEADER} BINDING_NAME)
118 # hardcoded in generator.lua
119 set (LQT_GEN_DIR ${CMAKE_BINARY_DIR}/${BINDING_NAME}_src)
120 file(MAKE_DIRECTORY ${LQT_GEN_DIR})
122 set (BINDING_SRC ${LQT_GEN_DIR}/${BINDING_NAME}_merged_build.cpp)
123 set_source_files_properties(${BINDING_SRC} PROPERTIES GENERATED TRUE)
126 set (PP_CONFIG ${CMAKE_SOURCE_DIR}/cpptoxml/parser/rpp/pp-qt-configuration)
128 set (PP_CONFIG ${CMAKE_SOURCE_DIR}/cpptoxml/parser/rpp/pp-qt-configuration-win)
132 set (GEN_XML ${LQT_GEN_DIR}/${BINDING_NAME}.xml)
133 add_custom_target(generate_${BINDING_NAME}_xml COMMAND cpptoxml
138 COMMENT "Generating XML: running cpptoxml on ${BINDING_NAME} "
142 math(EXPR MAX ${ARGC}-1)
144 foreach(I RANGE 1 ${MAX})
145 string(TOLOWER ${ARGV${I}} DEPNAME)
146 set(${BINDING_NAME}_TYPES ${${BINDING_NAME}_TYPES} -t ${DEPNAME}_src/${DEPNAME}_types.lua)
147 set(${BINDING_NAME}_DEPENDS ${${BINDING_NAME}_DEPENDS} generate_${DEPNAME}_cpp)
151 add_custom_target(generate_${BINDING_NAME}_cpp
153 "${CMAKE_SOURCE_DIR}/generator/generator.lua"
155 -i ${BINDING_HEADER} -i lqt_qt.hpp
157 -t ${CMAKE_SOURCE_DIR}/generator/qtypes.lua
158 ${${BINDING_NAME}_TYPES}
159 -f ${CMAKE_SOURCE_DIR}/generator/qt_internal.lua
160 COMMENT "Generating binding code with Lua"
163 add_custom_target(generate_${BINDING_NAME}_xml COMMAND
164 COMMENT "Reusing old XML on ${BINDING_NAME} "
166 add_custom_target(generate_${BINDING_NAME}_cpp
167 COMMENT "Reusing old binding code with Lua"
171 set(COMMON COMMON_${BINDING_NAME})
172 file(GLOB ${COMMON}_SRC ${CMAKE_SOURCE_DIR}/common/*.cpp)
173 file(GLOB ${COMMON}_HPP ${CMAKE_SOURCE_DIR}/common/*.hpp)
176 set(${BINDING_NAME}_GENERATED ${LQT_GEN_DIR}/${BINDING_NAME}_enum.cpp
177 ${LQT_GEN_DIR}/${BINDING_NAME}_meta.cpp
178 ${LQT_GEN_DIR}/${BINDING_NAME}_slot.cpp)
179 set_source_files_properties(${${BINDING_NAME}_GENERATED} PROPERTIES GENERATED TRUE)
182 #TODO fix this build process:
183 # 1. cmake ../lqt -Dnomerge=1
184 # 2. make -> will generate cpp files but they are not part of the Makefile (GLOB was at 1.)
185 # 3. cmake ../lqt -Dnomerge=1 -> GLOB now finds the generated cpp files
187 file(GLOB BINDING_SRC ${LQT_GEN_DIR}/*.cpp)
189 list(REMOVE_ITEM BINDING_SRC ${LQT_GEN_DIR}/${BINDING_NAME}_merged_build.cpp)
191 set(${COMMON}_SRC ${${COMMON}_SRC} ${${BINDING_NAME}_GENERATED})
194 qt4_wrap_cpp(${COMMON}_MOC ${LQT_GEN_DIR}/${BINDING_NAME}_slot.hpp)
196 include_directories(${CMAKE_SOURCE_DIR}/common ${LUA_INCLUDE_DIRS} ${QT_INCLUDES})
198 add_library(${BINDING_NAME} SHARED ${BINDING_SRC}
203 target_link_libraries(${BINDING_NAME} ${QT_LIBRARIES} ${LUA_LIBRARIES})
205 if(LQT_BUILDIN_CPPTOXML)
206 add_dependencies(generate_${BINDING_NAME}_xml cpptoxml)
209 add_dependencies(generate_${BINDING_NAME}_cpp generate_${BINDING_NAME}_xml ${${BINDING_NAME}_DEPENDS})
210 add_dependencies(${BINDING_NAME} generate_${BINDING_NAME}_cpp)
212 add_dependencies(generate_${BINDING_NAME}_cpp luaexec)
217 include_directories(${CMAKE_CURRENT_SOURCE_DIR}/test/noqt)
218 build_qt_lib_binding(noqt)
220 build_qt_lib_binding(QtCore)
221 build_qt_lib_binding(QtNetwork QtCore)
222 build_qt_lib_binding(QtGui QtNetwork QtCore)
223 build_qt_lib_binding(QtScript QtGui QtNetwork QtCore)
224 build_qt_lib_binding(QtOpenGL QtGui QtNetwork QtCore)
225 build_qt_lib_binding(QtSvg QtScript QtGui QtNetwork QtCore)
226 build_qt_lib_binding(QtXml QtSvg QtScript QtGui QtNetwork QtCore)
227 build_qt_lib_binding(QtWebKit QtSvg QtScript QtOpenGL QtGui QtNetwork QtCore)
229 #build_qt_lib_binding(QtSql)
230 #build_qt_lib_binding(QtScriptTools) # 4.5 only
231 #build_qt_lib_binding(QtXmlPatterns)
232 #build_qt_lib_binding(Phonon)