CMakeLists.txt 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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")
  7. else()
  8. # Silence deprecation warnings
  9. add_definitions(/D_CRT_SECURE_NO_WARNINGS)
  10. # set up output paths for executable binaries (.exe-files, and .dll-files on DLL-capable platforms)
  11. set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
  12. # Tweak optimization settings
  13. # As far as I can tell, there's no way to override the CMake defaults while leaving user
  14. # changes intact, so we'll just clobber everything and say sorry.
  15. message(STATUS "Cache compiler flags ignored, please edit CMakeFiles.txt to change the flags.")
  16. # /MD - Multi-threaded runtime
  17. # /Ox - Full optimization
  18. # /Oi - Use intrinsic functions
  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 "/MD /Ox /Oi /Oy- /DNDEBUG /GR- /GS- /EHsc")
  24. # /Zi - Output debugging information
  25. # /Zo - enahnced debug info for optimized builds
  26. set(CMAKE_C_FLAGS_RELEASE "${optimization_flags} /Zi" CACHE STRING "" FORCE)
  27. set(CMAKE_CXX_FLAGS_RELEASE "${optimization_flags} /Zi" CACHE STRING "" FORCE)
  28. set(CMAKE_C_FLAGS_RELWITHDEBINFO "${optimization_flags} /Zi /Zo" CACHE STRING "" FORCE)
  29. set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${optimization_flags} /Zi /Zo" CACHE STRING "" FORCE)
  30. endif()
  31. add_definitions(-DSINGLETHREADED)
  32. find_package(PNG QUIET)
  33. if (PNG_FOUND)
  34. add_definitions(-DHAVE_PNG)
  35. else()
  36. message(STATUS "libpng not found. Some debugging features have been disabled.")
  37. endif()
  38. find_package(Boost)
  39. if (Boost_FOUND)
  40. include_directories(${Boost_INCLUDE_DIRS})
  41. else()
  42. message(STATUS "Boost not found, falling back to externals")
  43. include_directories(externals/boost)
  44. endif()
  45. # Include bundled CMake modules
  46. list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/externals/cmake-modules")
  47. find_package(OpenGL REQUIRED)
  48. include_directories(${OPENGL_INCLUDE_DIR})
  49. option(ENABLE_GLFW "Enable the GLFW frontend" ON)
  50. if (ENABLE_GLFW)
  51. if (WIN32)
  52. # Detect toolchain and platform
  53. if (MSVC)
  54. if (CMAKE_SIZEOF_VOID_P EQUAL 8)
  55. set(TMP_ARCH "x64")
  56. else()
  57. set(TMP_ARCH "Win32")
  58. endif()
  59. if (MSVC11) # Visual C++ 2012
  60. set(TMP_TOOLSET "v110")
  61. elseif (MSVC12) # Visual C++ 2013
  62. set(TMP_TOOLSET "v120")
  63. else()
  64. set(TMP_TOOLSET "UNSUPPORTED")
  65. message(SEND_ERROR "We don't supply GLFW binaries for your version of MSVC, you might have to provide them yourself.")
  66. endif()
  67. set(TMP_TOOLSET "msvc_${TMP_TOOLSET}-${TMP_ARCH}")
  68. else()
  69. # Assume mingw
  70. if (CMAKE_SIZEOF_VOID_P EQUAL 8)
  71. set(TMP_ARCH "x86_64")
  72. else()
  73. set(TMP_ARCH "i686")
  74. endif()
  75. set(TMP_TOOLSET "mingw-${TMP_ARCH}")
  76. endif()
  77. set(GLFW_PREFIX "${CMAKE_CURRENT_SOURCE_DIR}/externals/glfw-3.0.4.bin")
  78. set(GLFW_INCLUDE_DIRS "${GLFW_PREFIX}/include" CACHE PATH "Path to GLFW3 headers")
  79. set(GLFW_LIBRARY_DIRS "${GLFW_PREFIX}/lib-${TMP_TOOLSET}" CACHE PATH "Path to GLFW3 libraries")
  80. # Clean up after ourselves
  81. unset(TMP_TOOLSET)
  82. unset(TMP_ARCH)
  83. set(GLFW_LIBRARIES glfw3)
  84. else()
  85. if (NOT APPLE)
  86. find_package(X11 REQUIRED)
  87. endif()
  88. find_package(PkgConfig REQUIRED)
  89. pkg_search_module(GLFW REQUIRED glfw3)
  90. endif()
  91. include_directories(${GLFW_INCLUDE_DIRS})
  92. link_directories(${GLFW_LIBRARY_DIRS})
  93. endif()
  94. IF (APPLE)
  95. # CoreFoundation is required only on OSX
  96. FIND_LIBRARY(COREFOUNDATION_LIBRARY CoreFoundation)
  97. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
  98. set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -stdlib=libc++")
  99. ENDIF (APPLE)
  100. option(ENABLE_QT "Enable the Qt frontend" ON)
  101. option(CITRA_FORCE_QT4 "Use Qt4 even if Qt5 is available." OFF)
  102. if (ENABLE_QT)
  103. # Set CMAKE_PREFIX_PATH if QTDIR is defined in the environment This allows CMake to
  104. # automatically find the Qt packages on Windows
  105. if (DEFINED ENV{QTDIR})
  106. list(APPEND CMAKE_PREFIX_PATH "$ENV{QTDIR}")
  107. endif()
  108. if (NOT CITRA_FORCE_QT4)
  109. find_package(Qt5 COMPONENTS Widgets OpenGL)
  110. set(CITRA_QT_LIBS Qt5::Widgets Qt5::OpenGL)
  111. endif()
  112. if (CITRA_FORCE_QT4 OR NOT Qt5_FOUND)
  113. # Try to fallback to Qt4
  114. find_package(Qt4 REQUIRED COMPONENTS QtGui QtOpenGL)
  115. set(CITRA_QT_LIBS Qt4::QtGui Qt4::QtOpenGL)
  116. endif()
  117. endif()
  118. # This function should be passed a list of all files in a target. It will automatically generate
  119. # file groups following the directory hierarchy, so that the layout of the files in IDEs matches the
  120. # one in the filesystem.
  121. function(create_directory_groups)
  122. # Place any files that aren't in the source list in a separate group so that they don't get in
  123. # the way.
  124. source_group("Other Files" REGULAR_EXPRESSION ".")
  125. foreach(file_name ${ARGV})
  126. get_filename_component(dir_name "${file_name}" PATH)
  127. # Group names use '\' as a separator even though the entire rest of CMake uses '/'...
  128. string(REPLACE "/" "\\" group_name "${dir_name}")
  129. source_group("${group_name}" FILES "${file_name}")
  130. endforeach()
  131. endfunction()
  132. # generate git revision information
  133. include(GetGitRevisionDescription)
  134. get_git_head_revision(GIT_REF_SPEC GIT_REV)
  135. git_describe(GIT_DESC --always --long --dirty)
  136. git_branch_name(GIT_BRANCH)
  137. set(INI_PREFIX "${CMAKE_CURRENT_SOURCE_DIR}/externals/inih")
  138. include_directories(${INI_PREFIX})
  139. add_subdirectory(${INI_PREFIX})
  140. include_directories(externals/nihstro/include)
  141. # process subdirectories
  142. if(ENABLE_QT)
  143. include_directories(externals/qhexedit)
  144. add_subdirectory(externals/qhexedit)
  145. endif()
  146. add_subdirectory(src)