Skip to content

Commit 28d7257

Browse files
authored
build(cmake): detect and use SDL2 include path correctly (#193)
Not all distros/packages place the SDL2 installation into a directory named SDL2. Just to name a prominent example: Homebrew. cmake's find_package will correctly identify SDL2 and provide the required include/lib paths.
1 parent ac140aa commit 28d7257

12 files changed

Lines changed: 13 additions & 163 deletions

File tree

CMakeLists.txt

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ target_include_directories(sim-base PUBLIC "lv_drivers")
113113

114114
target_include_directories(sim-base PUBLIC "${InfiniTime_DIR}/src") # InfiniTime drivers, components and all
115115

116+
find_package(SDL2 REQUIRED)
117+
target_link_libraries(sim-base PUBLIC SDL2::SDL2)
116118

117119
set(MONITOR_ZOOM 1 CACHE STRING "Scale simulator window by this factor")
118120
if(MONITOR_ZOOM MATCHES "^[0-9]\.?[0-9]*")
@@ -319,13 +321,6 @@ if(NOT alarmControllerFileSystemEntries STREQUAL "")
319321
endif()
320322

321323
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
322-
# Special case for SDL2 dependency, goal is to find a config that exports SDL2::SDL2 target
323-
# libsdl2-dev has a `sdl2-config.cmake` that doesn't export this, but vcpkg does..
324-
find_package(SDL2 CONFIG QUIET)
325-
if(NOT TARGET SDL2::SDL2)
326-
find_package(SDL2 MODULE REQUIRED)
327-
endif()
328-
target_link_libraries(infinisim PRIVATE SDL2::SDL2)
329324

330325
# Some toolchains (e.g. g++-8) require to explicitly link with the standard filesystem library
331326
# See https://github.com/InfiniTimeOrg/InfiniSim/issues/57#issuecomment-1386889378
@@ -352,7 +347,7 @@ endif()
352347

353348
target_include_directories(infinisim PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/external/gif-h")
354349

355-
# embedd background image for the status window to use
350+
# embed background image for the status window to use
356351
add_subdirectory(img)
357352
add_dependencies(infinisim infinisim_img_background)
358353

@@ -380,7 +375,6 @@ add_executable(littlefs-do
380375
target_link_libraries(littlefs-do PUBLIC sim-base)
381376
target_link_libraries(littlefs-do PUBLIC littlefs)
382377

383-
target_link_libraries(littlefs-do PRIVATE SDL2::SDL2)
384378
target_link_libraries(littlefs-do PRIVATE infinitime_fonts)
385379

386380
add_subdirectory(external/miniz)

cmake/FindSDL2.cmake

Lines changed: 0 additions & 144 deletions
This file was deleted.

lv_drv_conf.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@
107107
#define MONITOR_DOUBLE_BUFFERED 0
108108

109109
/*Eclipse: <SDL2/SDL.h> Visual Studio: <SDL.h>*/
110-
#define MONITOR_SDL_INCLUDE_PATH <SDL2/SDL.h>
110+
#define MONITOR_SDL_INCLUDE_PATH <SDL.h>
111111

112112
/*Different rendering might be used if running in a Virtual machine*/
113113
#define MONITOR_VIRTUAL_MACHINE 0

main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#include <stdlib.h>
1212
#include <unistd.h>
1313
#define SDL_MAIN_HANDLED /*To fix SDL's "undefined reference to WinMain" issue*/
14-
#include <SDL2/SDL.h>
14+
#include <SDL.h>
1515
#include "lvgl/lvgl.h"
1616
// #include "lvgl/examples/lv_examples.h"
1717
// #include "lv_demos/lv_demo.h"

sim/displayapp/LittleVgl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
// lv-sim monitor display driver for monitor_flush() function
1212
#include "lv_drivers/display/monitor.h"
1313

14-
#include <SDL2/SDL.h>
14+
#include <SDL.h>
1515
#include <array>
1616

1717
using namespace Pinetime::Components;

sim/drivers/Cst816s.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include "drivers/Cst816s.h"
22
#include "lv_drv_conf.h" // MONITOR_ZOOM
3-
#include <SDL2/SDL.h>
3+
#include <SDL.h>
44
#include <libraries/log/nrf_log.h>
55
#include <cmath>
66

sim/libraries/delay/nrf_delay.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#include "libraries/delay/nrf_delay.h"
2-
#include <SDL2/SDL.h>
2+
#include <SDL.h>
33

44
void nrf_delay_ms(uint32_t ms_time)
55
{

sim/nrfx/hal/nrf_gpio.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
#include "drivers/PinMap.h"
44

5-
#include <SDL2/SDL.h>
5+
#include <SDL.h>
66
#include <stdexcept>
77
#include <string> // std::to_string
88

sim/queue.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include "FreeRTOS.h"
22
#include "queue.h"
33
#include <stdexcept>
4-
#include <SDL2/SDL.h>
4+
#include <SDL.h>
55

66
QueueHandle_t xQueueCreate(const UBaseType_t uxQueueLength, const UBaseType_t uxItemSize) {
77
Queue_t* xQueue = new Queue_t;

sim/semphr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#include "semphr.h"
2-
#include <SDL2/SDL.h>
2+
#include <SDL.h>
33
#include <stdexcept>
44

55
QueueHandle_t xSemaphoreCreateMutex() {

0 commit comments

Comments
 (0)