CMakeLists.txt 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
  2. PROJECT(anki)
  3. #
  4. # Determin the system to build for. Do that first
  5. #
  6. if(WIN32)
  7. if(NOT WINDOWS)
  8. set(WINDOWS TRUE)
  9. message("++ Building for windows")
  10. endif()
  11. elseif(UNIX AND NOT APPLE)
  12. if(CMAKE_SYSTEM_NAME MATCHES ".*Linux")
  13. if(NOT ANDROID)
  14. set(LINUX TRUE)
  15. message("++ Building for Linux")
  16. else()
  17. message("++ Building for Android")
  18. endif()
  19. else()
  20. message(FATAL_ERROR "Unknown unix")
  21. endif()
  22. elseif(APPLE)
  23. if(CMAKE_SYSTEM_NAME MATCHES ".*MacOS.*")
  24. set(MACOS TRUE)
  25. message("++ Building for MacOS")
  26. else()
  27. message(FATAL_ERROR "Unknown apple")
  28. endif()
  29. else()
  30. message(FATAL_ERROR "Unknown system")
  31. endif()
  32. #
  33. # Configuration
  34. #
  35. set(ANKI_BUILD_TYPE "Release" CACHE STRING "Like CMAKE_BUILD_TYPE (Release or Debug)")
  36. option(ANKI_BUILD_TOOLS "Build tools" ON)
  37. option(ANKI_BUILD_TESTS "Build unit tests" OFF)
  38. option(ANKI_BUILD_TESTAPP "Build test application" ON)
  39. option(ANKI_BUILD_BENCH "Build benchmark application" OFF)
  40. option(ANKI_WITH_GPERFTOOLS_PROF "Link with gperftools profiler" OFF)
  41. option(ANKI_STRIP "Srip the symbols from the executables" OFF)
  42. option(ANKI_ENABLE_COUNTERS "Enable performance counters. Small overhead" OFF)
  43. if(ANKI_ENABLE_COUNTERS)
  44. set(_ANKI_ENABLE_COUNTERS 1)
  45. else()
  46. set(_ANKI_ENABLE_COUNTERS 0)
  47. endif()
  48. # Address space
  49. set(ANKI_CPU_ADDR_SPACE "0" CACHE STRING "The CPU architecture (0 or 32 or 64). If zero go native")
  50. # SIMD
  51. option(ANKI_ENABLE_SIMD "Enable or not SIMD optimizations" ON)
  52. if(ANKI_ENABLE_SIMD)
  53. set(_ANKI_ENABLE_SIMD 1)
  54. else()
  55. set(_ANKI_ENABLE_SIMD 0)
  56. endif()
  57. # Take a wild guess on the windowing system
  58. if(LINUX)
  59. #set(_WIN_BACKEND "GLXX11")
  60. set(_WIN_BACKEND "SDL")
  61. elseif(WINDOWS)
  62. set(_WIN_BACKEND "SDL")
  63. elseif(ANDROID)
  64. set(_WIN_BACKEND "ANDROID")
  65. elseif(MACOS)
  66. set(_WIN_BACKEND "SDL")
  67. else()
  68. message(FATAL_ERROR "Couldn't determine the window backend. You need to specify it manually")
  69. endif()
  70. set(ANKI_WINDOW_BACKEND "${_WIN_BACKEND}" CACHE STRING "The window backend (GLXX11 or EGLX11 or EGLFBDEV or ANDROID or SDL or DUMMY)")
  71. option(ANKI_GCC_TO_STRING_WORKAROUND "Enable workaround for C++11 GCC bug" OFF)
  72. if(ANKI_GCC_TO_STRING_WORKAROUND)
  73. set(_ANKI_GCC_TO_STRING_WORKAROUND 1)
  74. else()
  75. set(_ANKI_GCC_TO_STRING_WORKAROUND 0)
  76. endif()
  77. # Extra directories
  78. set(ANKI_EXTRA_INCLUDE_DIRS CACHE STRING "Some extra include paths (Needed for some weird builds)")
  79. set(ANKI_EXTRA_LIB_DIRS CACHE STRING "Some extra lib paths (Needed for some weird builds)")
  80. # Valgrind
  81. option(ANKI_VALGRIND_HAPPY "Make valgrind happy" OFF)
  82. #
  83. # Options that affect anki and extern
  84. #
  85. set(CXX_FLAGS "")
  86. set(COMPILER_FLAGS "")
  87. set(LINKER_FLAGS "")
  88. # address space
  89. if(NOT ANKI_CPU_ADDR_SPACE STREQUAL "0")
  90. set(LINKER_FLAGS "${LINKER_FLAGS} -m${ANKI_CPU_ADDR_SPACE} ")
  91. set(COMPILER_FLAGS "${COMPILER_FLAGS} -m${ANKI_CPU_ADDR_SPACE} ")
  92. endif()
  93. # static libstdc++
  94. set(CXX_FLAGS "${CXX_FLAGS} -static-libstdc++ ")
  95. # SSE
  96. if(LINUX OR MACOS OR WINDOWS)
  97. set(COMPILER_FLAGS "${COMPILER_FLAGS} -msse4 ")
  98. else()
  99. set(COMPILER_FLAGS "${COMPILER_FLAGS} -mfpu=neon ")
  100. endif()
  101. if(${ANKI_BUILD_TYPE} STREQUAL "Debug")
  102. # Debug
  103. set(COMPILER_FLAGS "${COMPILER_FLAGS} -g3 -O0 ")
  104. else()
  105. # Release
  106. # -flto ?
  107. set(COMPILER_FLAGS "${COMPILER_FLAGS} -ffast-math -O4 -DNODEBUG ")
  108. # Add this because Android compiler complains
  109. if(ANDROID)
  110. set(COMPILER_FLAGS "${COMPILER_FLAGS} -fno-data-sections ")
  111. endif()
  112. set(CXX_FLAGS "${CXX_FLAGS} -fno-rtti ")
  113. endif()
  114. # Valgrind hacks
  115. if(ANKI_VALGRIND_HAPPY)
  116. add_definitions("-DGLIBCXX_FORCE_NEW")
  117. endif()
  118. # Disable GLU in GLEW
  119. add_definitions(-DGLEW_NO_GLU)
  120. # Strip
  121. if(ANKI_STRIP)
  122. set(LINKER_FLAGS "${LINKER_FLAGS} -s ")
  123. set(COMPILER_FLAGS "${COMPILER_FLAGS} -s ")
  124. endif()
  125. # gperftools
  126. if(ANKI_WITH_GPERFTOOLS_PROF)
  127. LINK_DIRECTORIES("/home/godlike/src/more/gperftools/install/lib")
  128. set(ANKI_GPERFTOOLS_LIBS "profiler")
  129. else()
  130. set(ANKI_GPERFTOOLS_LIBS "")
  131. endif()
  132. include_directories(${ANKI_EXTRA_INCLUDE_DIRS})
  133. link_directories(${ANKI_EXTRA_LIB_DIRS})
  134. # Set the flags to cmake now
  135. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CXX_FLAGS} ${COMPILER_FLAGS}")
  136. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${COMPILER_FLAGS}")
  137. set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${LINKER_FLAGS}")
  138. #
  139. # Install
  140. #
  141. set(INCLUDE_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/include/" CACHE PATH "The subdirectory to the header prefix")
  142. set(LIB_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/lib" CACHE PATH "Library install path")
  143. message("++ Include install dir: ${INCLUDE_INSTALL_DIR}")
  144. message("++ Lib install dir: ${LIB_INSTALL_DIR}")
  145. #
  146. # First the extern
  147. #
  148. add_subdirectory(extern)
  149. #
  150. # Doxygen
  151. #
  152. find_package(Doxygen)
  153. if(DOXYGEN_FOUND)
  154. configure_file(${CMAKE_CURRENT_SOURCE_DIR}/docs/doxyfile ${CMAKE_CURRENT_BINARY_DIR}/doxyfile @ONLY)
  155. add_custom_target(doc ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/doxyfile WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
  156. COMMENT "Generating API documentation with Doxygen" VERBATIM)
  157. endif()
  158. #
  159. # Revision
  160. #
  161. find_package(Subversion 1.6)
  162. if(Subversion_FOUND)
  163. Subversion_WC_INFO(${CMAKE_CURRENT_SOURCE_DIR} ER)
  164. set(ANKI_REVISION ${ER_WC_REVISION})
  165. else()
  166. set(ANKI_REVISION "-1")
  167. endif()
  168. #
  169. # Config.h
  170. #
  171. set(ANKI_VERSION_MAJOR 0)
  172. set(ANKI_VERSION_MINOR 1)
  173. message("++ AnKi version: ${ANKI_VERSION_MAJOR}.${ANKI_VERSION_MINOR}")
  174. if(${ANKI_BUILD_TYPE} STREQUAL "Debug")
  175. set(ANKI_DEBUG 1)
  176. else()
  177. set(ANKI_DEBUG 0)
  178. endif()
  179. CONFIGURE_FILE("include/anki/Config.h.cmake" "${CMAKE_CURRENT_BINARY_DIR}/anki/Config.h")
  180. INSTALL(FILES "${CMAKE_CURRENT_BINARY_DIR}/anki/Config.h" DESTINATION "${INCLUDE_INSTALL_DIR}/anki")
  181. #
  182. # Include & lib directories
  183. #
  184. include_directories("extern/tinyxml2/include" "extern/lua" "extern/z" "extern/bullet" "extern/SDL2/include" "include" "${CMAKE_CURRENT_BINARY_DIR}")
  185. if(LINUX OR MACOS OR WINDOWS)
  186. include_directories("extern/GLEW/include")
  187. else()
  188. #include_directories("extern/GLES3/include")
  189. endif()
  190. if(ANDROID)
  191. include_directories("${ANDROID_NDK}/sources/android/native_app_glue")
  192. endif()
  193. #
  194. # AnKi specific compiler flags
  195. #
  196. # thread local
  197. add_definitions("-Dthread_local=__thread")
  198. # AnKi compiler flags (Mainly warnings)
  199. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic -Wall -W -Wextra -Wwrite-strings -Wunused -Wunused-variable -Wno-unused-parameter -Wundef -std=c++11 ")
  200. #
  201. # Add anki related dirs
  202. #
  203. add_subdirectory(src)
  204. if(ANKI_BUILD_TESTS)
  205. ENABLE_TESTING()
  206. add_subdirectory(tests)
  207. endif()
  208. if(ANKI_BUILD_TOOLS)
  209. add_subdirectory(tools)
  210. endif()
  211. if(ANKI_BUILD_TESTAPP)
  212. add_subdirectory(testapp)
  213. endif()
  214. if(ANKI_BUILD_BENCH)
  215. add_subdirectory(bench)
  216. endif()
  217. #
  218. # XXX
  219. #
  220. if(${ANDROID})
  221. # 1. generate Android.mk
  222. FILE(WRITE ./jni/Android.mk "APP_ABI := ${ANDROID_NDK_ABI_NAME}\n")
  223. # 2. generate gdb.setup
  224. GET_DIRECTORY_PROPERTY(include_directories DIRECTORY . include_directories)
  225. STRING(REGEX REPLACE ";" " " include_directories "${include_directories}")
  226. FILE(WRITE ./libs/${ANDROID_NDK_ABI_NAME}/gdb.setup "set solib-search-path ./libs/${ANDROID_NDK_ABI_NAME}\n")
  227. FILE(APPEND ./libs/${ANDROID_NDK_ABI_NAME}/gdb.setup "directory ${include_directories} ${CMAKE_CURRENT_SOURCE_DIR}/src ${CMAKE_CURRENT_SOURCE_DIR}\n")
  228. # 3. copy gdbserver executable
  229. FILE(COPY ${ANDROID_NDK}/prebuilt/android-arm/gdbserver/gdbserver DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/libs/${ANDROID_NDK_ABI_NAME}/)
  230. set(LIBRARY_NAME ankibench)
  231. # 4. copy lib to obj
  232. #ADD_CUSTOM_COMMAND(TARGET ${LIBRARY_NAME} POST_BUILD COMMAND mkdir -p ./obj/local/${ANDROID_NDK_ABI_NAME}/)
  233. #ADD_CUSTOM_COMMAND(TARGET ${LIBRARY_NAME} POST_BUILD COMMAND cp ./libs/${ANDROID_NDK_ABI_NAME}/lib${LIBRARY_NAME}.so ./obj/local/${ANDROID_NDK_ABI_NAME}/)
  234. endif()