CMakeLists.txt 6.5 KB

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