CMakeLists.txt 4.6 KB

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