CMakeLists.txt 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. # CMake 2.8.11 required for Qt5 settings to be applied automatically on
  2. # dependent libraries.
  3. cmake_minimum_required(VERSION 2.8.11)
  4. project(citra)
  5. if(NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.git/hooks/pre-commit)
  6. message(STATUS "Copying pre-commit hook")
  7. file(COPY hooks/pre-commit
  8. DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/.git/hooks
  9. FILE_PERMISSIONS WORLD_EXECUTE )
  10. endif()
  11. if (NOT MSVC)
  12. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wno-attributes -pthread")
  13. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pthread")
  14. else()
  15. # Silence "deprecation" warnings
  16. add_definitions(/D_CRT_SECURE_NO_WARNINGS /D_CRT_NONSTDC_NO_DEPRECATE)
  17. # Avoid windows.h junk
  18. add_definitions(/DNOMINMAX)
  19. # set up output paths for executable binaries (.exe-files, and .dll-files on DLL-capable platforms)
  20. set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
  21. set(CMAKE_CONFIGURATION_TYPES Debug Release CACHE STRING "" FORCE)
  22. # Tweak optimization settings
  23. # As far as I can tell, there's no way to override the CMake defaults while leaving user
  24. # changes intact, so we'll just clobber everything and say sorry.
  25. message(STATUS "Cache compiler flags ignored, please edit CMakeLists.txt to change the flags.")
  26. # /W3 - Level 3 warnings
  27. # /MP - Multi-threaded compilation
  28. # /Zi - Output debugging information
  29. # /Zo - enahnced debug info for optimized builds
  30. set(CMAKE_C_FLAGS "/W3 /MP /Zi /Zo" CACHE STRING "" FORCE)
  31. # /GR- - Disable RTTI
  32. # /EHsc - C++-only exception handling semantics
  33. set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} /GR- /EHsc" CACHE STRING "" FORCE)
  34. # /MDd - Multi-threaded Debug Runtime DLL
  35. set(CMAKE_C_FLAGS_DEBUG "/Od /MDd" CACHE STRING "" FORCE)
  36. set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}" CACHE STRING "" FORCE)
  37. # /O2 - Optimization level 2
  38. # /GS- - No stack buffer overflow checks
  39. # /MD - Multi-threaded runtime DLL
  40. set(CMAKE_C_FLAGS_RELEASE "/O2 /GS- /MD" CACHE STRING "" FORCE)
  41. set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}" CACHE STRING "" FORCE)
  42. set(CMAKE_EXE_LINKER_FLAGS_DEBUG "/DEBUG" CACHE STRING "" FORCE)
  43. set(CMAKE_EXE_LINKER_FLAGS_RELEASE "/DEBUG" CACHE STRING "" FORCE)
  44. endif()
  45. add_definitions(-DSINGLETHREADED)
  46. # CMake seems to only define _DEBUG on Windows
  47. set_property(DIRECTORY APPEND PROPERTY
  48. COMPILE_DEFINITIONS $<$<CONFIG:Debug>:_DEBUG> $<$<NOT:$<CONFIG:Debug>>:NDEBUG>)
  49. find_package(PNG QUIET)
  50. if (PNG_FOUND)
  51. add_definitions(-DHAVE_PNG)
  52. else()
  53. message(STATUS "libpng not found. Some debugging features have been disabled.")
  54. endif()
  55. find_package(Boost 1.57.0)
  56. if (Boost_FOUND)
  57. include_directories(${Boost_INCLUDE_DIRS})
  58. else()
  59. message(STATUS "Boost 1.57.0 or newer not found, falling back to externals")
  60. include_directories(externals/boost)
  61. endif()
  62. # Include bundled CMake modules
  63. list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/externals/cmake-modules")
  64. find_package(OpenGL REQUIRED)
  65. include_directories(${OPENGL_INCLUDE_DIR})
  66. option(ENABLE_GLFW "Enable the GLFW frontend" ON)
  67. if (ENABLE_GLFW)
  68. if (WIN32)
  69. # Detect toolchain and platform
  70. if (MSVC)
  71. if (CMAKE_SIZEOF_VOID_P EQUAL 8)
  72. set(TMP_ARCH "x64")
  73. elseif (CMAKE_SIZEOF_VOID_P EQUAL 4)
  74. set(TMP_ARCH "Win32")
  75. else()
  76. set(TMP_ARCH "UNKNOWN")
  77. message(SEND_ERROR "Couldn't detect your compiler's architecture, you'll have to manually specify the GLFW library to use. (Try checking CMakeOutput.log to find out why.)")
  78. endif()
  79. if (MSVC11) # Visual C++ 2012
  80. set(TMP_TOOLSET "v110")
  81. elseif (MSVC12) # Visual C++ 2013
  82. set(TMP_TOOLSET "v120")
  83. else()
  84. set(TMP_TOOLSET "UNSUPPORTED")
  85. message(SEND_ERROR "We don't supply GLFW binaries for your version of MSVC, you might have to provide them yourself.")
  86. endif()
  87. set(TMP_TOOLSET "msvc_${TMP_TOOLSET}-${TMP_ARCH}")
  88. else()
  89. # Assume mingw
  90. if (CMAKE_SIZEOF_VOID_P EQUAL 8)
  91. set(TMP_ARCH "x86_64")
  92. elseif (CMAKE_SIZEOF_VOID_P EQUAL 4)
  93. set(TMP_ARCH "i686")
  94. else()
  95. set(TMP_ARCH "UNKNOWN")
  96. message(SEND_ERROR "Couldn't detect your compiler's architecture, you'll have to manually specify the GLFW library to use.")
  97. endif()
  98. set(TMP_TOOLSET "mingw-${TMP_ARCH}")
  99. endif()
  100. set(GLFW_PREFIX "${CMAKE_CURRENT_SOURCE_DIR}/externals/glfw-3.1.1.bin")
  101. set(GLFW_INCLUDE_DIRS "${GLFW_PREFIX}/include" CACHE PATH "Path to GLFW3 headers")
  102. set(GLFW_LIBRARY_DIRS "${GLFW_PREFIX}/lib-${TMP_TOOLSET}" CACHE PATH "Path to GLFW3 libraries")
  103. # Clean up after ourselves
  104. unset(TMP_TOOLSET)
  105. unset(TMP_ARCH)
  106. set(GLFW_LIBRARIES glfw3)
  107. else()
  108. find_package(PkgConfig REQUIRED)
  109. pkg_search_module(GLFW REQUIRED glfw3)
  110. endif()
  111. include_directories(${GLFW_INCLUDE_DIRS})
  112. link_directories(${GLFW_LIBRARY_DIRS})
  113. endif()
  114. IF (APPLE)
  115. FIND_LIBRARY(COCOA_LIBRARY Cocoa) # Umbrella framework for everything GUI-related
  116. FIND_LIBRARY(IOKIT_LIBRARY IOKit) # GLFW dependency
  117. FIND_LIBRARY(COREVIDEO_LIBRARY CoreVideo) # GLFW dependency
  118. set(PLATFORM_LIBRARIES iconv ${COCOA_LIBRARY} ${IOKIT_LIBRARY} ${COREVIDEO_LIBRARY})
  119. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
  120. set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -stdlib=libc++")
  121. ELSEIF(MINGW)
  122. # GCC does not support codecvt, so use iconv instead
  123. set(PLATFORM_LIBRARIES winmm ws2_32 iconv)
  124. # WSAPoll functionality doesn't exist before WinNT 6.x (Vista and up)
  125. add_definitions(-D_WIN32_WINNT=0x0600)
  126. ELSEIF(WIN32)
  127. set(PLATFORM_LIBRARIES winmm ws2_32)
  128. ELSE()
  129. set(PLATFORM_LIBRARIES rt)
  130. ENDIF (APPLE)
  131. option(ENABLE_QT "Enable the Qt frontend" ON)
  132. option(CITRA_FORCE_QT4 "Use Qt4 even if Qt5 is available." OFF)
  133. if (ENABLE_QT)
  134. # Set CMAKE_PREFIX_PATH if QTDIR is defined in the environment This allows CMake to
  135. # automatically find the Qt packages on Windows
  136. if (DEFINED ENV{QTDIR})
  137. list(APPEND CMAKE_PREFIX_PATH "$ENV{QTDIR}")
  138. endif()
  139. if (NOT CITRA_FORCE_QT4)
  140. find_package(Qt5 COMPONENTS Widgets OpenGL)
  141. set(CITRA_QT_LIBS Qt5::Widgets Qt5::OpenGL)
  142. endif()
  143. if (CITRA_FORCE_QT4 OR NOT Qt5_FOUND)
  144. # Try to fallback to Qt4
  145. find_package(Qt4 REQUIRED COMPONENTS QtGui QtOpenGL)
  146. set(CITRA_QT_LIBS Qt4::QtGui Qt4::QtOpenGL)
  147. endif()
  148. endif()
  149. # This function should be passed a list of all files in a target. It will automatically generate
  150. # file groups following the directory hierarchy, so that the layout of the files in IDEs matches the
  151. # one in the filesystem.
  152. function(create_directory_groups)
  153. # Place any files that aren't in the source list in a separate group so that they don't get in
  154. # the way.
  155. source_group("Other Files" REGULAR_EXPRESSION ".")
  156. foreach(file_name ${ARGV})
  157. get_filename_component(dir_name "${file_name}" PATH)
  158. # Group names use '\' as a separator even though the entire rest of CMake uses '/'...
  159. string(REPLACE "/" "\\" group_name "${dir_name}")
  160. source_group("${group_name}" FILES "${file_name}")
  161. endforeach()
  162. endfunction()
  163. # generate git revision information
  164. include(GetGitRevisionDescription)
  165. get_git_head_revision(GIT_REF_SPEC GIT_REV)
  166. git_describe(GIT_DESC --always --long --dirty)
  167. git_branch_name(GIT_BRANCH)
  168. set(INI_PREFIX "${CMAKE_CURRENT_SOURCE_DIR}/externals/inih")
  169. include_directories(${INI_PREFIX})
  170. add_subdirectory(${INI_PREFIX})
  171. include_directories(externals/nihstro/include)
  172. if (MSVC)
  173. add_subdirectory(externals/getopt)
  174. endif()
  175. # process subdirectories
  176. if(ENABLE_QT)
  177. include_directories(externals/qhexedit)
  178. add_subdirectory(externals/qhexedit)
  179. endif()
  180. add_subdirectory(src)
  181. # Install freedesktop.org metadata files, following those specifications:
  182. # http://standards.freedesktop.org/desktop-entry-spec/desktop-entry-spec-latest.html
  183. # http://standards.freedesktop.org/icon-theme-spec/icon-theme-spec-latest.html
  184. # http://standards.freedesktop.org/shared-mime-info-spec/shared-mime-info-spec-latest.html
  185. if(${CMAKE_SYSTEM_NAME} MATCHES "Linux|FreeBSD|OpenBSD|NetBSD")
  186. install(FILES "${CMAKE_SOURCE_DIR}/dist/citra.desktop"
  187. DESTINATION "${CMAKE_INSTALL_PREFIX}/share/applications")
  188. install(FILES "${CMAKE_SOURCE_DIR}/dist/citra.svg"
  189. DESTINATION "${CMAKE_INSTALL_PREFIX}/share/pixmaps")
  190. install(FILES "${CMAKE_SOURCE_DIR}/dist/citra.xml"
  191. DESTINATION "${CMAKE_INSTALL_PREFIX}/share/mime/packages")
  192. endif()