CMakeLists.txt 7.3 KB

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