General cleanup of the CMake configuration files.

This commit is contained in:
Leon Styhre 2021-09-19 18:53:20 +02:00
parent dacda90186
commit fc78f8ee18
3 changed files with 400 additions and 380 deletions

View file

@ -25,8 +25,7 @@ set(CMAKE_VERBOSE_MAKEFILE OFF CACHE BOOL "Show verbose compiler output" FORCE)
set(LINUX_CPACK_GENERATOR "DEB" CACHE STRING "CPack generator, DEB or RPM")
# Add local find modules to the CMake path.
list(APPEND CMAKE_MODULE_PATH
${CMAKE_CURRENT_SOURCE_DIR}/CMake/Utils
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/CMake/Utils
${CMAKE_CURRENT_SOURCE_DIR}/CMake/Packages)
# Define the options.
@ -39,14 +38,20 @@ option(CLANG_TIDY "Set to ON to build using the clang-tidy static analyzer" ${CL
if(CLANG_TIDY)
find_program(CLANG_TIDY_BINARY NAMES clang-tidy)
if("${CLANG_TIDY_BINARY}" STREQUAL "CLANG_TIDY_BINARY-NOTFOUND")
if(CLANG_TIDY_BINARY STREQUAL "CLANG_TIDY_BINARY-NOTFOUND")
message("-- CLANG_TIDY was set but the clang-tidy binary was not found")
else()
message("-- Building with the clang-tidy static analyzer")
set(CMAKE_CXX_CLANG_TIDY "clang-tidy;-checks=*,-fuchsia-*,-hicpp-*,-llvm-*, \
-readability-braces-*,-google-readability-braces-*, \
-readability-uppercase-literal-suffix,-modernize-use-trailing-return-type, \
-cppcoreguidelines-avoid-magic-numbers,-readability-magic-numbers")
set(CMAKE_CXX_CLANG_TIDY "clang-tidy;-checks=*,\
-fuchsia-*,\
-hicpp-*,\
-llvm-*,\
-readability-braces-*,\
-google-readability-braces-*,\
-readability-uppercase-literal-suffix,\
-modernize-use-trailing-return-type,\
-cppcoreguidelines-avoid-magic-numbers,\
-readability-magic-numbers")
endif()
endif()
@ -59,19 +64,19 @@ if(EXISTS "${CMAKE_FIND_ROOT_PATH}/opt/vc/include/bcm_host.h")
# Setting BCMHOST seems to break OpenGL ES on the RPi 4 so set RPI instead.
#set(BCMHOST found)
set(RPI ON)
set(GLSystem "Embedded OpenGL" CACHE STRING "The OpenGL system to be used")
set(GLSYSTEM "Embedded OpenGL" CACHE STRING "The OpenGL system to be used")
elseif(GLES OR RPI)
set(GLSystem "Embedded OpenGL" CACHE STRING "The OpenGL system to be used")
set(GLSYSTEM "Embedded OpenGL" CACHE STRING "The OpenGL system to be used")
else()
set(GLSystem "Desktop OpenGL" CACHE STRING "The OpenGL system to be used")
set(GLSYSTEM "Desktop OpenGL" CACHE STRING "The OpenGL system to be used")
endif()
set_property(CACHE GLSystem PROPERTY STRINGS "Desktop OpenGL" "Embedded OpenGL")
set_property(CACHE GLSYSTEM PROPERTY STRINGS "Desktop OpenGL" "Embedded OpenGL")
#---------------------------------------------------------------------------------------------------
# Package dependencies.
if(${GLSystem} MATCHES "Desktop OpenGL")
if(GLSYSTEM MATCHES "Desktop OpenGL")
set(OpenGL_GL_PREFERENCE "GLVND")
find_package(OpenGL REQUIRED)
else()
@ -98,27 +103,27 @@ if(CEC)
endif()
# Add ALSA for Linux.
if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
if(CMAKE_SYSTEM_NAME MATCHES "Linux")
find_package(ALSA REQUIRED)
endif()
#---------------------------------------------------------------------------------------------------
# Compiler and linker settings.
if("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
message("-- Compiler is Clang/LLVM")
if(${CMAKE_CXX_COMPILER_VERSION} VERSION_LESS 5.0.0)
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.0.0)
message(SEND_ERROR "You need at least Clang 5.0.0 to compile EmulationStation-DE")
endif()
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
message("-- Compiler is GNU/GCC")
if(${CMAKE_CXX_COMPILER_VERSION} VERSION_LESS 7.1)
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 7.1)
message(SEND_ERROR "You need at least GCC 7.1 to compile EmulationStation-DE")
endif()
if(WIN32)
set(CMAKE_CXX_FLAGS "-mwindows ${CMAKE_CXX_FLAGS}")
endif()
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
message("-- Compiler is MSVC")
# If using the MSVC compiler on Windows, disable the built-in min() and max() macros.
add_definitions(-DNOMINMAX)
@ -131,7 +136,7 @@ endif()
# Set up compiler and linker flags for debug, profiling or release builds.
if(CMAKE_BUILD_TYPE MATCHES Debug)
# Enable the C++17 standard and disable optimizations as it's a debug build.
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /std:c++17 /Od /DEBUG:FULL")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 -O0 -Wall -Wpedantic -Wsign-compare -Wnarrowing -Wmissing-field-initializers")
@ -141,12 +146,12 @@ if(CMAKE_BUILD_TYPE MATCHES Debug)
# Comment this out if you're using LLDB for debugging as this flag makes the binary
# much larger and the application much slower. On macOS this setting is never enabled
# as LLDB is the default debugger on this OS.
if(NOT APPLE AND "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
if(NOT APPLE AND CMAKE_CXX_COMPILER_ID MATCHES "Clang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_GLIBCXX_DEBUG")
endif()
elseif(CMAKE_BUILD_TYPE MATCHES Profiling)
# For the profiling build, we enable optimizations and supply the required profiler flags.
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /std:c++17 /O2 /DEBUG:FULL")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 -O2 -pg -g -Wall -Wpedantic -Wsign-compare -Wnarrowing -Wmissing-field-initializers")
@ -155,7 +160,7 @@ elseif(CMAKE_BUILD_TYPE MATCHES Profiling)
else()
# Enable the C++17 standard and enable optimizations as it's a release build.
# This will also disable all assert() macros. Strip the binary too.
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DNDEBUG /std:c++17 /O2 /DEBUG:NONE")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 -O2 -DNDEBUG -Wall -Wpedantic -Wsign-compare -Wnarrowing -Wmissing-field-initializers")
@ -178,7 +183,7 @@ if(APPLE)
if(MACOS_CODESIGN_IDENTITY)
message("-- Code signing certificate identity: " ${MACOS_CODESIGN_IDENTITY})
endif()
if(${CMAKE_OSX_DEPLOYMENT_TARGET} VERSION_LESS 10.14)
if(CMAKE_OSX_DEPLOYMENT_TARGET VERSION_LESS 10.14)
message("-- macOS version 10.13 or lower has been set, so if code signing is enabled, Hardened Runtime will not be used")
endif()
endif()
@ -186,7 +191,7 @@ endif()
#---------------------------------------------------------------------------------------------------
# Preprocessor directives.
if(${GLSystem} MATCHES "Desktop OpenGL")
if(GLSYSTEM MATCHES "Desktop OpenGL")
add_definitions(-DUSE_OPENGL_21)
else()
add_definitions(-DUSE_OPENGLES_10)
@ -212,9 +217,9 @@ add_definitions(-DGLM_FORCE_XYZW_ONLY)
# we use /usr on Linux, /usr/pkg on NetBSD and /usr/local on FreeBSD and OpenBSD.
if(NOT WIN32 AND NOT APPLE)
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
if(CMAKE_SYSTEM_NAME MATCHES "Linux")
set(CMAKE_INSTALL_PREFIX "/usr" CACHE INTERNAL "CMAKE_INSTALL_PREFIX")
elseif(${CMAKE_SYSTEM_NAME} MATCHES "NetBSD")
elseif(CMAKE_SYSTEM_NAME MATCHES "NetBSD")
set(CMAKE_INSTALL_PREFIX "/usr/pkg" CACHE INTERNAL "CMAKE_INSTALL_PREFIX")
else()
set(CMAKE_INSTALL_PREFIX "/usr/local" CACHE INTERNAL "CMAKE_INSTALL_PREFIX")
@ -233,8 +238,7 @@ endif()
#---------------------------------------------------------------------------------------------------
# Include files.
set(COMMON_INCLUDE_DIRS
${CURL_INCLUDE_DIR}
set(COMMON_INCLUDE_DIRS ${CURL_INCLUDE_DIR}
${FFMPEG_INCLUDE_DIRS}
${FreeImage_INCLUDE_DIRS}
${FREETYPE_INCLUDE_DIRS}
@ -272,13 +276,12 @@ if(DEFINED libCEC_FOUND)
endif()
# For Linux, add the ALSA include directory.
if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
if(CMAKE_SYSTEM_NAME MATCHES "Linux")
list(APPEND COMMON_INCLUDE_DIRS ${ALSA_INCLUDE_DIRS})
endif()
if(DEFINED BCMHOST OR RPI)
list(APPEND COMMON_INCLUDE_DIRS
"${CMAKE_FIND_ROOT_PATH}/opt/vc/include"
list(APPEND COMMON_INCLUDE_DIRS "${CMAKE_FIND_ROOT_PATH}/opt/vc/include"
"${CMAKE_FIND_ROOT_PATH}/opt/vc/include/interface/vcos"
"${CMAKE_FIND_ROOT_PATH}/opt/vc/include/interface/vmcs_host/linux"
"${CMAKE_FIND_ROOT_PATH}/opt/vc/include/interface/vcos/pthreads")
@ -288,8 +291,7 @@ endif()
# Dependency libraries.
if(NOT WIN32)
set(COMMON_LIBRARIES
${CURL_LIBRARIES}
set(COMMON_LIBRARIES ${CURL_LIBRARIES}
${FFMPEG_LIBRARIES}
${FreeImage_LIBRARIES}
${FREETYPE_LIBRARIES}
@ -300,8 +302,7 @@ if(NOT WIN32)
endif()
elseif(WIN32)
if(DEFINED MSVC)
set(COMMON_LIBRARIES
"${PROJECT_SOURCE_DIR}/avcodec.lib"
set(COMMON_LIBRARIES "${PROJECT_SOURCE_DIR}/avcodec.lib"
"${PROJECT_SOURCE_DIR}/avfilter.lib"
"${PROJECT_SOURCE_DIR}/avformat.lib"
"${PROJECT_SOURCE_DIR}/avutil.lib"
@ -319,8 +320,7 @@ elseif(WIN32)
set(COMMON_LIBRARIES ${COMMON_LIBRARIES} "${PROJECT_SOURCE_DIR}/libvlc.lib")
endif()
else()
set(COMMON_LIBRARIES
"${PROJECT_SOURCE_DIR}/avcodec-58.dll"
set(COMMON_LIBRARIES "${PROJECT_SOURCE_DIR}/avcodec-58.dll"
"${PROJECT_SOURCE_DIR}/avfilter-7.dll"
"${PROJECT_SOURCE_DIR}/avformat-58.dll"
"${PROJECT_SOURCE_DIR}/avutil-56.dll"
@ -342,15 +342,13 @@ elseif(WIN32)
endif()
if(APPLE)
# See es-app/CMakeLists.txt for an explation for why an extra 'Resources' directory
# See es-app/CMakeLists.txt for an explation for why an extra "Resources" directory
# has been added to the install prefix.
set(CMAKE_INSTALL_PREFIX
"/Applications/EmulationStation Desktop Edition.app/Contents/Resources")
set(CMAKE_INSTALL_PREFIX "/Applications/EmulationStation Desktop Edition.app/Contents/Resources")
if(VLC_PLAYER)
# Required as the VLC find module doesn't work properly on macOS.
set(COMMON_LIBRARIES ${COMMON_LIBRARIES}
"/Applications/VLC.app/Contents/MacOS/lib/libvlc.dylib")
set(COMMON_LIBRARIES ${COMMON_LIBRARIES} "/Applications/VLC.app/Contents/MacOS/lib/libvlc.dylib")
endif()
# Set the same rpath links for the install executable as for the build executable.
@ -368,7 +366,7 @@ if(DEFINED libCEC_FOUND)
endif()
# Add ALSA for Linux libraries.
if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
if(CMAKE_SYSTEM_NAME MATCHES "Linux")
list(APPEND COMMON_LIBRARIES ${ALSA_LIBRARY})
endif()
@ -380,7 +378,7 @@ elseif(RPI)
list(APPEND COMMON_LIBRARIES ${OPENGLES_LIBRARIES})
endif()
if(${GLSystem} MATCHES "Desktop OpenGL")
if(GLSYSTEM MATCHES "Desktop OpenGL")
list(APPEND COMMON_LIBRARIES ${OPENGL_LIBRARIES})
else()
list(APPEND COMMON_LIBRARIES EGL ${OPENGLES_LIBRARIES})

View file

@ -134,20 +134,48 @@ endif()
# Setup for installation and package generation.
if(WIN32)
install(TARGETS EmulationStation RUNTIME DESTINATION .)
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
install(FILES ../avcodec-58.dll ../avfilter-7.dll ../avformat-58.dll ../avutil-56.dll
../postproc-55.dll ../swresample-3.dll ../swscale-5.dll ../FreeImage.dll
../glew32.dll ../libcrypto-1_1-x64.dll ../libcurl-x64.dll ../freetype.dll
../pugixml.dll ../libssl-1_1-x64.dll ../SDL2.dll ../MSVCP140.dll ../VCOMP140.DLL
../VCRUNTIME140.dll ../VCRUNTIME140_1.dll DESTINATION .)
if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
install(FILES ../avcodec-58.dll
../avfilter-7.dll
../avformat-58.dll
../avutil-56.dll
../postproc-55.dll
../swresample-3.dll
../swscale-5.dll
../FreeImage.dll
../freetype.dll
../glew32.dll
../libcrypto-1_1-x64.dll
../libcurl-x64.dll
../libssl-1_1-x64.dll
../MSVCP140.dll
../pugixml.dll
../SDL2.dll
../VCOMP140.DLL
../VCRUNTIME140.dll
../VCRUNTIME140_1.dll
DESTINATION .)
if(VLC_PLAYER)
install(FILES ../libvlc.dll ../libvlccore.dll DESTINATION .)
endif()
else()
install(FILES ../avcodec-58.dll ../avfilter-7.dll ../avformat-58.dll ../avutil-56.dll
../postproc-55.dll ../swresample-3.dll ../swscale-5.dll ../FreeImage.dll
../glew32.dll ../libcrypto-1_1-x64.dll ../libcurl-x64.dll ../libfreetype.dll
../libpugixml.dll ../libssl-1_1-x64.dll ../SDL2.dll ../vcomp140.dll DESTINATION .)
install(FILES ../avcodec-58.dll
../avfilter-7.dll
../avformat-58.dll
../avutil-56.dll
../postproc-55.dll
../swresample-3.dll
../swscale-5.dll
../FreeImage.dll
../glew32.dll
../libcrypto-1_1-x64.dll
../libcurl-x64.dll
../libfreetype.dll
../libpugixml.dll
../libssl-1_1-x64.dll
../SDL2.dll
../vcomp140.dll
DESTINATION .)
if(VLC_PLAYER)
install(FILES ../libvlc.dll ../libvlccore.dll DESTINATION .)
endif()
@ -166,12 +194,9 @@ elseif(APPLE)
# So an extra 'Resources' directory was added to the CMAKE_INSTALL_PREFIX variable as well
# to compensate for this. It's a bad solution to the problem and there must surely be a
# better way to fix this.
install(TARGETS EmulationStation RUNTIME
DESTINATION ../MacOS)
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/assets/EmulationStation-DE.icns
DESTINATION ../Resources)
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/assets/EmulationStation-DE_Info.plist
DESTINATION .. RENAME Info.plist)
install(TARGETS EmulationStation RUNTIME DESTINATION ../MacOS)
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/assets/EmulationStation-DE.icns DESTINATION ../Resources)
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/assets/EmulationStation-DE_Info.plist DESTINATION .. RENAME Info.plist)
# Another hack/workaround. I have not been able to find any way whatsover to force the
# linker to use rpaths for all shared libraries instead of absolute paths. So instead
@ -192,8 +217,8 @@ elseif(APPLE)
-change /usr/local/opt/libpng/lib/libpng16.16.dylib @rpath/libpng16.16.dylib
-change /usr/local/opt/sdl2/lib/libSDL2-2.0.0.dylib @rpath/libSDL2-2.0.0.dylib
$<TARGET_FILE:EmulationStation>)
set(APPLE_DYLIB_PERMISSIONS
OWNER_WRITE OWNER_READ OWNER_EXECUTE
set(APPLE_DYLIB_PERMISSIONS OWNER_WRITE OWNER_READ OWNER_EXECUTE
GROUP_READ GROUP_EXECUTE
WORLD_READ WORLD_EXECUTE)
@ -221,6 +246,7 @@ elseif(APPLE)
PERMISSIONS ${APPLE_DYLIB_PERMISSIONS} DESTINATION ../MacOS)
install(FILES ${CMAKE_SOURCE_DIR}/libSDL2-2.0.0.dylib
PERMISSIONS ${APPLE_DYLIB_PERMISSIONS} DESTINATION ../MacOS)
if(VLC_PLAYER)
install(FILES ${CMAKE_SOURCE_DIR}/libvlc.dylib
PERMISSIONS ${APPLE_DYLIB_PERMISSIONS} DESTINATION ../MacOS)
@ -229,18 +255,14 @@ elseif(APPLE)
install(DIRECTORY ${CMAKE_SOURCE_DIR}/plugins
DESTINATION ../MacOS)
endif()
install(FILES ${CMAKE_SOURCE_DIR}/LICENSE
DESTINATION ../Resources)
install(DIRECTORY ${CMAKE_SOURCE_DIR}/resources
DESTINATION ../Resources)
install(DIRECTORY ${CMAKE_SOURCE_DIR}/themes
DESTINATION ../Resources)
install(DIRECTORY ${CMAKE_SOURCE_DIR}/licenses
DESTINATION ../Resources)
install(FILES ${CMAKE_SOURCE_DIR}/LICENSE DESTINATION ../Resources)
install(DIRECTORY ${CMAKE_SOURCE_DIR}/resources DESTINATION ../Resources)
install(DIRECTORY ${CMAKE_SOURCE_DIR}/themes DESTINATION ../Resources)
install(DIRECTORY ${CMAKE_SOURCE_DIR}/licenses DESTINATION ../Resources)
else()
install(TARGETS emulationstation RUNTIME
DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
install(TARGETS emulationstation RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
if(CMAKE_SYSTEM_NAME MATCHES "Linux")
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/assets/emulationstation.6.gz
DESTINATION ${CMAKE_INSTALL_PREFIX}/share/man/man6)
else()
@ -295,7 +317,7 @@ endif()
# Settings per operating system and generator type.
if(APPLE)
set(CPACK_GENERATOR "Bundle")
if(${CMAKE_OSX_DEPLOYMENT_TARGET} VERSION_LESS 10.14)
if(CMAKE_OSX_DEPLOYMENT_TARGET VERSION_LESS 10.14)
set(CPACK_PACKAGE_FILE_NAME "EmulationStation-DE-${CPACK_PACKAGE_VERSION}-${CPU_ARCHITECTURE}_legacy")
set(CPACK_DMG_VOLUME_NAME "EmulationStation Desktop Edition ${CPACK_PACKAGE_VERSION}_legacy")
else()
@ -309,7 +331,7 @@ if(APPLE)
set(CPACK_BUNDLE_PLIST "${CMAKE_CURRENT_SOURCE_DIR}/assets/EmulationStation-DE_Info.plist")
if(MACOS_CODESIGN_IDENTITY)
set(CPACK_BUNDLE_APPLE_CERT_APP "Developer ID Application: ${MACOS_CODESIGN_IDENTITY}")
if(${CMAKE_OSX_DEPLOYMENT_TARGET} VERSION_GREATER 10.13)
if(CMAKE_OSX_DEPLOYMENT_TARGET VERSION_GREATER 10.13)
set(CPACK_BUNDLE_APPLE_CODESIGN_PARAMETER "--deep --force --options runtime")
endif()
endif()
@ -332,7 +354,7 @@ elseif(WIN32)
else()
set(CPACK_PACKAGE_INSTALL_DIRECTORY "emulationstation_${CMAKE_PACKAGE_VERSION}")
set(CPACK_PACKAGE_EXECUTABLES "emulationstation" "emulationstation")
if("${LINUX_CPACK_GENERATOR}" STREQUAL "DEB")
if(LINUX_CPACK_GENERATOR STREQUAL "DEB")
set(CPACK_GENERATOR "DEB")
endif()
set(CPACK_DEBIAN_FILE_NAME "emulationstation-de-${CPACK_PACKAGE_VERSION}-${CPU_ARCHITECTURE}.deb")
@ -344,7 +366,7 @@ else()
set(CPACK_DEBIAN_PACKAGE_DEPENDS "vlc")
endif()
set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON)
if("${LINUX_CPACK_GENERATOR}" STREQUAL "RPM")
if(LINUX_CPACK_GENERATOR STREQUAL "RPM")
set(CPACK_GENERATOR "RPM")
endif()
set(CPACK_RPM_FILE_NAME "emulationstation-de-${CPACK_PACKAGE_VERSION}-${CPU_ARCHITECTURE}.rpm")