CMakeLists.txt 7.6 KB

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