add global definitions for all paths

This commit is contained in:
AlexandreRouma 2024-08-25 21:40:01 +02:00
parent d5bc0fa3c3
commit d905d19020
5 changed files with 70 additions and 36 deletions

View File

@ -106,14 +106,45 @@ if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
endif() endif()
endif() endif()
# Set up the standard install directories # Include standard install directory definitions
include(GNUInstallDirs)
# Set up SDR++ directory load paths
if (MSVC) if (MSVC)
set(CMAKE_INSTALL_BINDIR "/") set(SDRPP_MODULES_LOAD_DIR "./modules")
set(CMAKE_INSTALL_LIBDIR "/") set(SDRPP_RES_LOAD_DIR "./res")
set(CMAKE_INSTALL_INCLUDEDIR "include") elseif (USE_BUNDLE_DEFAULTS)
set(CMAKE_INSTALL_DATAROOTDIR "/") 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() 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() endif()
# Configure toolchain for android # Configure toolchain for android
@ -375,15 +406,16 @@ endif ()
# Create module cmake file # Create module cmake file
configure_file(${CMAKE_SOURCE_DIR}/sdrpp_module.cmake ${CMAKE_CURRENT_BINARY_DIR}/sdrpp_module.cmake @ONLY) configure_file(${CMAKE_SOURCE_DIR}/sdrpp_module.cmake ${CMAKE_CURRENT_BINARY_DIR}/sdrpp_module.cmake @ONLY)
# Install directives # Create desktop entry file
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)
configure_file(${CMAKE_SOURCE_DIR}/sdrpp.desktop ${CMAKE_CURRENT_BINARY_DIR}/sdrpp.desktop @ONLY) 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") if (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/sdrpp.desktop DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/applications) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/sdrpp.desktop DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/applications)
endif () endif ()

View File

@ -18,6 +18,10 @@ if (MSVC)
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON) set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
endif () 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 # Configure backend sources
if (OPT_BACKEND_GLFW) if (OPT_BACKEND_GLFW)
file(GLOB_RECURSE BACKEND_SRC "backends/glfw/*.cpp" "backends/glfw/*.c") 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 # Set compiler options
target_compile_options(sdrpp_core PRIVATE ${SDRPP_COMPILER_FLAGS}) 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 # Include core headers
target_include_directories(sdrpp_core PUBLIC "src/") target_include_directories(sdrpp_core PUBLIC "src/")
target_include_directories(sdrpp_core PUBLIC "src/imgui") 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" # cmake .. "-DCMAKE_TOOLCHAIN_FILE=C:/dev/vcpkg/scripts/buildsystems/vcpkg.cmake"
# Install directives # Install directives
install(TARGETS sdrpp_core DESTINATION ${CMAKE_INSTALL_LIBDIR}) install(TARGETS sdrpp_core DESTINATION ${SDRPP_LIB_INSTALL_DIR})

View File

@ -24,14 +24,16 @@
#include <Windows.h> #include <Windows.h>
#endif #endif
#ifndef INSTALL_PREFIX
#ifdef __APPLE__ // Default install dirs to make the IDE happy
#define INSTALL_PREFIX "/usr/local" #ifndef SDRPP_MODULES_LOAD_DIR
#else #define SDRPP_MODULES_LOAD_DIR ""
#define INSTALL_PREFIX "/usr"
#endif #endif
#ifndef SDRPP_RES_LOAD_DIR
#define SDRPP_RES_LOAD_DIR ""
#endif #endif
namespace core { namespace core {
ConfigManager configManager; ConfigManager configManager;
ModuleManager moduleManager; ModuleManager moduleManager;
@ -248,20 +250,15 @@ int sdrpp_main(int argc, char* argv[]) {
defConfig["lockMenuOrder"] = false; defConfig["lockMenuOrder"] = false;
#endif #endif
#if defined(_WIN32) #if define(__ANDROID__)
defConfig["modulesDirectory"] = "./modules"; defConfig["modulesDirectory"] = root + SDRPP_MODULES_LOAD_DIR;
defConfig["resourcesDirectory"] = "./res"; defConfig["resourcesDirectory"] = root + SDRPP_RES_LOAD_DIR;
#elif defined(IS_MACOS_BUNDLE)
defConfig["modulesDirectory"] = "../Plugins";
defConfig["resourcesDirectory"] = "../Resources";
#elif defined(__ANDROID__)
defConfig["modulesDirectory"] = root + "/modules";
defConfig["resourcesDirectory"] = root + "/res";
#else #else
defConfig["modulesDirectory"] = INSTALL_PREFIX "/lib/sdrpp/plugins"; defConfig["modulesDirectory"] = SDRPP_MODULES_LOAD_DIR;
defConfig["resourcesDirectory"] = INSTALL_PREFIX "/share/sdrpp"; defConfig["resourcesDirectory"] = SDRPP_RES_LOAD_DIR;
#endif #endif
// Load config // Load config
flog::info("Loading config"); flog::info("Loading config");
core::configManager.setPath(root + "/config.json"); core::configManager.setPath(root + "/config.json");

View File

@ -3,7 +3,7 @@ Encoding=UTF-8
Version=1.0 Version=1.0
Type=Application Type=Application
Terminal=false Terminal=false
Exec=@CMAKE_INSTALL_PREFIX@/bin/sdrpp Exec=@SDRPP_BIN_INSTALL_DIR@/sdrpp
Name=SDR++ Name=SDR++
Icon=@CMAKE_INSTALL_PREFIX@/share/sdrpp/icons/sdrpp.png Icon=@SDRPP_RES_INSTALL_DIR@/icons/sdrpp.png
Categories=HamRadio Categories=HamRadio

View File

@ -6,6 +6,10 @@ if (NOT SDRPP_MODULE_COMPILER_FLAGS)
set(SDRPP_MODULE_COMPILER_FLAGS @SDRPP_MODULE_COMPILER_FLAGS@) set(SDRPP_MODULE_COMPILER_FLAGS @SDRPP_MODULE_COMPILER_FLAGS@)
endif () 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 # Created shared lib and link to core
add_library(${PROJECT_NAME} SHARED ${SRC}) add_library(${PROJECT_NAME} SHARED ${SRC})
target_link_libraries(${PROJECT_NAME} PRIVATE sdrpp_core) 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}) target_compile_options(${PROJECT_NAME} PRIVATE ${SDRPP_MODULE_COMPILER_FLAGS})
# Install directives # Install directives
install(TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_LIBDIR}/sdrpp/plugins) install(TARGETS ${PROJECT_NAME} DESTINATION ${SDRPP_MODULES_INSTALL_DIR})