1- # ArduinoLibrary .cmake
1+ # Arduino .cmake
22# Defines a function to easily add Arduino-style libraries to your CMake project.
33#
44# Example usage for arduino-SAM library from GitHub
5- # Place this in your CMakeLists.txt after including ArduinoLibrary .cmake
5+ # Place this in your CMakeLists.txt after including Arduino .cmake
66#
7- # include(${CMAKE_SOURCE_DIR}/ArduinoLibrary .cmake)
7+ # include(${CMAKE_SOURCE_DIR}/Arduino .cmake)
88# arduino_library(arduino-SAM "https://github.com/pschatzmann/arduino-SAM")
99# target_link_libraries(your_target PRIVATE arduino-SAM)
1010
@@ -31,31 +31,43 @@ function(arduino_library LIB_NAME LIB_PATH)
3131 endif ()
3232 set (LIB_PATH "${CLONE_DIR} " )
3333 endif ()
34- set (INC_DIR "${LIB_PATH} /src" )
35- file (GLOB SRC_FILES
36- "${LIB_PATH} /src/*.c"
37- "${LIB_PATH} /src/*.cpp"
38- )
34+ if (EXISTS "${LIB_PATH} /src" )
35+ set (INC_DIR "${LIB_PATH} /src" )
36+ file (GLOB_RECURSE SRC_FILES
37+ "${LIB_PATH} /src/*.c"
38+ "${LIB_PATH} /src/*.cpp"
39+ )
40+ else ()
41+ # Legacy libraries without src folder
42+ set (INC_DIR "${LIB_PATH} " )
43+ file (GLOB_RECURSE SRC_FILES
44+ "${LIB_PATH} /*.c"
45+ "${LIB_PATH} /*.cpp"
46+ )
47+ endif ()
3948 # Only create library if there are source files
4049 if (SRC_FILES)
4150 add_library (${LIB_NAME} STATIC ${SRC_FILES} )
4251 target_compile_options (${LIB_NAME} PRIVATE -DPROGMEM=)
4352 # Ensure C files are compiled as C, not C++
4453 set_target_properties (${LIB_NAME} PROPERTIES LINKER_LANGUAGE C)
54+ target_include_directories (${LIB_NAME} PUBLIC ${INC_DIR} )
4555 else ()
4656 # Create a header-only interface library if no source files
4757 add_library (${LIB_NAME} INTERFACE )
58+ target_include_directories (${LIB_NAME} INTERFACE ${INC_DIR} )
4859 endif ()
49- target_include_directories (${LIB_NAME} PUBLIC ${INC_DIR} )
5060 # Link arduino_emulator to propagate its include directories
5161 if (TARGET arduino_emulator)
5262 if (SRC_FILES)
5363 target_link_libraries (${LIB_NAME} PUBLIC arduino_emulator)
5464 else ()
5565 # For interface libraries, use INTERFACE linkage
5666 target_link_libraries (${LIB_NAME} INTERFACE arduino_emulator)
57- endif ()
67+ endif ()
68+
5869 endif ()
70+
5971endfunction ()
6072
6173# arduino_sketch(<name> <ino_file> [LIBRARIES <lib1> <lib2> ...] [DEFINITIONS <def1> <def2> ...])
@@ -107,11 +119,7 @@ function(arduino_sketch name ino_file)
107119 target_compile_definitions (${name} PUBLIC ${ARG_DEFINITIONS} )
108120 endif ()
109121
110- # Add platform-specific libraries
111- if (USE_RPI)
112- target_link_libraries (${name} gpiod)
113- endif (USE_RPI)
114-
122+ # Handle FTDI support if specified
115123 if (USE_FTDI)
116124 # Find and link libftdi1
117125 find_package (PkgConfig REQUIRED)
0 commit comments