CMakeLists.txt 4.9 KB

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