From d905d1902077cdd29067d0c825108df38a7789c8 Mon Sep 17 00:00:00 2001 From: AlexandreRouma Date: Sun, 25 Aug 2024 21:40:01 +0200 Subject: [PATCH] add global definitions for all paths --- CMakeLists.txt | 58 +++++++++++++++++++++++++++++++++++---------- core/CMakeLists.txt | 9 +++---- core/src/core.cpp | 29 ++++++++++------------- sdrpp.desktop | 4 ++-- sdrpp_module.cmake | 6 ++++- 5 files changed, 70 insertions(+), 36 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index bfcecf798..1a61f9ef6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -106,14 +106,45 @@ if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) endif() endif() -# Set up the standard install directories +# Include standard install directory definitions +include(GNUInstallDirs) + +# Set up SDR++ directory load paths if (MSVC) - set(CMAKE_INSTALL_BINDIR "/") - set(CMAKE_INSTALL_LIBDIR "/") - set(CMAKE_INSTALL_INCLUDEDIR "include") - set(CMAKE_INSTALL_DATAROOTDIR "/") + set(SDRPP_MODULES_LOAD_DIR "./modules") + set(SDRPP_RES_LOAD_DIR "./res") +elseif (USE_BUNDLE_DEFAULTS) + set(SDRPP_MODULES_LOAD_DIR "../Plugins") + set(SDRPP_RES_LOAD_DIR "../Resources") +elseif (ANDROID) + set(SDRPP_MODULES_LOAD_DIR "/modules") + set(SDRPP_RES_LOAD_DIR "/res") else() - include(GNUInstallDirs) + set(SDRPP_MODULES_LOAD_DIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/sdrpp/plugins") + set(SDRPP_RES_LOAD_DIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATAROOTDIR}/sdrpp") +endif() + +# Set up SDR++ directory install paths +if (MSVC) + set(SDRPP_BIN_INSTALL_DIR "/") + set(SDRPP_LIB_INSTALL_DIR "/") + set(SDRPP_MODULES_INSTALL_DIR "modules") + set(SDRPP_RES_INSTALL_DIR "res") +elseif (USE_BUNDLE_DEFAULTS) + set(SDRPP_BIN_INSTALL_DIR "Contents/MacOS") + set(SDRPP_LIB_INSTALL_DIR "Contents/Frameworks") + set(SDRPP_MODULES_INSTALL_DIR "Contents/Plugins") + set(SDRPP_RES_INSTALL_DIR "Contents/Resources") +elseif (ANDROID) + set(SDRPP_BIN_INSTALL_DIR "${CMAKE_INSTALL_BINDIR}") + set(SDRPP_LIB_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}") + set(SDRPP_MODULES_INSTALL_DIR "/modules") + set(SDRPP_RES_INSTALL_DIR "/res") +else() + set(SDRPP_BIN_INSTALL_DIR "${CMAKE_INSTALL_BINDIR}") + set(SDRPP_LIB_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}") + set(SDRPP_MODULES_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}/sdrpp/plugins") + set(SDRPP_RES_INSTALL_DIR "${CMAKE_INSTALL_DATAROOTDIR}/sdrpp") endif() # Configure toolchain for android @@ -375,15 +406,16 @@ endif () # Create module cmake file configure_file(${CMAKE_SOURCE_DIR}/sdrpp_module.cmake ${CMAKE_CURRENT_BINARY_DIR}/sdrpp_module.cmake @ONLY) -# Install directives -install(TARGETS sdrpp DESTINATION ${CMAKE_INSTALL_BINDIR}) -install(DIRECTORY ${CMAKE_SOURCE_DIR}/root/res/bandplans DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/sdrpp) -install(DIRECTORY ${CMAKE_SOURCE_DIR}/root/res/colormaps DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/sdrpp) -install(DIRECTORY ${CMAKE_SOURCE_DIR}/root/res/fonts DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/sdrpp) -install(DIRECTORY ${CMAKE_SOURCE_DIR}/root/res/icons DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/sdrpp) -install(DIRECTORY ${CMAKE_SOURCE_DIR}/root/res/themes DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/sdrpp) +# Create desktop entry file configure_file(${CMAKE_SOURCE_DIR}/sdrpp.desktop ${CMAKE_CURRENT_BINARY_DIR}/sdrpp.desktop @ONLY) +# Install directives +install(TARGETS sdrpp DESTINATION ${SDRPP_BIN_INSTALL_DIR}) +install(DIRECTORY ${CMAKE_SOURCE_DIR}/root/res/bandplans DESTINATION ${SDRPP_RES_INSTALL_DIR}) +install(DIRECTORY ${CMAKE_SOURCE_DIR}/root/res/colormaps DESTINATION ${SDRPP_RES_INSTALL_DIR}) +install(DIRECTORY ${CMAKE_SOURCE_DIR}/root/res/fonts DESTINATION ${SDRPP_RES_INSTALL_DIR}) +install(DIRECTORY ${CMAKE_SOURCE_DIR}/root/res/icons DESTINATION ${SDRPP_RES_INSTALL_DIR}) +install(DIRECTORY ${CMAKE_SOURCE_DIR}/root/res/themes DESTINATION ${SDRPP_RES_INSTALL_DIR}) if (${CMAKE_SYSTEM_NAME} MATCHES "Linux") install(FILES ${CMAKE_CURRENT_BINARY_DIR}/sdrpp.desktop DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/applications) endif () diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt index 213f03ad3..e336232e5 100644 --- a/core/CMakeLists.txt +++ b/core/CMakeLists.txt @@ -18,6 +18,10 @@ if (MSVC) set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON) endif () +# Add compiler definitions for the directories +add_definitions(-DSDRPP_MODULES_LOAD_DIR=${SDRPP_MODULES_LOAD_DIR}) +add_definitions(-DSDRPP_RES_LOAD_DIR=${SDRPP_RES_LOAD_DIR}) + # Configure backend sources if (OPT_BACKEND_GLFW) file(GLOB_RECURSE BACKEND_SRC "backends/glfw/*.cpp" "backends/glfw/*.c") @@ -33,9 +37,6 @@ add_library(sdrpp_core SHARED ${SRC} ${BACKEND_SRC}) # Set compiler options target_compile_options(sdrpp_core PRIVATE ${SDRPP_COMPILER_FLAGS}) -# Set the install prefix -target_compile_definitions(sdrpp_core PUBLIC INSTALL_PREFIX="${CMAKE_INSTALL_PREFIX}") - # Include core headers target_include_directories(sdrpp_core PUBLIC "src/") target_include_directories(sdrpp_core PUBLIC "src/imgui") @@ -167,4 +168,4 @@ set(CORE_FILES ${RUNTIME_OUTPUT_DIRECTORY} PARENT_SCOPE) # cmake .. "-DCMAKE_TOOLCHAIN_FILE=C:/dev/vcpkg/scripts/buildsystems/vcpkg.cmake" # Install directives -install(TARGETS sdrpp_core DESTINATION ${CMAKE_INSTALL_LIBDIR}) \ No newline at end of file +install(TARGETS sdrpp_core DESTINATION ${SDRPP_LIB_INSTALL_DIR}) \ No newline at end of file diff --git a/core/src/core.cpp b/core/src/core.cpp index 1fcbf956d..bd6fab05f 100644 --- a/core/src/core.cpp +++ b/core/src/core.cpp @@ -24,14 +24,16 @@ #include #endif -#ifndef INSTALL_PREFIX -#ifdef __APPLE__ -#define INSTALL_PREFIX "/usr/local" -#else -#define INSTALL_PREFIX "/usr" + +// Default install dirs to make the IDE happy +#ifndef SDRPP_MODULES_LOAD_DIR +#define SDRPP_MODULES_LOAD_DIR "" #endif +#ifndef SDRPP_RES_LOAD_DIR +#define SDRPP_RES_LOAD_DIR "" #endif + namespace core { ConfigManager configManager; ModuleManager moduleManager; @@ -248,19 +250,14 @@ int sdrpp_main(int argc, char* argv[]) { defConfig["lockMenuOrder"] = false; #endif -#if defined(_WIN32) - defConfig["modulesDirectory"] = "./modules"; - defConfig["resourcesDirectory"] = "./res"; -#elif defined(IS_MACOS_BUNDLE) - defConfig["modulesDirectory"] = "../Plugins"; - defConfig["resourcesDirectory"] = "../Resources"; -#elif defined(__ANDROID__) - defConfig["modulesDirectory"] = root + "/modules"; - defConfig["resourcesDirectory"] = root + "/res"; +#if define(__ANDROID__) + defConfig["modulesDirectory"] = root + SDRPP_MODULES_LOAD_DIR; + defConfig["resourcesDirectory"] = root + SDRPP_RES_LOAD_DIR; #else - defConfig["modulesDirectory"] = INSTALL_PREFIX "/lib/sdrpp/plugins"; - defConfig["resourcesDirectory"] = INSTALL_PREFIX "/share/sdrpp"; + defConfig["modulesDirectory"] = SDRPP_MODULES_LOAD_DIR; + defConfig["resourcesDirectory"] = SDRPP_RES_LOAD_DIR; #endif + // Load config flog::info("Loading config"); diff --git a/sdrpp.desktop b/sdrpp.desktop index 57a415181..694924928 100644 --- a/sdrpp.desktop +++ b/sdrpp.desktop @@ -3,7 +3,7 @@ Encoding=UTF-8 Version=1.0 Type=Application Terminal=false -Exec=@CMAKE_INSTALL_PREFIX@/bin/sdrpp +Exec=@SDRPP_BIN_INSTALL_DIR@/sdrpp Name=SDR++ -Icon=@CMAKE_INSTALL_PREFIX@/share/sdrpp/icons/sdrpp.png +Icon=@SDRPP_RES_INSTALL_DIR@/icons/sdrpp.png Categories=HamRadio \ No newline at end of file diff --git a/sdrpp_module.cmake b/sdrpp_module.cmake index 5f0a2c16d..d87f2e885 100644 --- a/sdrpp_module.cmake +++ b/sdrpp_module.cmake @@ -6,6 +6,10 @@ if (NOT SDRPP_MODULE_COMPILER_FLAGS) set(SDRPP_MODULE_COMPILER_FLAGS @SDRPP_MODULE_COMPILER_FLAGS@) endif () +# Add compiler definitions for the directories +add_definitions(-DSDRPP_MODULES_LOAD_DIR=${SDRPP_MODULES_LOAD_DIR}) +add_definitions(-DSDRPP_RES_LOAD_DIR=${SDRPP_RES_LOAD_DIR}) + # Created shared lib and link to core add_library(${PROJECT_NAME} SHARED ${SRC}) target_link_libraries(${PROJECT_NAME} PRIVATE sdrpp_core) @@ -16,4 +20,4 @@ set_target_properties(${PROJECT_NAME} PROPERTIES PREFIX "") target_compile_options(${PROJECT_NAME} PRIVATE ${SDRPP_MODULE_COMPILER_FLAGS}) # Install directives -install(TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_LIBDIR}/sdrpp/plugins) \ No newline at end of file +install(TARGETS ${PROJECT_NAME} DESTINATION ${SDRPP_MODULES_INSTALL_DIR}) \ No newline at end of file