CMakeLists.txt 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. # Normally, this is not a toplevel CMakeLists.txt file. Except when it is
  2. # used in combination with the Windows SDK, then it is prefixed with the
  3. # required configuration settings to allow building the examples of the
  4. # binary Wt distribution as a standalone project.
  5. #
  6. # This CMakeLists.txt is complex because it supports all different modes
  7. # of building Wt on all supported platforms. Your own CMakeLists.txt can
  8. # be much simpler. For example (for Windows):
  9. #
  10. # CMAKE_MINIMUM_REQUIRED(VERSION 2.4)
  11. # Project(myproject)
  12. #
  13. # INCLUDE_DIRECTORIES(c:/wt-installation-path/include)
  14. # LINK_DIRECTORIES(c:/wt-installation-path/lib)
  15. #
  16. # ADD_DEFINITIONS(-DHPDF_DLL)
  17. #
  18. # ADD_EXECUTABLE(myprog.wt
  19. # MyProg1.cpp
  20. # OtherFile.cpp
  21. # AndEvenMoreCode.cpp
  22. # )
  23. #
  24. # TARGET_LINK_LIBRARIES(myprog.wt
  25. # debug wtd optimized wt
  26. # debug wthttpd optimized wthttp
  27. # debug libhpdfd optimized libhpdf # only required for if you write pdfs
  28. # )
  29. IF("${CMAKE_CURRENT_LIST_DIR}" STREQUAL "${CMAKE_SOURCE_DIR}")
  30. IF(WIN32)
  31. # preamble to make this a toplevel CMakeLists.txt for Windows, intended
  32. # for being used
  33. CMAKE_MINIMUM_REQUIRED(VERSION 2.4)
  34. Project(WtExamples)
  35. # build widgetgallery, if supported
  36. IF(MSVC_VERSION GREATER 1600)
  37. SET(HAS_CXX11 ON)
  38. ENDIF(MSVC_VERSION GREATER 1600)
  39. SET(EXAMPLES_CONNECTOR
  40. debug wthttpd optimized wthttp
  41. debug libhpdfd optimized libhpdf
  42. )
  43. INCLUDE_DIRECTORIES($(CMAKE_SOURCE_DIR)/../../../include)
  44. LINK_DIRECTORIES(${CMAKE_SOURCE_DIR}/../../../lib)
  45. # We ship libharu as DLL. Compiling/linking against libharu DLL requires
  46. # this definition to be set.
  47. ADD_DEFINITIONS(-DHPDF_DLL)
  48. ENDIF(WIN32)
  49. ENDIF("${CMAKE_CURRENT_LIST_DIR}" STREQUAL "${CMAKE_SOURCE_DIR}")
  50. # Normal example CMakeLists.txt starts here
  51. IF(BOOST_WT_MT_FOUND)
  52. IF(MULTI_THREADED)
  53. ADD_DEFINITIONS(-D_REENTRANT -DBOOST_SPIRIT_THREADSAFE)
  54. ELSE(MULTI_THREADED)
  55. ADD_DEFINITIONS(-DBOOST_DISABLE_THREADS)
  56. ENDIF(MULTI_THREADED)
  57. ELSE(BOOST_WT_MT_FOUND)
  58. ADD_DEFINITIONS(-DBOOST_DISABLE_THREADS)
  59. ENDIF(BOOST_WT_MT_FOUND)
  60. ADD_DEFINITIONS(-DWT_DEPRECATED_3_0_0)
  61. # The WT_ADD_EXAMPLE function builds a DLL in case of ISAPI, and an executable
  62. # in case of FCGI or HTTPD connectors. It also makes sure that the example
  63. # links to the proper libraries (connector + wt).
  64. MACRO(WT_ADD_EXAMPLE name)
  65. IF(EXAMPLES_CONNECTOR MATCHES "wtisapi")
  66. SET(MYLIST ${ARGV})
  67. LIST(INSERT MYLIST 1 SHARED)
  68. ADD_LIBRARY(${MYLIST})
  69. SET_TARGET_PROPERTIES(${name}
  70. PROPERTIES
  71. LINK_FLAGS
  72. "/EXPORT:HttpExtensionProc /EXPORT:GetExtensionVersion /EXPORT:TerminateExtension"
  73. )
  74. ELSE(EXAMPLES_CONNECTOR MATCHES "wtisapi")
  75. ADD_EXECUTABLE(${ARGV})
  76. ENDIF(EXAMPLES_CONNECTOR MATCHES "wtisapi")
  77. if(ANDROID)
  78. set(WT_ANDROID plaforms/android/wt-android)
  79. make_directory(${CMAKE_CURRENT_BINARY_DIR}/wt-android)
  80. make_directory(${CMAKE_CURRENT_BINARY_DIR}/wt-android/libs/armeabi)
  81. SET(MYLIST ${ARGV})
  82. LIST(INSERT MYLIST 1 SHARED)
  83. ADD_LIBRARY(${MYLIST})
  84. set_target_properties(${name} PROPERTIES
  85. LIBRARY_OUTPUT_DIRECTORY
  86. "${CMAKE_CURRENT_BINARY_DIR}/wt-android/libs/armeabi"
  87. OUTPUT_NAME
  88. wt-jni)
  89. string(REPLACE ".wt" "" APP_NAME ${name})
  90. string(LENGTH ${APP_NAME} APP_NAME_LENGTH)
  91. math(EXPR APP_NAME_LENGTH_MINUS_ONE "${APP_NAME_LENGTH} - 1")
  92. string(SUBSTRING ${APP_NAME} 0 1 APP_NAME_BEGIN)
  93. string(TOUPPER ${APP_NAME_BEGIN} APP_NAME_BEGIN_UPPER)
  94. string(SUBSTRING ${APP_NAME} 1 ${APP_NAME_LENGTH_MINUS_ONE} APP_NAME_END)
  95. set(APP_NAME "Wt${APP_NAME_BEGIN_UPPER}${APP_NAME_END}")
  96. make_directory(${CMAKE_CURRENT_BINARY_DIR}/wt-android/assets)
  97. set(WT_ANDROID target/android/wt-android)
  98. configure_file(${WT_SOURCE_DIR}/${WT_ANDROID}/src/eu/webtoolkit/android/WtAndroid.java
  99. ${CMAKE_CURRENT_BINARY_DIR}/wt-android/src/eu/webtoolkit/android/WtAndroid.java)
  100. make_directory(${CMAKE_CURRENT_BINARY_DIR}/wt-android/src/eu/webtoolkit/android/${APP_NAME}/)
  101. configure_file("${WT_SOURCE_DIR}/${WT_ANDROID}/src/eu/webtoolkit/android/WtExample.java.template"
  102. ${CMAKE_CURRENT_BINARY_DIR}/wt-android/src/eu/webtoolkit/android/${APP_NAME}/${APP_NAME}.java)
  103. make_directory(${CMAKE_CURRENT_BINARY_DIR}/wt-android/res)
  104. FILE(COPY ${WT_SOURCE_DIR}/${WT_ANDROID}/utils.xml
  105. DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/wt-android)
  106. configure_file("${WT_SOURCE_DIR}/${WT_ANDROID}/AndroidManifest.xml.template"
  107. ${CMAKE_CURRENT_BINARY_DIR}/wt-android/AndroidManifest.xml)
  108. add_custom_command(TARGET ${name}
  109. POST_BUILD
  110. COMMAND ant -f ${CMAKE_CURRENT_BINARY_DIR}/wt-android/utils.xml
  111. -Dwt.dir=${WT_SOURCE_DIR} -Dexample.dir=${CMAKE_CURRENT_SOURCE_DIR}
  112. -Dwt-android.dir=${CMAKE_CURRENT_BINARY_DIR}/wt-android/)
  113. IF(NOT DEFINED ANDROID_STRIP)
  114. MESSAGE(" Warning!!! ANDROID_STRIP is not defined!")
  115. MESSAGE(" Warning!!! The so file will not be stripped and your android")
  116. MESSAGE(" package might be too large to fit on the target")
  117. MESSAGE(" device!")
  118. ELSE(NOT DEFINED ANDROID_STRIP)
  119. add_custom_command(TARGET ${name}
  120. POST_BUILD
  121. COMMAND ${ANDROID_STRIP}
  122. "${CMAKE_CURRENT_BINARY_DIR}/wt-android/libs/armeabi/*")
  123. ENDIF(NOT DEFINED ANDROID_STRIP)
  124. add_custom_command(TARGET ${name}
  125. POST_BUILD
  126. COMMAND ${ANDROID_SDK_DIR}/tools/android update project
  127. --name wt-android --target ${ANDROID_SDK_TARGET_ID}
  128. --path ${CMAKE_CURRENT_BINARY_DIR}/wt-android/)
  129. add_custom_command(TARGET ${name}
  130. POST_BUILD
  131. COMMAND ant -f ${CMAKE_CURRENT_BINARY_DIR}/wt-android/build.xml debug)
  132. ENDIF(ANDROID)
  133. IF(MSVC)
  134. SET_TARGET_PROPERTIES(${name} PROPERTIES COMPILE_FLAGS "/W3 /Wp64 /wd4251 /wd4275")
  135. ENDIF(MSVC)
  136. TARGET_LINK_LIBRARIES(${name} ${EXAMPLES_CONNECTOR} wt)
  137. IF(INSTALL_EXAMPLES)
  138. # Finding the directory where to install the binary and the wrapper/runner script is tricky
  139. # because examples do not use project(...), or there is more than one example in one subdirectory
  140. SET( ${name}_SOURCEFILES ${ARGV} )
  141. LIST( REMOVE_AT ${name}_SOURCEFILES 0 )
  142. LIST(GET ${name}_SOURCEFILES 0 ${name}_FIRST_SOURCEFILE )
  143. GET_SOURCE_FILE_PROPERTY(${name}_FIRST_SOURCEFILE_FULLPATH ${${name}_FIRST_SOURCEFILE} LOCATION)
  144. STRING(REPLACE ${WT_SOURCE_DIR}/examples/ "" ${name}_SUBDIRANDSOURCE ${${name}_FIRST_SOURCEFILE_FULLPATH})
  145. STRING(REPLACE /${${name}_FIRST_SOURCEFILE} "" ${name}_SUBDIR ${${name}_SUBDIRANDSOURCE})
  146. SET( EXAMPLESUBDIR ${${name}_SUBDIR} )
  147. SET( EXAMPLESUBDIRFROMPREFIX ${EXAMPLES_DESTINATION}/${EXAMPLESUBDIR} )
  148. STRING( REPLACE .wt "" EXAMPLENAME ${name} )
  149. SET(DOCROOTSUBFOLDER)
  150. SET(_${EXAMPLENAME}_POTENTIAL_DOCROOTSUBFOLDER ${WT_SOURCE_DIR}/examples/${EXAMPLESUBDIR}/docroot)
  151. IF(EXISTS ${_${EXAMPLENAME}_POTENTIAL_DOCROOTSUBFOLDER})
  152. SET(DOCROOTSUBFOLDER docroot)
  153. ENDIF(EXISTS ${_${EXAMPLENAME}_POTENTIAL_DOCROOTSUBFOLDER})
  154. SET(APPROOTSUBFOLDER)
  155. SET(_${EXAMPLENAME}_POTENTIAL_APPROOTSUBFOLDER ${WT_SOURCE_DIR}/examples/${EXAMPLESUBDIR}/approot)
  156. IF(EXISTS ${_${EXAMPLENAME}_POTENTIAL_APPROOTSUBFOLDER})
  157. SET(APPROOTSUBFOLDER approot)
  158. ENDIF(EXISTS ${_${EXAMPLENAME}_POTENTIAL_APPROOTSUBFOLDER})
  159. INSTALL( TARGETS ${name} DESTINATION ${EXAMPLES_DESTINATION}/${${name}_SUBDIR} )
  160. IF(WIN32)
  161. SET(SCRIPT_DOCROOT "--docroot .")
  162. IF(DOCROOTSUBFOLDER)
  163. SET(SCRIPT_DOCROOT "--docroot ${DOCROOTSUBFOLDER}")
  164. ENDIF(DOCROOTSUBFOLDER)
  165. SET(SCRIPT_APPROOT "")
  166. IF(APPROOTSUBFOLDER)
  167. SET(SCRIPT_APPROOT "--approot ${APPROOTSUBFOLDER}")
  168. ENDIF(APPROOTSUBFOLDER)
  169. CONFIGURE_FILE(${WT_SOURCE_DIR}/examples/run-example.bat.cmake ${WT_BINARY_DIR}/examples/${EXAMPLESUBDIR}/${EXAMPLENAME}.bat @ONLY)
  170. INSTALL(PROGRAMS ${WT_BINARY_DIR}/examples/${EXAMPLESUBDIR}/${EXAMPLENAME}.bat DESTINATION bin )
  171. IF(INSTALL_RESOURCES)
  172. INSTALL(DIRECTORY ${WT_SOURCE_DIR}/resources DESTINATION ${EXAMPLES_DESTINATION}/${EXAMPLESUBDIR}/${DOCROOTSUBFOLDER}) # Can't safely make symlinks of Windows
  173. ENDIF(INSTALL_RESOURCES)
  174. ELSE(WIN32)
  175. CONFIGURE_FILE(${WT_SOURCE_DIR}/examples/run-example.cmake ${WT_BINARY_DIR}/examples/${EXAMPLESUBDIR}/${EXAMPLENAME} @ONLY)
  176. INSTALL(PROGRAMS ${WT_BINARY_DIR}/examples/${EXAMPLESUBDIR}/${EXAMPLENAME} DESTINATION ${EXAMPLES_DESTINATION}/${EXAMPLESUBDIR})
  177. IF(INSTALL_RESOURCES)
  178. INSTALL( CODE "EXECUTE_PROCESS(COMMAND ${CMAKE_COMMAND} -E create_symlink ${CMAKE_INSTALL_PREFIX}/share/Wt/resources ${CMAKE_INSTALL_PREFIX}/${EXAMPLES_DESTINATION}/${EXAMPLESUBDIR}/resources)" )
  179. ENDIF(INSTALL_RESOURCES)
  180. ENDIF(WIN32)
  181. ENDIF(INSTALL_EXAMPLES)
  182. ENDMACRO(WT_ADD_EXAMPLE)
  183. SUBDIRS(
  184. blog
  185. charts
  186. codeview
  187. composer
  188. dialog
  189. dragdrop
  190. feature
  191. filetreetable
  192. filedrop
  193. form
  194. gitmodel
  195. hangman
  196. hello
  197. javascript
  198. mandelbrot
  199. mission
  200. onethread
  201. painting
  202. planner
  203. qrlogin
  204. simplechat
  205. style
  206. treelist
  207. treeview
  208. treeview-dragdrop
  209. webgl
  210. wt-homepage
  211. wtwithqt
  212. )
  213. IF(HAS_CXX11)
  214. SUBDIRS(
  215. chart3D
  216. widgetgallery
  217. )
  218. ELSE(HAS_CXX11)
  219. MESSAGE("*** Not building widget gallery; C++11 required (gcc > 4.6 + set WT_CPP_11_MODE=-std=c++0x or MSVS >= 2012)")
  220. ENDIF(HAS_CXX11)