CMakeLists.txt 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. if (NOT APPLE)
  57. find_package(X11 REQUIRED)
  58. endif()
  59. find_package(PkgConfig REQUIRED)
  60. pkg_search_module(GLFW REQUIRED glfw3)
  61. endif()
  62. include_directories(${GLFW_INCLUDE_DIRS})
  63. link_directories(${GLFW_LIBRARY_DIRS})
  64. endif()
  65. IF (APPLE)
  66. # CoreFoundation is required only on OSX
  67. FIND_LIBRARY(COREFOUNDATION_LIBRARY CoreFoundation)
  68. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
  69. set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -stdlib=libc++")
  70. ENDIF (APPLE)
  71. option(ENABLE_QT "Enable the Qt frontend" ON)
  72. option(CITRA_FORCE_QT4 "Use Qt4 even if Qt5 is available." OFF)
  73. if (ENABLE_QT)
  74. # Set CMAKE_PREFIX_PATH if QTDIR is defined in the environment This allows CMake to
  75. # automatically find the Qt packages on Windows
  76. if (DEFINED ENV{QTDIR})
  77. list(APPEND CMAKE_PREFIX_PATH "$ENV{QTDIR}")
  78. endif()
  79. if (NOT CITRA_FORCE_QT4)
  80. find_package(Qt5 COMPONENTS Widgets OpenGL)
  81. set(CITRA_QT_LIBS Qt5::Widgets Qt5::OpenGL)
  82. endif()
  83. if (CITRA_FORCE_QT4 OR NOT Qt5_FOUND)
  84. # Try to fallback to Qt4
  85. find_package(Qt4 REQUIRED COMPONENTS QtGui QtOpenGL)
  86. set(CITRA_QT_LIBS Qt4::QtGui Qt4::QtOpenGL)
  87. endif()
  88. endif()
  89. # This function should be passed a list of all files in a target. It will automatically generate
  90. # file groups following the directory hierarchy, so that the layout of the files in IDEs matches the
  91. # one in the filesystem.
  92. function(create_directory_groups)
  93. # Place any files that aren't in the source list in a separate group so that they don't get in
  94. # the way.
  95. source_group("Other Files" REGULAR_EXPRESSION ".")
  96. foreach(file_name ${ARGV})
  97. get_filename_component(dir_name "${file_name}" PATH)
  98. # Group names use '\' as a separator even though the entire rest of CMake uses '/'...
  99. string(REPLACE "/" "\\" group_name "${dir_name}")
  100. source_group("${group_name}" FILES "${file_name}")
  101. endforeach()
  102. endfunction()
  103. # generate git revision information
  104. include(GetGitRevisionDescription)
  105. get_git_head_revision(GIT_REF_SPEC GIT_REV)
  106. git_describe(GIT_DESC --always --long --dirty)
  107. git_branch_name(GIT_BRANCH)
  108. set(INI_PREFIX "${CMAKE_CURRENT_SOURCE_DIR}/externals/inih")
  109. include_directories(${INI_PREFIX})
  110. add_subdirectory(${INI_PREFIX})
  111. # process subdirectories
  112. if(ENABLE_QT)
  113. include_directories(externals/qhexedit)
  114. add_subdirectory(externals/qhexedit)
  115. endif()
  116. add_subdirectory(src)