Merge pull request #2734 from yuriks/cmake-imported-libs

CMake: Use CMake target properties for all libraries
This commit is contained in:
Yuri Kunde Schlesner 2017-05-29 15:12:21 -07:00 committed by GitHub
commit a4f88c7d7c
14 changed files with 160 additions and 120 deletions

View file

@ -11,7 +11,7 @@ if [ "$TRAVIS_OS_NAME" = "linux" -o -z "$TRAVIS_OS_NAME" ]; then
if [ ! -e $HOME/.local/bin/cmake ]; then
echo "CMake not found in the cache, get and extract it..."
curl -L http://www.cmake.org/files/v3.2/cmake-3.2.0-Linux-i386.tar.gz \
curl -L http://www.cmake.org/files/v3.6/cmake-3.6.3-Linux-x86_64.tar.gz \
| tar -xz -C $HOME/.local --strip-components=1
else
echo "Using cached CMake"

View file

@ -1,20 +1,25 @@
# CMake 3.2 required for cmake to know the right flags for CXX standard on OSX
cmake_minimum_required(VERSION 3.2)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/CMakeModules)
# CMake 3.6 required for FindBoost to define IMPORTED libs properly on unknown Boost versions
cmake_minimum_required(VERSION 3.6)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules")
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/externals/cmake-modules")
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
https://github.com/citra-emu/ext-windows-bin/raw/master/${remote_path}${lib_name}.7z
"${CMAKE_BINARY_DIR}/externals/${lib_name}.7z" SHOW_PROGRESS)
execute_process(COMMAND ${CMAKE_COMMAND} -E tar xf "${CMAKE_BINARY_DIR}/externals/${lib_name}.7z"
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/externals")
project(citra)
option(ENABLE_SDL2 "Enable the SDL2 frontend" ON)
option(CITRA_USE_BUNDLED_SDL2 "Download bundled SDL2 binaries" OFF)
option(ENABLE_QT "Enable the Qt frontend" ON)
option(CITRA_USE_BUNDLED_QT "Download bundled Qt binaries" OFF)
if(NOT EXISTS ${CMAKE_SOURCE_DIR}/.git/hooks/pre-commit)
message(STATUS "Copying pre-commit hook")
file(COPY hooks/pre-commit
DESTINATION ${CMAKE_SOURCE_DIR}/.git/hooks)
endif()
message(STATUS "Using bundled binaries at ${prefix}")
set(${prefix_var} "${prefix}" PARENT_SCOPE)
endfunction()
# Detect current compilation architecture and create standard definitions
# =======================================================================
include(CheckSymbolExists)
function(detect_architecture symbol arch)
@ -33,20 +38,6 @@ function(detect_architecture symbol arch)
endif()
endfunction()
project(citra)
option(ENABLE_SDL2 "Enable the SDL2 frontend" ON)
option(CITRA_USE_BUNDLED_SDL2 "Download bundled SDL2 binaries" OFF)
option(ENABLE_QT "Enable the Qt frontend" ON)
option(CITRA_USE_BUNDLED_QT "Download bundled Qt binaries" OFF)
if(NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.git/hooks/pre-commit)
message(STATUS "Copying pre-commit hook")
file(COPY hooks/pre-commit
DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/.git/hooks)
endif()
if (MSVC)
detect_architecture("_M_AMD64" x86_64)
detect_architecture("_M_IX86" x86)
@ -63,6 +54,10 @@ if (NOT DEFINED ARCHITECTURE)
endif()
message(STATUS "Target architecture: ${ARCHITECTURE}")
# Configure compilation flags
# ===========================
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
@ -130,25 +125,41 @@ add_definitions(-DSINGLETHREADED)
set_property(DIRECTORY APPEND PROPERTY
COMPILE_DEFINITIONS $<$<CONFIG:Debug>:_DEBUG> $<$<NOT:$<CONFIG:Debug>>:NDEBUG>)
# System imported libraries
# ======================
# This function downloads a binary library package from our external repo.
# Params:
# remote_path: path to the file to download, relative to the remote repository root
# prefix_var: name of a variable which will be set with the path to the extracted contents
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
https://github.com/citra-emu/ext-windows-bin/raw/master/${remote_path}${lib_name}.7z
"${CMAKE_BINARY_DIR}/externals/${lib_name}.7z" SHOW_PROGRESS)
execute_process(COMMAND ${CMAKE_COMMAND} -E tar xf "${CMAKE_BINARY_DIR}/externals/${lib_name}.7z"
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/externals")
endif()
message(STATUS "Using bundled binaries at ${prefix}")
set(${prefix_var} "${prefix}" PARENT_SCOPE)
endfunction()
find_package(PNG QUIET)
if (PNG_FOUND)
add_definitions(-DHAVE_PNG)
else()
if (NOT PNG_FOUND)
message(STATUS "libpng not found. Some debugging features have been disabled.")
endif()
find_package(Boost 1.57.0 QUIET)
find_package(Boost 1.63.0 QUIET)
if (NOT Boost_FOUND)
message(STATUS "Boost 1.57.0 or newer not found, falling back to externals")
set(Boost_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/externals/boost")
message(STATUS "Boost 1.63.0 or newer not found, falling back to externals")
set(BOOST_ROOT "${CMAKE_SOURCE_DIR}/externals/boost")
set(Boost_NO_SYSTEM_PATHS OFF)
find_package(Boost QUIET REQUIRED)
endif()
include_directories(${Boost_INCLUDE_DIR})
# Include bundled CMake modules
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/externals/cmake-modules")
find_package(OpenGL REQUIRED)
include_directories(${OPENGL_INCLUDE_DIR})
# Prefer the -pthread flag on Linux.
set(THREADS_PREFER_PTHREAD_FLAG ON)
@ -174,10 +185,43 @@ if (ENABLE_SDL2)
else()
find_package(SDL2 REQUIRED)
endif()
if (SDL2_FOUND)
# TODO(yuriks): Make FindSDL2.cmake export an IMPORTED library instead
add_library(SDL2 INTERFACE)
target_link_libraries(SDL2 INTERFACE "${SDL2_LIBRARY}")
target_include_directories(SDL2 INTERFACE "${SDL2_INCLUDE_DIR}")
endif()
else()
set(SDL2_FOUND NO)
endif()
if (ENABLE_QT)
if (CITRA_USE_BUNDLED_QT)
if (MSVC14 AND ARCHITECTURE_x86_64)
set(QT_VER qt-5.7-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()
# Passing an empty HINTS seems to cause default system paths to get ignored in CMake 2.8 so
# make sure to not pass anything if we don't have one.
set(QT_PREFIX_HINT)
endif()
find_package(Qt5 REQUIRED COMPONENTS Widgets OpenGL ${QT_PREFIX_HINT})
endif()
# Platform-specific library requirements
# ======================================
IF (APPLE)
FIND_LIBRARY(COCOA_LIBRARY Cocoa) # Umbrella framework for everything GUI-related
set(PLATFORM_LIBRARIES ${COCOA_LIBRARY} ${IOKIT_LIBRARY} ${COREVIDEO_LIBRARY})
@ -206,28 +250,9 @@ if (UNIX OR MINGW)
endif()
endif()
if (ENABLE_QT)
if (CITRA_USE_BUNDLED_QT)
if (MSVC14 AND ARCHITECTURE_x86_64)
set(QT_VER qt-5.7-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()
# Passing an empty HINTS seems to cause default system paths to get ignored in CMake 2.8 so
# make sure to not pass anything if we don't have one.
set(QT_PREFIX_HINT)
endif()
find_package(Qt5 REQUIRED COMPONENTS Widgets OpenGL ${QT_PREFIX_HINT})
set(CITRA_QT_LIBS Qt5::Widgets Qt5::OpenGL)
endif()
# Include source code
# ===================
# This function should be passed a list of all files in a target. It will automatically generate
# file groups following the directory hierarchy, so that the layout of the files in IDEs matches the
@ -251,30 +276,13 @@ get_git_head_revision(GIT_REF_SPEC GIT_REV)
git_describe(GIT_DESC --always --long --dirty)
git_branch_name(GIT_BRANCH)
set(INI_PREFIX "${CMAKE_CURRENT_SOURCE_DIR}/externals/inih")
include_directories(${INI_PREFIX})
add_subdirectory(${INI_PREFIX})
add_subdirectory(externals)
option(DYNARMIC_TESTS OFF)
set(DYNARMIC_NO_BUNDLED_FMT ON)
add_subdirectory(externals/dynarmic)
add_subdirectory(externals/glad)
include_directories(externals/microprofile)
include_directories(externals/nihstro/include)
if (MSVC)
add_subdirectory(externals/getopt)
endif()
# process subdirectories
add_subdirectory(externals/soundtouch)
add_subdirectory(src)
enable_testing()
add_subdirectory(src)
# Installation instructions
# =========================
# Install freedesktop.org metadata files, following those specifications:
# http://standards.freedesktop.org/desktop-entry-spec/desktop-entry-spec-latest.html

View file

@ -1,12 +1,52 @@
# Definitions for all external bundled libraries
# Catch
add_library(catch-single-include INTERFACE)
target_include_directories(catch-single-include INTERFACE catch/single_include)
# Crypto++
add_subdirectory(cryptopp)
# Dynarmic
# Dynarmic will skip defining xbyak if it's already defined, we then define it below
add_library(xbyak INTERFACE)
option(DYNARMIC_TESTS OFF)
set(DYNARMIC_NO_BUNDLED_FMT ON)
add_subdirectory(dynarmic)
# libfmt
add_subdirectory(fmt)
# getopt
if (MSVC)
add_subdirectory(getopt)
endif()
# Glad
add_subdirectory(glad)
# inih
add_subdirectory(inih)
# MicroProfile
add_library(microprofile INTERFACE)
target_include_directories(microprofile INTERFACE ./microprofile)
# Nihstro
add_library(nihstro-headers INTERFACE)
target_include_directories(nihstro-headers INTERFACE ./nihstro/include)
# SoundTouch
add_subdirectory(soundtouch)
# The SoundTouch target doesn't export the necessary include paths as properties by default
target_include_directories(SoundTouch INTERFACE ./soundtouch/include)
# Xbyak
if (ARCHITECTURE_x86_64)
add_library(xbyak INTERFACE)
target_include_directories(xbyak INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/xbyak/xbyak)
# Defined before "dynarmic" above
# add_library(xbyak INTERFACE)
target_include_directories(xbyak INTERFACE ./xbyak/xbyak)
if (NOT MSVC)
target_compile_options(xbyak INTERFACE -fno-operator-names)
endif()
endif()
add_subdirectory(cryptopp)
add_subdirectory(fmt)

View file

@ -10,6 +10,7 @@
# - disabled installation
# - disabled documentation
# - configured to build a static library only
# - adds include directories to the library target
include(TestBigEndian)
include(CheckCXXCompilerFlag)
@ -148,14 +149,15 @@ endif()
# Compile targets
#============================================================================
add_library(cryptopp STATIC ${cryptopp_SOURCES})
target_include_directories(cryptopp INTERFACE .)
#============================================================================
# Third-party libraries
#============================================================================
if(WIN32)
target_link_libraries(cryptopp ws2_32)
target_link_libraries(cryptopp PRIVATE ws2_32)
endif()
find_package(Threads)
target_link_libraries(cryptopp ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries(cryptopp PRIVATE ${CMAKE_THREAD_LIBS_INIT})

View file

@ -9,6 +9,7 @@ set(HEADERS
create_directory_groups(${SRCS} ${HEADERS})
add_library(glad STATIC ${SRCS} ${HEADERS})
target_include_directories(glad PUBLIC "include/")
if ("${CMAKE_SYSTEM_NAME}" MATCHES "Linux")
target_link_libraries(glad dl)
target_link_libraries(glad PRIVATE dl)
endif()

View file

@ -9,3 +9,4 @@ set(HEADERS
create_directory_groups(${SRCS} ${HEADERS})
add_library(inih ${SRCS} ${HEADERS})
target_include_directories(inih INTERFACE .)

View file

@ -27,12 +27,9 @@ set(HEADERS
time_stretch.h
)
include_directories(../../externals/soundtouch/include)
if(SDL2_FOUND)
set(SRCS ${SRCS} sdl2_sink.cpp)
set(HEADERS ${HEADERS} sdl2_sink.h)
include_directories(${SDL2_INCLUDE_DIR})
endif()
create_directory_groups(${SRCS} ${HEADERS})
@ -42,6 +39,6 @@ target_link_libraries(audio_core PUBLIC common core)
target_link_libraries(audio_core PRIVATE SoundTouch)
if(SDL2_FOUND)
target_link_libraries(audio_core PRIVATE ${SDL2_LIBRARY})
target_link_libraries(audio_core PRIVATE SDL2)
target_compile_definitions(audio_core PRIVATE HAVE_SDL2)
endif()

View file

@ -15,15 +15,13 @@ set(HEADERS
create_directory_groups(${SRCS} ${HEADERS})
include_directories(${SDL2_INCLUDE_DIR})
add_executable(citra ${SRCS} ${HEADERS})
target_link_libraries(citra PRIVATE common core input_common)
target_link_libraries(citra PRIVATE ${SDL2_LIBRARY} ${OPENGL_gl_LIBRARY} inih glad)
target_link_libraries(citra PRIVATE inih glad)
if (MSVC)
target_link_libraries(citra PRIVATE getopt)
endif()
target_link_libraries(citra PRIVATE ${PLATFORM_LIBRARIES} Threads::Threads)
target_link_libraries(citra PRIVATE ${PLATFORM_LIBRARIES} SDL2 Threads::Threads)
if(UNIX AND NOT APPLE)
install(TARGETS citra RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}/bin")

View file

@ -92,7 +92,7 @@ else()
add_executable(citra-qt ${SRCS} ${HEADERS} ${UI_HDRS})
endif()
target_link_libraries(citra-qt PRIVATE audio_core common core input_common video_core)
target_link_libraries(citra-qt PRIVATE ${OPENGL_gl_LIBRARY} ${CITRA_QT_LIBS} glad)
target_link_libraries(citra-qt PRIVATE Boost::boost glad nihstro-headers Qt5::OpenGL Qt5::Widgets)
target_link_libraries(citra-qt PRIVATE ${PLATFORM_LIBRARIES} Threads::Threads)
if(UNIX AND NOT APPLE)

View file

@ -95,6 +95,7 @@ endif()
create_directory_groups(${SRCS} ${HEADERS})
add_library(common STATIC ${SRCS} ${HEADERS})
target_link_libraries(common PUBLIC Boost::boost microprofile)
if (ARCHITECTURE_x86_64)
target_link_libraries(common PRIVATE xbyak)
endif()

View file

@ -374,11 +374,7 @@ set(HEADERS
telemetry_session.h
)
include_directories(../../externals/dynarmic/include)
include_directories(../../externals/cryptopp)
create_directory_groups(${SRCS} ${HEADERS})
add_library(core STATIC ${SRCS} ${HEADERS})
target_link_libraries(core PUBLIC common PRIVATE audio_core video_core)
target_link_libraries(core PRIVATE cryptopp dynarmic)
target_link_libraries(core PUBLIC Boost::boost PRIVATE cryptopp dynarmic)

View file

@ -13,7 +13,6 @@ set(HEADERS
if(SDL2_FOUND)
set(SRCS ${SRCS} sdl/sdl.cpp)
set(HEADERS ${HEADERS} sdl/sdl.h)
include_directories(${SDL2_INCLUDE_DIR})
endif()
create_directory_groups(${SRCS} ${HEADERS})
@ -22,6 +21,6 @@ add_library(input_common STATIC ${SRCS} ${HEADERS})
target_link_libraries(input_common PUBLIC core PRIVATE common)
if(SDL2_FOUND)
target_link_libraries(input_common PRIVATE ${SDL2_LIBRARY})
target_link_libraries(input_common PRIVATE SDL2)
target_compile_definitions(input_common PRIVATE HAVE_SDL2)
endif()

View file

@ -10,11 +10,9 @@ set(HEADERS
create_directory_groups(${SRCS} ${HEADERS})
include_directories(../../externals/catch/single_include/)
add_executable(tests ${SRCS} ${HEADERS})
target_link_libraries(tests PRIVATE common core)
target_link_libraries(tests PRIVATE glad) # To support linker work-around
target_link_libraries(tests PRIVATE ${PLATFORM_LIBRARIES} Threads::Threads)
target_link_libraries(tests PRIVATE ${PLATFORM_LIBRARIES} catch-single-include Threads::Threads)
add_test(NAME tests COMMAND $<TARGET_FILE:tests>)
add_test(NAME tests COMMAND tests)

View file

@ -80,14 +80,13 @@ create_directory_groups(${SRCS} ${HEADERS})
add_library(video_core STATIC ${SRCS} ${HEADERS})
target_link_libraries(video_core PUBLIC common core)
target_link_libraries(video_core PRIVATE glad)
target_link_libraries(video_core PRIVATE glad nihstro-headers)
if (ARCHITECTURE_x86_64)
target_link_libraries(video_core PRIVATE xbyak)
endif()
if (PNG_FOUND)
target_link_libraries(video_core PRIVATE ${PNG_LIBRARIES})
target_include_directories(video_core PRIVATE ${PNG_INCLUDE_DIRS})
target_compile_definitions(video_core PRIVATE ${PNG_DEFINITIONS})
target_link_libraries(video_core PRIVATE PNG::PNG)
target_compile_definitions(video_core PRIVATE HAVE_PNG)
endif()