1 # Copyright (c) 2008 Peter Kuemmel
3 # Permission is hereby granted, free of charge, to any person
4 # obtaining a copy of this software and associated documentation
5 # files (the "Software"), to deal in the Software without
6 # restriction, including without limitation the rights to use,
7 # copy, modify, merge, publish, distribute, sublicense, and/or sell
8 # copies of the Software, and to permit persons to whom the
9 # Software is furnished to do so, subject to the following
12 # The above copyright notice and this permission notice shall be
13 # included in all copies or substantial portions of the Software.
15 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17 # OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19 # HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20 # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 # OTHER DEALINGS IN THE SOFTWARE.
24 cmake_minimum_required(VERSION 2.6)
29 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
30 set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
31 set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
34 find_package(Qt4 REQUIRED)
37 set(QT_USE_QTNETWORK 1)
38 set(QT_USE_QTWEBKIT 1)
39 set(QT_USE_QTOPENGL 1)
40 set(QT_USE_QTSCRIPT 1)
44 #set(QT_USE_QTXMLPATTERNS 1)
45 include(${QT_USE_FILE})
48 find_package(Lua51 REQUIRED)
53 set(LUA_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/lua/lua/src)
54 set(LUA_LIBRARIES lua)
58 set(CMAKE_SUPPRESS_REGENERATION TRUE)
59 add_definitions(-D_CRT_SECURE_NO_WARNINGS -D_SCL_SECURE_NO_WARNINGS -DLUA_BUILD_AS_DLL)
60 set(CMAKE_DEBUG_POSTFIX)
64 set(CMAKE_SHARED_LINKER_FLAGS "-Wl,-add-stdcall-alias")
65 SET(CMAKE_VERBOSE_MAKEFILE ON)
69 macro(lqt_files name folder)
70 file(GLOB ${name}_sources ${folder}/*.cpp)
71 file(GLOB ${name}_headers ${folder}/*.hpp)
72 qt4_wrap_cpp(${name}_moc ${${name}_headers})
73 qt4_automoc(${${name}_sources})
74 set(${name}_src ${${name}_sources} ${${name}_moc})
75 set(${name}_h ${${name}_headers})
76 source_group(generated FILES ${${name}_moc})
77 project_source_group("${GROUP_CODE}" ${name}_sources ${name}_headers)
81 # folders in the msvc projects
82 # mode==flat : headers and sources not in folders
83 # mode==split : standard behavior of cmake, split headers and sources
84 # mode==<other values> : code is in this folder
85 macro(project_source_group mode sources headers)
86 if(${mode} MATCHES "flat")
87 source_group("Source Files" Files)
88 source_group("Header Files" Files)
89 source_group("cmake" FILES CMakeLists.txt)
91 if(NOT ${mode} MATCHES "split")
92 source_group("${mode}" FILES ${${sources}} ${${headers}})
96 set(GROUP_CODE "Source Files")
98 set(LQT_BUILDIN_CPPTOXML 1)
99 if(LQT_BUILDIN_CPPTOXML)
100 add_subdirectory(cpptoxml)
106 macro(build_qt_lib_binding BINDING_HEADER)
108 string(TOLOWER ${BINDING_HEADER} BINDING_NAME)
110 # hardcoded in generator.lua
111 set (LQT_GEN_DIR ${CMAKE_BINARY_DIR}/${BINDING_NAME}_src)
112 file(MAKE_DIRECTORY ${LQT_GEN_DIR})
114 set (BINDING_SRC ${LQT_GEN_DIR}/${BINDING_NAME}_merged_build.cpp)
115 set_source_files_properties(${BINDING_SRC} PROPERTIES GENERATED TRUE)
118 set (PP_CONFIG ${CMAKE_SOURCE_DIR}/cpptoxml/parser/rpp/pp-qt-configuration)
120 set (PP_CONFIG ${CMAKE_SOURCE_DIR}/cpptoxml/parser/rpp/pp-qt-configuration-win)
123 set (GEN_XML ${LQT_GEN_DIR}/${BINDING_NAME}.xml)
124 add_custom_target(generate_${BINDING_NAME}_xml COMMAND cpptoxml
129 COMMENT "Generating XML: running cpptoxml on ${BINDING_NAME} "
133 add_custom_target(generate_${BINDING_NAME}_cpp COMMAND cmake -E copy_directory ${CMAKE_SOURCE_DIR}/common ${LQT_GEN_DIR}
135 "${CMAKE_SOURCE_DIR}/generator/generator.lua"
137 -i ${BINDING_HEADER} -i lqt_qt.hpp
139 -t ${CMAKE_SOURCE_DIR}/generator/types.lua
140 -t ${CMAKE_SOURCE_DIR}/generator/qtypes.lua
141 -f ${CMAKE_SOURCE_DIR}/generator/qt_internal.lua
142 COMMENT "Generating binding code with Lua"
145 set(COMMON COMMON_${BINDING_NAME})
146 file(GLOB ${COMMON}_SRC ${CMAKE_SOURCE_DIR}/common/*.cpp)
147 file(GLOB ${COMMON}_HPP ${CMAKE_SOURCE_DIR}/common/*.hpp)
149 set(${BINDING_NAME}_GENERATED ${LQT_GEN_DIR}/${BINDING_NAME}_enum.cpp
150 ${LQT_GEN_DIR}/${BINDING_NAME}_meta.cpp
151 ${LQT_GEN_DIR}/${BINDING_NAME}_slot.cpp)
152 set_source_files_properties(${${BINDING_NAME}_GENERATED} PROPERTIES GENERATED TRUE)
154 set(${COMMON}_SRC ${${COMMON}_SRC} ${${BINDING_NAME}_GENERATED})
155 qt4_wrap_cpp(${COMMON}_MOC ${LQT_GEN_DIR}/${BINDING_NAME}_slot.hpp)
157 include_directories(${CMAKE_SOURCE_DIR}/common ${LUA_INCLUDE_DIRS} ${QT_INCLUDES})
159 add_library(${BINDING_NAME} SHARED ${BINDING_SRC}
164 target_link_libraries(${BINDING_NAME} ${QT_LIBRARIES} ${LUA_LIBRARIES})
166 if(LQT_BUILDIN_CPPTOXML)
167 add_dependencies(generate_${BINDING_NAME}_xml cpptoxml)
169 add_dependencies(generate_${BINDING_NAME}_cpp generate_${BINDING_NAME}_xml)
170 add_dependencies(${BINDING_NAME} generate_${BINDING_NAME}_cpp)
172 add_dependencies(generate_${BINDING_NAME}_cpp luaexec)
177 add_definitions(-D_CRT_SECURE_NO_DEPRECATE)
181 build_qt_lib_binding(QtCore)
182 build_qt_lib_binding(QtGui)
183 build_qt_lib_binding(QtNetwork)
184 build_qt_lib_binding(QtOpenGL)
185 build_qt_lib_binding(QtScript)
186 build_qt_lib_binding(QtSvg)
187 build_qt_lib_binding(QtWebKit)
188 build_qt_lib_binding(QtXml)
191 #build_qt_lib_binding(QtSql)
192 #build_qt_lib_binding(QtXmlPatterns)
193 #build_qt_lib_binding(Phonon)