@ -2,6 +2,37 @@
# d e p e n d e n t l i b r a r i e s .
cmake_minimum_required ( VERSION 2.8.11 )
function ( download_bundled_external remote_path lib_name prefix_var )
set ( prefix "${CMAKE_BINARY_DIR}/externals/${lib_name}" )
if ( NOT EXISTS "${prefix}" )
message ( STATUS "Downloading binaries for ${lib_name}..." )
file ( DOWNLOAD
h t t p s : / / g i t h u b . c o m / c i t r a - e m u / e x t - w i n d o w s - b i n / r a w / m a s t e r / $ { r e m o t e _ p a t h } $ { l i b _ n a m e } . 7 z
" $ { C M A K E _ B I N A R Y _ D I R } / e x t e r n a l s / $ { l i b _ n a m e } . 7 z " S H O W _ P R O G R E S S )
execute_process ( COMMAND ${ CMAKE_COMMAND } -E tar xf "${CMAKE_BINARY_DIR}/externals/${lib_name}.7z"
W O R K I N G _ D I R E C T O R Y " $ { C M A K E _ B I N A R Y _ D I R } / e x t e r n a l s " )
endif ( )
message ( STATUS "Using bundled binaries at ${prefix}" )
set ( ${ prefix_var } "${prefix}" PARENT_SCOPE )
endfunction ( )
include ( CheckSymbolExists )
function ( detect_architecture symbol arch )
if ( NOT DEFINED ARCHITECTURE )
set ( CMAKE_REQUIRED_QUIET 1 )
check_symbol_exists ( "${symbol}" "" ARCHITECTURE_ ${ arch } )
unset ( CMAKE_REQUIRED_QUIET )
# T h e o u t p u t v a r i a b l e n e e d s t o b e u n i q u e a c r o s s i n v o c a t i o n s o t h e r w i s e
# C M a k e ' s c r a z y s c o p e r u l e s w i l l k e e p i t d e f i n e d
if ( ARCHITECTURE_ ${ arch } )
set ( ARCHITECTURE "${arch}" PARENT_SCOPE )
set ( ARCHITECTURE_ ${ arch } 1 PARENT_SCOPE )
add_definitions ( -DARCHITECTURE_ ${ arch } =1 )
endif ( )
endif ( )
endfunction ( )
project ( citra )
if ( NOT EXISTS ${ CMAKE_CURRENT_SOURCE_DIR } /.git/hooks/pre-commit )
@ -10,12 +41,21 @@ if(NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.git/hooks/pre-commit)
D E S T I N A T I O N $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / . g i t / h o o k s )
endif ( )
# P l a t f o r m - a g n o s t i c d e f i n i t i o n t o c h e c k i f w e a r e o n x 8 6 _ 6 4
if ( ${ CMAKE_SYSTEM_PROCESSOR } MATCHES "[xX]86_64" OR
$ { C M A K E _ S Y S T E M _ P R O C E S S O R } M A T C H E S " [ a A ] [ m M ] [ d D ] 6 4 " )
set ( ARCHITECTURE_x86_64 1 )
add_definitions ( -DARCHITECTURE_x86_64=1 )
if ( MSVC )
detect_architecture ( "_M_AMD64" x86_64 )
detect_architecture ( "_M_IX86" x86 )
detect_architecture ( "_M_ARM" ARM )
else ( )
detect_architecture ( "__x86_64__" x86_64 )
detect_architecture ( "__i386__" x86 )
detect_architecture ( "__arm__" ARM )
endif ( )
if ( NOT DEFINED ARCHITECTURE )
set ( ARCHITECTURE "GENERIC" )
set ( ARCHITECTURE_GENERIC 1 )
add_definitions ( -DARCHITECTURE_GENERIC=1 )
endif ( )
message ( STATUS "Target architecture: ${ARCHITECTURE}" )
if ( NOT MSVC )
set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wno-attributes -pthread" )
@ -75,7 +115,7 @@ else()
message ( STATUS "libpng not found. Some debugging features have been disabled." )
endif ( )
find_package ( Boost 1.57.0 )
find_package ( Boost 1.57.0 QUIET )
if ( Boost_FOUND )
include_directories ( ${ Boost_INCLUDE_DIRS } )
else ( )
@ -90,59 +130,29 @@ find_package(OpenGL REQUIRED)
include_directories ( ${ OPENGL_INCLUDE_DIR } )
option ( ENABLE_GLFW "Enable the GLFW frontend" ON )
option ( CITRA_USE_BUNDLED_GLFW "Download bundled GLFW binaries" OFF )
if ( ENABLE_GLFW )
if ( WIN32 )
if ( CITRA_USE_BUNDLED_GLFW )
# D e t e c t t o o l c h a i n a n d p l a t f o r m
if ( MSVC )
if ( CMAKE_SIZEOF_VOID_P EQUAL 8 )
set ( TMP_ARCH "x64" )
elseif ( CMAKE_SIZEOF_VOID_P EQUAL 4 )
set ( TMP_ARCH "Win32" )
else ( )
set ( TMP_ARCH "UNKNOWN" )
message ( SEND_ERROR "Couldn't detect your compiler's architecture, you'll have to manually specify the GLFW library to use. (Try checking CMakeOutput.log to find out why.)" )
endif ( )
if ( MSVC11 ) # V i s u a l C + + 2 0 1 2
set ( TMP_TOOLSET "v110" )
elseif ( MSVC12 ) # V i s u a l C + + 2 0 1 3
set ( TMP_TOOLSET "v120" )
else ( )
set ( TMP_TOOLSET "UNSUPPORTED" )
message ( SEND_ERROR "We don't supply GLFW binaries for your version of MSVC, you might have to provide them yourself." )
endif ( )
set ( TMP_TOOLSET "msvc_${TMP_TOOLSET}-${TMP_ARCH}" )
if ( MSVC14 AND ARCHITECTURE_x86_64 )
set ( GLFW_VER "glfw-3.1.1-msvc2015_64" )
elseif ( MSVC12 AND ARCHITECTURE_x86_64 )
set ( GLFW_VER "glfw-3.1.1-msvc2013_64" )
else ( )
# A s s u m e m i n g w
if ( CMAKE_SIZEOF_VOID_P EQUAL 8 )
set ( TMP_ARCH "x86_64" )
elseif ( CMAKE_SIZEOF_VOID_P EQUAL 4 )
set ( TMP_ARCH "i686" )
else ( )
set ( TMP_ARCH "UNKNOWN" )
message ( SEND_ERROR "Couldn't detect your compiler's architecture, you'll have to manually specify the GLFW library to use." )
endif ( )
set ( TMP_TOOLSET "mingw-${TMP_ARCH}" )
message ( FATAL_ERROR "No bundled GLFW binaries for your toolchain. Disable CITRA_USE_BUNDLED_GLFW and provide your own." )
endif ( )
if ( DEFINED GLFW_VER )
download_bundled_external ( "glfw/" ${ GLFW_VER } GLFW_PREFIX )
endif ( )
set ( GLFW_PREFIX "${CMAKE_CURRENT_SOURCE_DIR}/externals/glfw-3.1.1.bin" )
set ( GLFW_INCLUDE_DIRS "${GLFW_PREFIX}/include" CACHE PATH "Path to GLFW3 headers" )
set ( GLFW_LIBRARY_DIRS "${GLFW_PREFIX}/lib-${TMP_TOOLSET}" CACHE PATH "Path to GLFW3 libraries" )
# C l e a n u p a f t e r o u r s e l v e s
unset ( TMP_TOOLSET )
unset ( TMP_ARCH )
set ( GLFW_LIBRARY_DIRS "${GLFW_PREFIX}/lib" CACHE PATH "Path to GLFW3 libraries" )
set ( GLFW_LIBRARIES glfw3 )
else ( )
find_package ( PkgConfig REQUIRED )
pkg_search_module ( GLFW REQUIRED glfw3 )
endif ( )
include_directories ( ${ GLFW_INCLUDE_DIRS } )
link_directories ( ${ GLFW_LIBRARY_DIRS } )
endif ( )
IF ( APPLE )
@ -167,22 +177,35 @@ ELSE()
ENDIF ( APPLE )
option ( ENABLE_QT "Enable the Qt frontend" ON )
option ( CITRA_USE_BUNDLED_QT "Download bundled Qt binaries" OFF )
option ( CITRA_FORCE_QT4 "Use Qt4 even if Qt5 is available." OFF )
if ( ENABLE_QT )
# S e t C M A K E _ P R E F I X _ P A T H i f Q T D I R i s d e f i n e d i n t h e e n v i r o n m e n t T h i s a l l o w s C M a k e t o
# a u t o m a t i c a l l y f i n d t h e Q t p a c k a g e s o n W i n d o w s
if ( DEFINED ENV{QTDIR} )
list ( APPEND CMAKE_PREFIX_PATH "$ENV{QTDIR}" )
if ( CITRA_USE_BUNDLED_QT )
if ( MSVC14 AND ARCHITECTURE_x86_64 )
set ( QT_VER qt-5.5-msvc2015_64 )
else ( )
message ( FATAL_ERROR "No bundled Qt binaries for your toolchain. Disable CITRA_USE_BUNDLED_QT and provide your own." )
endif ( )
if ( DEFINED QT_VER )
download_bundled_external ( "qt/" ${ QT_VER } QT_PREFIX )
endif ( )
set ( QT_PREFIX_HINT HINTS "${QT_PREFIX}" )
else ( )
# P a s s i n g a n e m p t y H I N T S s e e m s t o c a u s e d e f a u l t s y s t e m p a t h s t o g e t i g n o r e d i n C M a k e 2 . 8 s o
# m a k e s u r e t o n o t p a s s a n y t h i n g i f w e d o n ' t h a v e o n e .
set ( QT_PREFIX_HINT )
endif ( )
if ( NOT CITRA_FORCE_QT4 )
find_package ( Qt5 COMPONENTS Widgets OpenGL )
find_package ( Qt5 COMPONENTS Widgets OpenGL ${ QT_PREFIX_HINT } )
set ( CITRA_QT_LIBS Qt5::Widgets Qt5::OpenGL )
endif ( )
if ( CITRA_FORCE_QT4 OR NOT Qt5_FOUND )
# T r y t o f a l l b a c k t o Q t 4
find_package ( Qt4 REQUIRED COMPONENTS QtGui QtOpenGL )
find_package ( Qt4 REQUIRED COMPONENTS QtGui QtOpenGL ${ QT_PREFIX_HINT } )
set ( CITRA_QT_LIBS Qt4::QtGui Qt4::QtOpenGL )
endif ( )
endif ( )