Skip to content

Commit

Permalink
Fix compilation on arm-none-eabi (#700)
Browse files Browse the repository at this point in the history
  • Loading branch information
calcmogul authored Jan 19, 2025
1 parent ec934bd commit f9cc55f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
17 changes: 11 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,11 @@ option(DISABLE_DIAGNOSTICS "Disable diagnostics support at compile-time" OFF)
include(CompilerFlags)

file(GLOB_RECURSE Sleipnir_src src/*.cpp)
add_library(Sleipnir ${Sleipnir_src})
if(TARGET_SUPPORTS_SHARED_LIBS)
add_library(Sleipnir ${Sleipnir_src})
else()
add_library(Sleipnir STATIC ${Sleipnir_src})
endif()
add_library(Sleipnir::Sleipnir ALIAS Sleipnir)
compiler_flags(Sleipnir)
target_include_directories(Sleipnir PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src)
Expand All @@ -95,9 +99,10 @@ option(USE_SYSTEM_EIGEN "Use system eigen" OFF)
option(USE_SYSTEM_NANOBIND "Use system nanobind" OFF)

# Required for std::async()
find_package(Threads REQUIRED)

target_link_libraries(Sleipnir PUBLIC Threads::Threads)
find_package(Threads)
if(Threads_FOUND)
target_link_libraries(Sleipnir PUBLIC Threads::Threads)
endif()

if(DISABLE_DIAGNOSTICS)
target_compile_definitions(Sleipnir PUBLIC SLEIPNIR_DISABLE_DIAGNOSTICS)
Expand All @@ -119,7 +124,7 @@ endif()

target_link_libraries(Sleipnir PUBLIC Eigen3::Eigen)

if(BUILD_TESTING)
if(BUILD_TESTING AND NOT CMAKE_CROSSCOMPILING)
# Catch2 dependency
fetchcontent_declare(
Catch2
Expand Down Expand Up @@ -227,7 +232,7 @@ if(BUILD_BENCHMARKS)
endif()
endif()

if(BUILD_TESTING)
if(BUILD_TESTING AND NOT CMAKE_CROSSCOMPILING)
enable_testing()
list(APPEND CMAKE_MODULE_PATH ${Catch2_SOURCE_DIR}/extras)
include(Catch)
Expand Down
2 changes: 1 addition & 1 deletion cmake/modules/CompilerFlags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ macro(compiler_flags target)
if(NOT MSVC)
target_compile_options(
${target}
PRIVATE -Wall -pedantic -Wextra -Werror
PRIVATE -Wall -pedantic -Wextra -Werror -Wno-psabi
)
else()
# Suppress the following warnings:
Expand Down
12 changes: 12 additions & 0 deletions cmake/toolchains/arm-none-eabi.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
set(CMAKE_SYSTEM_NAME Generic)
set(CMAKE_SYSTEM_PROCESSOR arm)

set(CMAKE_C_COMPILER "arm-none-eabi-gcc")
set(CMAKE_CXX_COMPILER "arm-none-eabi-g++")

set(CMAKE_EXE_LINKER_FLAGS "--specs=nosys.specs" CACHE INTERNAL "")

set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)

0 comments on commit f9cc55f

Please sign in to comment.