CMakeLists.txt 4.8 KB

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