Added more templated classes
[lqt/mk.git] / CMakeLists.txt
blobb2dc3eec3e3bc5f77cd40468dee92eac8f6c5b7f
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_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)
36 option(SYSTEM_LUA "Use installed Lua" TRUE) 
38 find_package(Qt4 REQUIRED)
39 set(QT_USE_QTCORE 1)
40 set(QT_USE_QTGUI 1)
41 set(QT_USE_QTNETWORK 1)
42 set(QT_USE_QTWEBKIT 1)
43 set(QT_USE_QTOPENGL 1)
44 set(QT_USE_QTSCRIPT 1)
45 set(QT_USE_QTSVG 1)
46 set(QT_USE_QTUITOOLS 1) 
47 set(QT_USE_QTXML 1)
48 set(QT_USE_QTSQL 1)
49 set(QT_USE_QTXMLPATTERNS 1)
50 include(${QT_USE_FILE})
52 if(noqt)
53         set(QT_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/test)
54         #set(nomerge TRUE)
55 endif()
57 if(SYSTEM_LUA)
58         find_package(Lua51 REQUIRED)
59         set(LUA_INCLUDE_DIRS ${LUA_INCLUDE_DIR})
60         set(LUA_CMD lua)
61 else()
62         add_subdirectory(lua)
63         set(LUA_CMD luaexec)
64         set(LUA_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/lua/lua/src)
65         set(LUA_LIBRARIES lua)
66 endif()
68 if(MSVC)
69         set(CMAKE_SUPPRESS_REGENERATION TRUE) 
70         add_definitions(-D_CRT_SECURE_NO_DEPRECATE -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_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_SOURCE_DIR}/cpptoxml/parser/rpp/pp-qt-configuration)
130         else()
131                 set (PP_CONFIG ${CMAKE_SOURCE_DIR}/cpptoxml/parser/rpp/pp-qt-configuration-win)
132         endif()
134         if(NOT REUSE_FILES)
135                 set (GEN_XML ${LQT_GEN_DIR}/${BINDING_NAME}.xml)
136                 add_custom_target(generate_${BINDING_NAME}_xml  COMMAND cpptoxml 
137                                                                 ${BINDING_HEADER} 
138                                                                 -C ${PP_CONFIG}
139                                                                 -Q ${QT_INCLUDE_DIR} 
140                                                                 -o ${GEN_XML}
141                                                         COMMENT "Generating XML: running cpptoxml on ${BINDING_NAME} "
142                                                         VERBATIM)
145                 math(EXPR MAX ${ARGC}-1)
146                 if(MAX)
147                         foreach(I RANGE 1 ${MAX})
148                                 string(TOLOWER ${ARGV${I}} DEPNAME)
149                                 set(${BINDING_NAME}_TYPES ${${BINDING_NAME}_TYPES} -t ${DEPNAME}_src/${DEPNAME}_types.lua)
150                                 set(${BINDING_NAME}_DEPENDS ${${BINDING_NAME}_DEPENDS} generate_${DEPNAME}_cpp)
151                         endforeach()
152                 endif()
153                 
154                 add_custom_target(generate_${BINDING_NAME}_cpp
155                                                         COMMAND ${LUA_CMD}
156                                                                 "${CMAKE_SOURCE_DIR}/generator/generator.lua" 
157                                                                 ${GEN_XML} 
158                                                                 -i ${BINDING_HEADER} -i lqt_qt.hpp 
159                                                                 -n ${BINDING_NAME} 
160                                                                 -t ${CMAKE_SOURCE_DIR}/generator/qtypes.lua
161                                                                 ${${BINDING_NAME}_TYPES}
162                                                                 -f ${CMAKE_SOURCE_DIR}/generator/qt_internal.lua
163                                                         COMMENT "Generating binding code with Lua"
164                                                         VERBATIM)
165         else()
166                 add_custom_target(generate_${BINDING_NAME}_xml  COMMAND
167                                                         COMMENT "Reusing old XML on ${BINDING_NAME} "
168                                                         VERBATIM)
169                 add_custom_target(generate_${BINDING_NAME}_cpp
170                                                         COMMENT "Reusing old binding code with Lua"
171                                                         VERBATIM)
172         endif()
174         set(COMMON COMMON_${BINDING_NAME})
175         file(GLOB ${COMMON}_SRC ${CMAKE_SOURCE_DIR}/common/*.cpp)
176         file(GLOB ${COMMON}_HPP ${CMAKE_SOURCE_DIR}/common/*.hpp)
179         set(${BINDING_NAME}_GENERATED ${LQT_GEN_DIR}/${BINDING_NAME}_enum.cpp
180                                                                         ${LQT_GEN_DIR}/${BINDING_NAME}_meta.cpp
181                                                                         ${LQT_GEN_DIR}/${BINDING_NAME}_slot.cpp)
182         set_source_files_properties(${${BINDING_NAME}_GENERATED} PROPERTIES GENERATED TRUE)
184         if(nomerge)
185                 #TODO fix this build process:
186                 #       1. cmake ../lqt -Dnomerge=1
187                 #       2. make -> will generate cpp files but they are not part of the Makefile (GLOB was at 1.)
188                 #       3. cmake ../lqt -Dnomerge=1 -> GLOB now finds the generated cpp files
189                 #       4. make
190                 file(GLOB BINDING_SRC ${LQT_GEN_DIR}/*.cpp) 
191                 set(${COMMON}_SRC)
192                 list(REMOVE_ITEM BINDING_SRC ${LQT_GEN_DIR}/${BINDING_NAME}_merged_build.cpp)
193         else()                          
194                 set(${COMMON}_SRC ${${COMMON}_SRC}      ${${BINDING_NAME}_GENERATED})
195         endif()
197         qt4_wrap_cpp(${COMMON}_MOC ${LQT_GEN_DIR}/${BINDING_NAME}_slot.hpp)
198         
199         include_directories(${CMAKE_SOURCE_DIR}/common ${LUA_INCLUDE_DIRS} ${QT_INCLUDES})
201         add_library(${BINDING_NAME} SHARED  ${BINDING_SRC}
202                                                                                         ${${COMMON}_SRC}
203                                                                                         ${${COMMON}_HPP} 
204                                                                                         ${${COMMON}_MOC})
205                                                                                         
206         target_link_libraries(${BINDING_NAME} ${QT_LIBRARIES} ${LUA_LIBRARIES})         
207         set_target_properties(${BINDING_NAME} PROPERTIES PREFIX "")
209         if(LQT_BUILDIN_CPPTOXML)
210                 add_dependencies(generate_${BINDING_NAME}_xml  cpptoxml)
211         endif()
213         add_dependencies(generate_${BINDING_NAME}_cpp  generate_${BINDING_NAME}_xml ${${BINDING_NAME}_DEPENDS})
214         add_dependencies(${BINDING_NAME} generate_${BINDING_NAME}_cpp)
215         if(NOT SYSTEM_LUA)
216                 add_dependencies(generate_${BINDING_NAME}_cpp luaexec)
217         endif()
218 endfunction()
220 if(noqt)
221         include_directories(${CMAKE_CURRENT_SOURCE_DIR}/test/noqt)
222         build_qt_lib_binding(noqt)
223 else()
224         build_qt_lib_binding(QtCore)
225         build_qt_lib_binding(QtNetwork QtCore)
226         build_qt_lib_binding(QtGui QtNetwork QtCore)
227         build_qt_lib_binding(QtScript QtGui QtNetwork QtCore)
228         build_qt_lib_binding(QtOpenGL QtGui QtNetwork QtCore)
229         build_qt_lib_binding(QtSvg QtScript QtGui QtNetwork QtCore)
230         build_qt_lib_binding(QtXml QtSvg QtScript QtGui QtNetwork QtCore)
231         build_qt_lib_binding(QtXmlPatterns QtCore QtXml)
232         build_qt_lib_binding(QtUiTools QtCore QtGui QtXml) 
233         build_qt_lib_binding(QtWebKit QtXmlPatterns QtSvg QtScript QtOpenGL QtGui QtNetwork QtCore QtXml)
234         build_qt_lib_binding(QtSql QtCore)
235         # TODO
236         #build_qt_lib_binding(QtScriptTools) # 4.5 only
237         #build_qt_lib_binding(Phonon)
238 endif()