CMakeLists.txt 8.5 KB

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