CMakeLists.txt 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. endif()
  11. add_definitions(-DSINGLETHREADED)
  12. find_package(PNG)
  13. if (PNG_FOUND)
  14. add_definitions(-DHAVE_PNG)
  15. endif ()
  16. # Include bundled CMake modules
  17. list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/externals/cmake-modules")
  18. find_package(OpenGL REQUIRED)
  19. include_directories(${OPENGL_INCLUDE_DIR})
  20. option(ENABLE_GLFW "Enable the GLFW frontend" ON)
  21. if (ENABLE_GLFW)
  22. if (WIN32)
  23. # Detect toolchain and platform
  24. if (MSVC)
  25. if (CMAKE_SIZEOF_VOID_P EQUAL 8)
  26. set(TMP_ARCH "x64")
  27. else()
  28. set(TMP_ARCH "Win32")
  29. endif()
  30. if (MSVC11) # Visual C++ 2012
  31. set(TMP_TOOLSET "v110")
  32. elseif (MSVC12) # Visual C++ 2013
  33. set(TMP_TOOLSET "v120")
  34. else()
  35. set(TMP_TOOLSET "UNSUPPORTED")
  36. message(SEND_ERROR "We don't supply GLFW binaries for your version of MSVC, you might have to provide them yourself.")
  37. endif()
  38. set(TMP_TOOLSET "msvc_${TMP_TOOLSET}-${TMP_ARCH}")
  39. else()
  40. # Assume mingw
  41. if (CMAKE_SIZEOF_VOID_P EQUAL 8)
  42. set(TMP_ARCH "x86_64")
  43. else()
  44. set(TMP_ARCH "i686")
  45. endif()
  46. set(TMP_TOOLSET "mingw-${TMP_ARCH}")
  47. endif()
  48. set(GLFW_PREFIX "${CMAKE_CURRENT_SOURCE_DIR}/externals/glfw-3.0.4.bin")
  49. set(GLFW_INCLUDE_DIRS "${GLFW_PREFIX}/include" CACHE PATH "Path to GLFW3 headers")
  50. set(GLFW_LIBRARY_DIRS "${GLFW_PREFIX}/lib-${TMP_TOOLSET}" CACHE PATH "Path to GLFW3 libraries")
  51. # Clean up after ourselves
  52. unset(TMP_TOOLSET)
  53. unset(TMP_ARCH)
  54. set(GLFW_LIBRARIES glfw3)
  55. else()
  56. find_package(X11 REQUIRED)
  57. find_package(PkgConfig REQUIRED)
  58. pkg_search_module(GLFW REQUIRED glfw3)
  59. endif()
  60. include_directories(${GLFW_INCLUDE_DIRS})
  61. link_directories(${GLFW_LIBRARY_DIRS})
  62. endif()
  63. IF (APPLE)
  64. # CoreFoundation is required only on OSX
  65. FIND_LIBRARY(COREFOUNDATION_LIBRARY CoreFoundation)
  66. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
  67. set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -stdlib=libc++")
  68. ENDIF (APPLE)
  69. option(ENABLE_QT "Enable the Qt frontend" ON)
  70. option(CITRA_FORCE_QT4 "Use Qt4 even if Qt5 is available." OFF)
  71. if (ENABLE_QT)
  72. # Set CMAKE_PREFIX_PATH if QTDIR is defined in the environment This allows CMake to
  73. # automatically find the Qt packages on Windows
  74. if (DEFINED ENV{QTDIR})
  75. list(APPEND CMAKE_PREFIX_PATH "$ENV{QTDIR}")
  76. endif()
  77. if (NOT CITRA_FORCE_QT4)
  78. find_package(Qt5 COMPONENTS Widgets OpenGL)
  79. set(CITRA_QT_LIBS Qt5::Widgets Qt5::OpenGL)
  80. endif()
  81. if (CITRA_FORCE_QT4 OR NOT Qt5_FOUND)
  82. # Try to fallback to Qt4
  83. find_package(Qt4 REQUIRED COMPONENTS QtGui QtOpenGL)
  84. set(CITRA_QT_LIBS Qt4::QtGui Qt4::QtOpenGL)
  85. endif()
  86. endif()
  87. # This function should be passed a list of all files in a target. It will automatically generate
  88. # file groups following the directory hierarchy, so that the layout of the files in IDEs matches the
  89. # one in the filesystem.
  90. function(create_directory_groups)
  91. # Place any files that aren't in the source list in a separate group so that they don't get in
  92. # the way.
  93. source_group("Other Files" REGULAR_EXPRESSION ".")
  94. foreach(file_name ${ARGV})
  95. get_filename_component(dir_name "${file_name}" PATH)
  96. # Group names use '\' as a separator even though the entire rest of CMake uses '/'...
  97. string(REPLACE "/" "\\" group_name "${dir_name}")
  98. source_group("${group_name}" FILES "${file_name}")
  99. endforeach()
  100. endfunction()
  101. # generate git revision information
  102. include(GetGitRevisionDescription)
  103. get_git_head_revision(GIT_REF_SPEC GIT_REV)
  104. git_describe(GIT_DESC --always --long --dirty)
  105. git_branch_name(GIT_BRANCH)
  106. # process subdirectories
  107. if(ENABLE_QT)
  108. include_directories(externals/qhexedit)
  109. add_subdirectory(externals/qhexedit)
  110. endif()
  111. add_subdirectory(src)