diff --git a/CMakeLists.txt b/CMakeLists.txt index 4b1ec2c..c625b9b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -44,43 +44,31 @@ add_executable(MagicPlayer) # Add sources cmutils_target_sources_folders( MagicPlayer PRIVATE - "${CMAKE_SOURCE_DIR}/src" - "${CMAKE_SOURCE_DIR}/include" + "${CMAKE_CURRENT_SOURCE_DIR}/src" + "${CMAKE_CURRENT_SOURCE_DIR}/include" ) # Add includes target_include_directories( MagicPlayer PRIVATE - "${CMAKE_SOURCE_DIR}/include" -) - -# Add external includes -target_include_directories( - MagicPlayer SYSTEM PRIVATE - "${OPENGL_INCLUDE_DIR}" - "${SFML_INCLUDE_DIR}" - "${IMGUI_INCLUDE_DIR}" - "${IMGUI_SFML_INCLUDE_DIR}" - "${LIBMPG123_INCLUDE_DIR}" - "${SPDLOG_INCLUDE_DIR}" - "${ICON_FONT_CPP_HEADERS_INCLUDE_DIR}" - "${UTFCPP_INCLUDE_DIR}" - "${TAGLIB_INCLUDE_DIR}" - "${JSON_INCLUDE_DIR}" + "${CMAKE_CURRENT_SOURCE_DIR}/include" ) # Link dependencies target_link_libraries( - MagicPlayer PRIVATE - ${OPENGL_LIBRARY} - ${SFML_LIBRARY} - ${IMGUI_SFML_LIBRARY} - ${LIBMPG123_LIBRARY} - ${SPDLOG_LIBRARY} - ${ICON_FONT_CPP_HEADERS_LIBRARY} - ${UTFCPP_LIBRARY} - ${TAGLIB_LIBRARY} - ${JSON_LIBRARY} + MagicPlayer PRIVATE + OpenGL::GL + sfml-system + sfml-window + sfml-graphics + sfml-audio + imgui-sfml + libmpg123 + spdlog + IconFontCppHeaders + utf8cpp + taglib + nlohmann_json ) # Link threads library @@ -123,25 +111,25 @@ endif() cmutils_target_set_ide_folder(MagicPlayer "MagicPlayer") # Group sources for IDEs -cmutils_target_source_group(MagicPlayer "${CMAKE_SOURCE_DIR}") +cmutils_target_source_group(MagicPlayer "${CMAKE_CURRENT_SOURCE_DIR}") # Visual studio config get_target_property(magicplayer_binary_folder MagicPlayer RUNTIME_OUTPUT_DIRECTORY) set_target_properties( - MagicPlayer PROPERTIES - VS_DEBUGGER_WORKING_DIRECTORY "${magicplayer_binary_folder}" + MagicPlayer PROPERTIES + VS_DEBUGGER_WORKING_DIRECTORY "${magicplayer_binary_folder}" ) set_property( - DIRECTORY - ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY - VS_STARTUP_PROJECT MagicPlayer + DIRECTORY + ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY + VS_STARTUP_PROJECT MagicPlayer ) # Resources cmutils_configure_folder( - "${CMAKE_SOURCE_DIR}/resources" - "${magicplayer_binary_folder}/resources" - COPYONLY + "${CMAKE_CURRENT_SOURCE_DIR}/resources" + "${magicplayer_binary_folder}/resources" + COPYONLY ) # Enable console log in debug diff --git a/cmake/IconFontCppHeaders.cmake b/cmake/IconFontCppHeaders.cmake index dd6a3e3..3d9c00a 100644 --- a/cmake/IconFontCppHeaders.cmake +++ b/cmake/IconFontCppHeaders.cmake @@ -2,10 +2,18 @@ message(STATUS "Configuring IconFontCppHeaders") get_filename_component(ICON_FONT_CPP_HEADERS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/extlibs/IconFontCppHeaders ABSOLUTE) -# Variables -get_filename_component(ICON_FONT_CPP_HEADERS_INCLUDE_DIR ${ICON_FONT_CPP_HEADERS_DIR} ABSOLUTE) -set(ICON_FONT_CPP_HEADERS_LIBRARY "") +# Declare IconFontCppHeaders +add_library(IconFontCppHeaders INTERFACE) + +# Add includes +target_include_directories( + IconFontCppHeaders SYSTEM INTERFACE + "${ICON_FONT_CPP_HEADERS_DIR}" +) + +# Headers target for ide +cmutils_interface_target_generate_headers_target(IconFontCppHeaders IconFontCppHeaders_headers_for_ide) +cmutils_target_source_group(IconFontCppHeaders_headers_for_ide "${ICON_FONT_CPP_HEADERS_DIR}") +cmutils_target_set_ide_folder(IconFontCppHeaders_headers_for_ide "deps/IconFontCppHeaders") -# Message -message("> include: ${ICON_FONT_CPP_HEADERS_INCLUDE_DIR}") message(STATUS "Configuring IconFontCppHeaders - Done") diff --git a/cmake/SFML.cmake b/cmake/SFML.cmake index df8c74c..7d1ab03 100644 --- a/cmake/SFML.cmake +++ b/cmake/SFML.cmake @@ -1,7 +1,7 @@ message(STATUS "Configuring SFML") -# Cache config -set(MAGICPLAYER_COMPILE_SFML_WITH_PROJECT OFF CACHE BOOL "Compile SFML with project, don't search system installation") +# Compile with project option +option(MAGICPLAYER_COMPILE_SFML_WITH_PROJECT "Compile SFML with project, don't search system installation" OFF) # Config set(SFML_MINIMUM_SYSTEM_VERSION 2.5) @@ -15,17 +15,11 @@ if(NOT SFML_USE_EMBEDED) else() find_package(SFML ${SFML_MINIMUM_SYSTEM_VERSION} COMPONENTS system window graphics audio CONFIG) if(SFML_FOUND) - # Variables - set(SFML_INCLUDE_DIR "") - set(SFML_LIBRARY sfml-system sfml-window sfml-graphics sfml-audio) - - # Message - message(WARNING "If the program crashes when using the clipboard," - " it is an SFML bug not yet fixed on your system but already fixed on Github (see https://github.com/SFML/SFML/pull/1437)," - " use CMake with -DMAGICPLAYER_COMPILE_SFML_WITH_PROJECT=ON to compile and use the fixed version with the project") - message("> include: ${SFML_INCLUDE_DIR}") - message("> library: ${SFML_LIBRARY}") - message(STATUS "Configuring SFML - Done") + message(WARNING + "If the program crashes when using the clipboard," + " it is an SFML bug not yet fixed on your system but already fixed on Github (see https://github.com/SFML/SFML/pull/1437)," + " use CMake with -DMAGICPLAYER_COMPILE_SFML_WITH_PROJECT=ON to compile and use the fixed version with the project" + ) else() set(SFML_USE_EMBEDED ON) message(STATUS "SFML system installation not found, compile SFML with project") @@ -45,10 +39,19 @@ if(SFML_USE_EMBEDED) # Subproject add_subdirectory(${SFML_DIR}) - # Configure SFML folder in IDE + # Configure targets foreach(sfml_target IN ITEMS sfml-system sfml-network sfml-window sfml-graphics sfml-audio sfml-main) if(TARGET ${sfml_target}) - set_target_properties(${sfml_target} PROPERTIES FOLDER deps/SFML) + # Configure SFML folder in IDE + cmutils_target_set_ide_folder(${sfml_target} "deps/SFML") + + # Disable warnings on headers + get_target_property(target_include_directories ${sfml_target} INTERFACE_INCLUDE_DIRECTORIES) + set_target_properties(${sfml_target} PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "") + target_include_directories(${sfml_target} SYSTEM INTERFACE ${target_include_directories}) + + # Setup output, put MagicPlayer executable and required SFML dll in the same folder + cmutils_target_set_output_directory(${sfml_target} "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}") endif() endforeach() @@ -62,19 +65,6 @@ if(SFML_USE_EMBEDED) endif() configure_file(${SFML_DIR}/extlibs/bin/${ARCH_FOLDER}/openal32.dll "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}" COPYONLY) endif() - - # Setup targets output, put exe and required SFML dll in the same folder - cmutils_target_set_output_directory(sfml-system "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}") - cmutils_target_set_output_directory(sfml-window "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}") - cmutils_target_set_output_directory(sfml-graphics "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}") - cmutils_target_set_output_directory(sfml-audio "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}") - - # Variables - get_filename_component(SFML_INCLUDE_DIR ${SFML_DIR}/include ABSOLUTE) - set(SFML_LIBRARY sfml-system sfml-window sfml-graphics sfml-audio) - - # Message - message("> include: ${SFML_INCLUDE_DIR}") - message("> library: [compiled with project]") - message(STATUS "Configuring SFML - Done") endif() + +message(STATUS "Configuring SFML - Done") diff --git a/cmake/imgui-sfml.cmake b/cmake/imgui-sfml.cmake index 7e18be8..a7efbd5 100644 --- a/cmake/imgui-sfml.cmake +++ b/cmake/imgui-sfml.cmake @@ -14,13 +14,20 @@ if(is_empty) message(FATAL_ERROR "imgui-sfml dependency is missing, maybe you didn't pull the git submodules") endif() -# Configure imgui for imgui-sfml -#if(NOT OPENGL_INCLUDE_DIR OR NOT OPENGL_LIBRARY) -# message(FATAL_ERROR "Missing OpenGL config") -#endif() -#if(NOT SFML_INCLUDE_DIR OR NOT SFML_LIBRARY) -if(NOT SFML_LIBRARY) - message(FATAL_ERROR "Missing SFML config") +if(NOT TARGET sfml-system) + message(FATAL_ERROR "sfml-system target is missing") +endif() + +if(NOT TARGET sfml-window) + message(FATAL_ERROR "sfml-window target is missing") +endif() + +if(NOT TARGET sfml-graphics) + message(FATAL_ERROR "sfml-graphics target is missing") +endif() + +if(NOT TARGET OpenGL::GL) + message(FATAL_ERROR "OpenGL::GL target is missing") endif() # Copy imgui and imgui-sfml files to cmake build folder @@ -28,7 +35,7 @@ cmutils_configure_folder(${IMGUI_DIR} ${IMGUI_SFML_TARGET_DIR} COPYONLY) cmutils_configure_folder(${IMGUI_SFML_DIR} ${IMGUI_SFML_TARGET_DIR} COPYONLY) # Include imgui-sfml config header in imgui config header file(APPEND "${IMGUI_SFML_TARGET_DIR}/imconfig.h" - "\n#include \"imconfig-SFML.h\"\n" + "\n#include \"imconfig-SFML.h\"\n" ) # Declare imgui-sfml @@ -42,17 +49,17 @@ cmutils_target_sources_folders( # Add includes target_include_directories( - imgui-sfml PRIVATE - "${OPENGL_INCLUDE_DIR}" - "${SFML_INCLUDE_DIR}" + imgui-sfml SYSTEM PUBLIC "${IMGUI_SFML_TARGET_DIR}" ) # Link dependencies target_link_libraries( - imgui-sfml PRIVATE - "${SFML_LIBRARY}" - "${OPENGL_LIBRARY}" + imgui-sfml PUBLIC + OpenGL::GL + sfml-system + sfml-window + sfml-graphics ) # Add definitions @@ -64,7 +71,7 @@ target_compile_definitions( # Configure compile options cmutils_target_configure_compile_options(imgui-sfml) -# Disable warnings +# Disable warnings cmutils_target_disable_warnings(imgui-sfml) # Build in C++17 @@ -74,7 +81,7 @@ cmutils_target_set_standard(imgui-sfml CXX 17) cmutils_target_set_runtime(imgui-sfml DYNAMIC) # Set target IDE folder -cmutils_target_set_ide_folder(imgui-sfml "generated/deps") +cmutils_target_set_ide_folder(imgui-sfml "deps/generated/imgui-sfml") # Group sources for IDEs cmutils_target_source_group(imgui-sfml "${IMGUI_SFML_TARGET_DIR}") @@ -82,12 +89,4 @@ cmutils_target_source_group(imgui-sfml "${IMGUI_SFML_TARGET_DIR}") # Use ccache cmutils_target_use_ccache(imgui-sfml) - -# Variables -get_filename_component(IMGUI_SFML_INCLUDE_DIR ${IMGUI_SFML_TARGET_DIR} ABSOLUTE) -set(IMGUI_SFML_LIBRARY imgui-sfml) - -# Message -message("> include: ${IMGUI_SFML_INCLUDE_DIR}") -message("> library: [compiled with project]") message(STATUS "Configuring imgui-sfml - Done") diff --git a/cmake/json.cmake b/cmake/json.cmake index 125cc13..3533c9d 100644 --- a/cmake/json.cmake +++ b/cmake/json.cmake @@ -8,12 +8,16 @@ if(is_empty) message(FATAL_ERROR "Json dependency is missing, maybe you didn't pull the git submodules") endif() +# Include json set(JSON_BuildTests OFF CACHE INTERNAL "") add_subdirectory(${JSON_DIR}) +if(NOT TARGET nlohmann_json) + message(FATAL_ERROR "nlohmann_json target is missing") +endif() -# Variables -set(JSON_INCLUDE_DIR "") -set(JSON_LIBRARY nlohmann_json::nlohmann_json) +# Disable warnings on nlohmann_json headers +get_target_property(nlohmann_json_include_directories nlohmann_json INTERFACE_INCLUDE_DIRECTORIES) +set_target_properties(nlohmann_json PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "") +target_include_directories(nlohmann_json SYSTEM INTERFACE ${nlohmann_json_include_directories}) -# Message message(STATUS "Configuring json - Done") diff --git a/cmake/libmpg123.cmake b/cmake/libmpg123.cmake index 3861219..e5130e7 100644 --- a/cmake/libmpg123.cmake +++ b/cmake/libmpg123.cmake @@ -11,8 +11,8 @@ set(EMBEDDED_LIBMPG123_MSVC_SHARED_FILENAME_DLL "libmpg123.dll") cmutils_define_os_variables() if(OS_WINDOWS) - # Cache config - set(MAGICPLAYER_STATICALLY_LINK_LIBMPG123 OFF CACHE BOOL "Statically link libmpg123") + # Static link option + option(MAGICPLAYER_STATICALLY_LINK_LIBMPG123 "Statically link libmpg123" OFF) # Embeded library config cmutils_define_compiler_variables() @@ -32,6 +32,7 @@ if(OS_WINDOWS) set(EMBEDED_LIBMPG123_COPY_PATH ${EMBEDED_LIBMPG123_PATH}/lib/${COMPILER_FOLDER}/${ARCH_FOLDER}) if(MAGICPLAYER_STATICALLY_LINK_LIBMPG123) # Static link + set(EMBEDED_LIBMPG123_LIBRARY_TYPE SHARED) set(EMBEDED_LIBMPG123_LINK_PATH ${EMBEDED_LIBMPG123_LINK_PATH}/static) if(COMPILER_CLANG OR COMPILER_MSVC) set(EMBEDED_LIBMPG123_LINK_PATH ${EMBEDED_LIBMPG123_LINK_PATH}/${EMBEDDED_LIBMPG123_MSVC_STATIC_FILENAME}) @@ -40,6 +41,7 @@ if(OS_WINDOWS) endif() else() # Dynamic link + set(EMBEDED_LIBMPG123_LIBRARY_TYPE STATIC) set(EMBEDED_LIBMPG123_LINK_PATH ${EMBEDED_LIBMPG123_LINK_PATH}/shared) set(EMBEDED_LIBMPG123_COPY_PATH ${EMBEDED_LIBMPG123_COPY_PATH}/shared) if(COMPILER_CLANG OR COMPILER_MSVC) @@ -49,13 +51,25 @@ if(OS_WINDOWS) set(EMBEDED_LIBMPG123_LINK_PATH ${EMBEDED_LIBMPG123_LINK_PATH}/${EMBEDDED_LIBMPG123_MINGW_SHARED_FILENAME}) set(EMBEDED_LIBMPG123_COPY_PATH ${EMBEDED_LIBMPG123_COPY_PATH}/${EMBEDDED_LIBMPG123_MINGW_SHARED_FILENAME}) endif() + # Copy binary to output folder configure_file(${EMBEDED_LIBMPG123_COPY_PATH} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} COPYONLY) endif() - # Variables - get_filename_component(LIBMPG123_INCLUDE_DIR ${EMBEDED_LIBMPG123_PATH}/include ABSOLUTE) - get_filename_component(LIBMPG123_LIBRARY ${EMBEDED_LIBMPG123_LINK_PATH} ABSOLUTE) + # Declare libmpg123 + add_library(libmpg123 ${EMBEDED_LIBMPG123_LIBRARY_TYPE} IMPORTED) + + # Add includes + target_include_directories( + libmpg123 SYSTEM INTERFACE + "${EMBEDED_LIBMPG123_PATH}/include" + ) + + # Add linked binary + set_target_properties( + libmpg123 PROPERTIES + IMPORTED_LOCATION "${EMBEDED_LIBMPG123_LINK_PATH}" + ) else() # Find PkgConfig find_package(PkgConfig REQUIRED) @@ -69,12 +83,20 @@ else() message(FATAL_ERROR "libmpg123 not found (dev version must be installed on the system to compile)") endif() - # Variables - set(LIBMPG123_INCLUDE_DIR ${LIBMPG123_INCLUDE_DIRS}) - set(LIBMPG123_LIBRARY ${LIBMPG123_LIBRARIES}) + # Declare libmpg123 + add_library(libmpg123 SHARED IMPORTED) + + # Add includes + target_include_directories( + libmpg123 SYSTEM INTERFACE + "${LIBMPG123_INCLUDE_DIRS}" + ) + + # Add linked binary + set_target_properties( + libmpg123 PROPERTIES + IMPORTED_LOCATION "${LIBMPG123_LINK_LIBRARIES}" + ) endif() -# Message -message("> include: ${LIBMPG123_INCLUDE_DIR}") -message("> library: ${LIBMPG123_LIBRARY}") message(STATUS "Configuring libmpg123 - Done") diff --git a/cmake/opengl.cmake b/cmake/opengl.cmake index 079687f..d5314d6 100644 --- a/cmake/opengl.cmake +++ b/cmake/opengl.cmake @@ -9,9 +9,9 @@ if(NOT OPENGL_FOUND) return() endif() -# Variables -set(OPENGL_INCLUDE_DIR ${OPENGL_INCLUDE_DIRS}) -set(OPENGL_LIBRARY ${OPENGL_gl_LIBRARY}) +if(NOT TARGET OpenGL::GL) + message(FATAL_ERROR "OpenGL::GL target is missing") +endif() # Message message(STATUS "Configuring OpenGL - Done") diff --git a/cmake/spdlog.cmake b/cmake/spdlog.cmake index 9f2695f..155d46e 100644 --- a/cmake/spdlog.cmake +++ b/cmake/spdlog.cmake @@ -8,10 +8,20 @@ if(is_empty) message(FATAL_ERROR "Spdlog dependency is missing, maybe you didn't pull the git submodules") endif() -# Variables -get_filename_component(SPDLOG_INCLUDE_DIR ${SPDLOG_DIR}/include ABSOLUTE) -set(SPDLOG_LIBRARY "") +# Include spdlog +add_subdirectory(${SPDLOG_DIR}) +if(NOT TARGET spdlog) + message(FATAL_ERROR "spdlog target is missing") +endif() + +# Disable warnings on spdlog headers +get_target_property(spdlog_include_directories spdlog INTERFACE_INCLUDE_DIRECTORIES) +set_target_properties(spdlog PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "") +target_include_directories(spdlog SYSTEM INTERFACE ${spdlog_include_directories}) + +if(TARGET spdlog_headers_for_ide) + # Set target IDE folder + cmutils_target_set_ide_folder(spdlog_headers_for_ide "deps/spdlog") +endif() -# Message -message("> include: ${SPDLOG_INCLUDE_DIR}") message(STATUS "Configuring spdlog - Done") diff --git a/cmake/taglib.cmake b/cmake/taglib.cmake index ce27434..d645c98 100644 --- a/cmake/taglib.cmake +++ b/cmake/taglib.cmake @@ -62,7 +62,7 @@ target_compile_definitions(tag PUBLIC HAVE_CONFIG_H) # Configure compile options cmutils_target_configure_compile_options(tag) -# Disable warnings +# Disable warnings cmutils_target_disable_warnings(tag) # Build in C++11 @@ -90,13 +90,14 @@ file( DESTINATION "${TAGLIB_IMPORTED_INCLUDE_DIR}/taglib" PATTERN "*/tagutils.h" EXCLUDE ) -target_include_directories(taglib SYSTEM INTERFACE "${TAGLIB_IMPORTED_INCLUDE_DIR}") +target_include_directories( + taglib SYSTEM INTERFACE + "${TAGLIB_IMPORTED_INCLUDE_DIR}" +) -# Variables -set(TAGLIB_INCLUDE_DIR "") -set(TAGLIB_LIBRARY taglib) +# Headers target for ide +cmutils_interface_target_generate_headers_target(taglib taglib_headers_for_ide) +cmutils_target_source_group(taglib_headers_for_ide "${TAGLIB_IMPORTED_INCLUDE_DIR}") +cmutils_target_set_ide_folder(taglib_headers_for_ide "deps/generated/taglib") -# Message -message("> include: ${TAGLIB_IMPORTED_INCLUDE_DIR}/taglib") -message("> library: [compiled with project]") message(STATUS "Configuring taglib - Done") diff --git a/cmake/utfcpp.cmake b/cmake/utfcpp.cmake index 2d88ad1..3e1894f 100644 --- a/cmake/utfcpp.cmake +++ b/cmake/utfcpp.cmake @@ -8,10 +8,17 @@ if(is_empty) message(FATAL_ERROR "utfcpp dependency is missing, maybe you didn't pull the git submodules") endif() -# Variables -get_filename_component(UTFCPP_INCLUDE_DIR ${UTFCPP_DIR}/source ABSOLUTE) -set(UTFCPP_LIBRARY "") +# Include utfcpp +set(UTF8_TESTS OFF CACHE INTERNAL "") +set(UTF8_SAMPLES OFF CACHE INTERNAL "") +add_subdirectory(${UTFCPP_DIR}) +if(NOT TARGET utf8cpp) + message(FATAL_ERROR "utf8cpp target is missing") +endif() + +# Disable warnings on utf8cpp headers +get_target_property(utf8cpp_include_directories utf8cpp INTERFACE_INCLUDE_DIRECTORIES) +set_target_properties(utf8cpp PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "") +target_include_directories(utf8cpp SYSTEM INTERFACE ${utf8cpp_include_directories}) -# Message -message("> include: ${UTFCPP_INCLUDE_DIR}") message(STATUS "Configuring utfcpp - Done")