CMakeLists.txt 9.1 KB

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