Skip to content

Commit

Permalink
add global definitions for all paths
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexandreRouma committed Aug 25, 2024
1 parent d5bc0fa commit d905d19
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 36 deletions.
58 changes: 45 additions & 13 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 ()
Expand Down
9 changes: 5 additions & 4 deletions core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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")
Expand Down Expand Up @@ -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})
install(TARGETS sdrpp_core DESTINATION ${SDRPP_LIB_INSTALL_DIR})
29 changes: 13 additions & 16 deletions core/src/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,16 @@
#include <Windows.h>
#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;
Expand Down Expand Up @@ -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");
Expand Down
4 changes: 2 additions & 2 deletions sdrpp.desktop
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 5 additions & 1 deletion sdrpp_module.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
install(TARGETS ${PROJECT_NAME} DESTINATION ${SDRPP_MODULES_INSTALL_DIR})

0 comments on commit d905d19

Please sign in to comment.