comment out unused code
[lqt.git] / CMakeLists.txt
blobffb74743dd50e86d683e4ce2ff896626729a3282
1 #  Copyright (c) 2008 Peter Kuemmel 
2 #  
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
10 #  conditions:
11 #  
12 #  The above copyright notice and this permission notice shall be
13 #  included in all copies or substantial portions of the Software.
14 #  
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)
26 project(lqt)
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)
35 set(QT_USE_QTCORE 1)
36 set(QT_USE_QTGUI 1)
37 set(QT_USE_QTNETWORK 1)
38 set(QT_USE_QTWEBKIT 1)
39 set(QT_USE_QTOPENGL 1)
40 set(QT_USE_QTSCRIPT 1)
41 set(QT_USE_QTSVG 1)
42 set(QT_USE_QTXML 1)
43 #set(QT_USE_QTSQL 1)
44 #set(QT_USE_QTXMLPATTERNS 1)
45 include(${QT_USE_FILE})
47 if(SYSTEM_LUA)
48         find_package(Lua51 REQUIRED)
49         set(LUA_CMD lua)
50 else()
51         add_subdirectory(lua)
52         set(LUA_CMD luaexec)
53         set(LUA_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/lua/lua/src)
54         set(LUA_LIBRARIES lua)
55 endif()
57 if(MSVC)
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)
61 endif()
63 if(MINGW)
64         set(CMAKE_SHARED_LINKER_FLAGS "-Wl,-add-stdcall-alias")
65         SET(CMAKE_VERBOSE_MAKEFILE ON)
66 endif()
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)
78 endmacro()
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) 
90         else() 
91                 if(NOT ${mode} MATCHES "split") 
92                         source_group("${mode}" FILES ${${sources}} ${${headers}}) 
93                 endif() 
94         endif() 
95 endmacro()
96 set(GROUP_CODE "Source Files")
98 set(LQT_BUILDIN_CPPTOXML 1)
99 if(LQT_BUILDIN_CPPTOXML)
100         add_subdirectory(cpptoxml)
101 else()
102 #TODO find cpptpxml
103 endif()
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)
117         if (UNIX)
118                 set (PP_CONFIG ${CMAKE_SOURCE_DIR}/cpptoxml/parser/rpp/pp-qt-configuration)
119         else()
120                 set (PP_CONFIG ${CMAKE_SOURCE_DIR}/cpptoxml/parser/rpp/pp-qt-configuration-win)
121         endif()
123         set (GEN_XML ${LQT_GEN_DIR}/${BINDING_NAME}.xml)
124         add_custom_target(generate_${BINDING_NAME}_xml  COMMAND cpptoxml 
125                                                         ${BINDING_HEADER} 
126                                                         -C ${PP_CONFIG}
127                                                         -Q ${QT_INCLUDE_DIR} 
128                                                         -o ${GEN_XML}
129                                                 COMMENT "Generating XML: running cpptoxml on ${BINDING_NAME} "
130                                                 VERBATIM)
133         add_custom_target(generate_${BINDING_NAME}_cpp  COMMAND cmake -E copy_directory ${CMAKE_SOURCE_DIR}/common ${LQT_GEN_DIR}
134                                                 COMMAND ${LUA_CMD}
135                                                         "${CMAKE_SOURCE_DIR}/generator/generator.lua" 
136                                                         ${GEN_XML} 
137                                                         -i ${BINDING_HEADER} -i lqt_qt.hpp 
138                                                         -n ${BINDING_NAME} 
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"
143                                                 VERBATIM)
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) 
148         
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)
153                                                                         
154         set(${COMMON}_SRC ${${COMMON}_SRC}      ${${BINDING_NAME}_GENERATED})
155         qt4_wrap_cpp(${COMMON}_MOC ${LQT_GEN_DIR}/${BINDING_NAME}_slot.hpp)
156         
157         include_directories(${CMAKE_SOURCE_DIR}/common ${LUA_INCLUDE_DIRS} ${QT_INCLUDES})
159         add_library(${BINDING_NAME} SHARED  ${BINDING_SRC}
160                                                                                         ${${COMMON}_SRC}
161                                                                                         ${${COMMON}_HPP} 
162                                                                                         ${${COMMON}_MOC})
163                                                                                         
164         target_link_libraries(${BINDING_NAME} ${QT_LIBRARIES} ${LUA_LIBRARIES})         
166         if(LQT_BUILDIN_CPPTOXML)
167                 add_dependencies(generate_${BINDING_NAME}_xml  cpptoxml)
168     endif()     
169         add_dependencies(generate_${BINDING_NAME}_cpp  generate_${BINDING_NAME}_xml)
170         add_dependencies(${BINDING_NAME} generate_${BINDING_NAME}_cpp)
171         if(NOT SYSTEM_LUA)
172                 add_dependencies(generate_${BINDING_NAME}_cpp luaexec)
173         endif()
174 endmacro()
176 if(MSVC)
177                 add_definitions(-D_CRT_SECURE_NO_DEPRECATE)
178 endif()
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)
190 # needs testing
191 #build_qt_lib_binding(QtSql)
192 #build_qt_lib_binding(QtXmlPatterns)
193 #build_qt_lib_binding(Phonon)