Files
allwpilib/wpiutil/CMakeLists.txt
Tyler Veness af7d68e993 [wpiutil] Use C++23 stacktrace library on Windows (#6839)
This lets us remove the unmaintained StackWalker library and its hacky
upstream_utils script.

@Gold856 reported that StackWalker gives blank stacktraces:
https://discord.com/channels/176186766946992128/368993897495527424/1261940029287301150.
They also reported an earlier version of this PR giving the following
stacktrace instead:
```
D:\allwpilib\developerRobot\src\main\native\cpp\Robot.cpp(18): developerRobotCpp!Robot::RobotInit+0xB6
D:\allwpilib\wpilibc\src\main\native\cpp\TimedRobot.cpp(22): wpilibcd!frc::TimedRobot::StartCompetition+0x4F
D:\allwpilib\wpilibc\src\main\native\include\frc\RobotBase.h(36): developerRobotCpp!frc::impl::RunRobot<Robot>+0xC8
D:\allwpilib\wpilibc\src\main\native\include\frc\RobotBase.h(106): developerRobotCpp!frc::StartRobot<Robot>+0x17E
D:\allwpilib\developerRobot\src\main\native\cpp\Robot.cpp(60): developerRobotCpp!main+0xB
D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl(79): developerRobotCpp!invoke_main+0x39
D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl(288): developerRobotCpp!__scrt_common_main_seh+0x132
D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl(331): developerRobotCpp!__scrt_common_main+0xE
D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_main.cpp(17): developerRobotCpp!mainCRTStartup+0xE
KERNEL32!BaseThreadInitThunk+0x1D
ntdll!RtlUserThreadStart+0x28
```
2026-04-26 00:15:39 -07:00

281 lines
11 KiB
CMake

project(wpiutil)
include(SubDirList)
include(GenResources)
include(CompileWarnings)
include(AddTest)
include(DownloadAndCheck)
file(GLOB wpiutil_jni_src src/main/native/cpp/jni/WPIUtilJNI.cpp)
# Java bindings
if(WITH_JAVA)
include(UseJava)
if(NOT EXISTS "${WPILIB_BINARY_DIR}/wpiutil/thirdparty/avaje/avaje-jsonb-3.11.jar")
set(BASE_URL "https://search.maven.org/remotecontent?filepath=")
set(JAR_ROOT "${WPILIB_BINARY_DIR}/wpiutil/thirdparty/avaje")
message(STATUS "Downloading Avaje jarfiles...")
download_and_check(
"${BASE_URL}io/avaje/avaje-jsonb/3.11/avaje-jsonb-3.11.jar"
"${JAR_ROOT}/avaje-jsonb-3.11.jar"
)
download_and_check(
"${BASE_URL}io/avaje/avaje-json-core/3.11/avaje-json-core-3.11.jar"
"${JAR_ROOT}/avaje-json-core-3.11.jar"
)
download_and_check(
"${BASE_URL}io/avaje/avaje-jsonb-inject-plugin/3.11/avaje-jsonb-inject-plugin-3.11.jar"
"${JAR_ROOT}/avaje-jsonb-inject-plugin-3.11.jar"
)
download_and_check(
"${BASE_URL}io/avaje/avaje-jsonb-generator/3.11/avaje-jsonb-generator-3.11.jar"
"${JAR_ROOT}/avaje-jsonb-generator-3.11.jar"
)
download_and_check(
"${BASE_URL}io/avaje/avaje-spi-service/2.16/avaje-spi-service-2.16.jar"
"${JAR_ROOT}/avaje-spi-service-2.16.jar"
)
download_and_check(
"${BASE_URL}io/avaje/avaje-spi-core/2.16/avaje-spi-core-2.16.jar"
"${JAR_ROOT}/avaje-spi-core-2.16.jar"
)
message(STATUS "All files downloaded.")
endif()
file(GLOB AVAJE_JARS ${WPILIB_BINARY_DIR}/wpiutil/thirdparty/avaje/*.jar)
if(NOT EXISTS "${WPILIB_BINARY_DIR}/wpiutil/thirdparty/quickbuf/quickbuf-runtime-1.4.jar")
set(BASE_URL "https://search.maven.org/remotecontent?filepath=")
set(JAR_ROOT "${WPILIB_BINARY_DIR}/wpiutil/thirdparty/quickbuf")
message(STATUS "Downloading Quickbuf jarfile...")
download_and_check(
"${BASE_URL}us/hebi/quickbuf/quickbuf-runtime/1.4/quickbuf-runtime-1.4.jar"
"${JAR_ROOT}/quickbuf-runtime-1.4.jar"
)
message(STATUS "Downloaded.")
endif()
file(GLOB QUICKBUF_JAR ${WPILIB_BINARY_DIR}/wpiutil/thirdparty/quickbuf/*.jar)
set(CMAKE_JNI_TARGET true)
file(GLOB_RECURSE JAVA_SOURCES src/main/java/*.java)
add_jar(
wpiutil_jar
${JAVA_SOURCES}
INCLUDE_JARS ${AVAJE_JARS} ${QUICKBUF_JAR}
OUTPUT_NAME wpiutil
OUTPUT_DIR ${WPILIB_BINARY_DIR}/${java_lib_dest}
GENERATE_NATIVE_HEADERS wpiutil_jni_headers
)
set_property(TARGET wpiutil_jar PROPERTY FOLDER "java")
install_jar(wpiutil_jar DESTINATION ${java_lib_dest})
install_jar_exports(TARGETS wpiutil_jar FILE wpiutil_jar.cmake DESTINATION share/wpiutil)
add_library(wpiutiljni ${wpiutil_jni_src})
wpilib_target_warnings(wpiutiljni)
target_link_libraries(wpiutiljni PUBLIC wpiutil)
set_property(TARGET wpiutiljni PROPERTY FOLDER "libraries")
target_link_libraries(wpiutiljni PRIVATE wpiutil_jni_headers)
add_dependencies(wpiutiljni wpiutil_jar)
install(TARGETS wpiutiljni EXPORT wpiutiljni)
export(TARGETS wpiutiljni FILE wpiutiljni.cmake NAMESPACE wpiutiljni::)
endif()
if(WITH_JAVA_SOURCE)
include(UseJava)
include(CreateSourceJar)
add_source_jar(
wpiutil_src_jar
BASE_DIRECTORIES ${CMAKE_CURRENT_SOURCE_DIR}/src/main/java
OUTPUT_NAME wpiutil-sources
OUTPUT_DIR ${WPILIB_BINARY_DIR}/${java_lib_dest}
)
set_property(TARGET wpiutil_src_jar PROPERTY FOLDER "java")
install_jar(wpiutil_src_jar DESTINATION ${java_lib_dest})
endif()
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
if(NOT MSVC AND NOT APPLE AND NOT ANDROID)
find_library(ATOMIC NAMES atomic libatomic.so.1)
if(ATOMIC)
message(STATUS "Found libatomic: ${ATOMIC}")
else()
message(STATUS "libatomic not found. If build fails, install libatomic")
endif()
endif()
generate_resources(src/main/native/resources generated/main/cpp WPI wpi wpiutil_resources_src)
file(
GLOB_RECURSE wpiutil_native_src
src/main/native/cpp/*.cpp
src/main/native/thirdparty/debugging/src/*.cpp
src/main/native/thirdparty/double-conversion/src/*.cpp
src/main/native/thirdparty/json/src/*.cpp
src/main/native/thirdparty/llvm/cpp/*.cpp
src/main/native/thirdparty/mpack/src/*.cpp
src/main/native/thirdparty/nanopb/src/*.cpp
src/main/native/thirdparty/upb/src/*.c
)
list(REMOVE_ITEM wpiutil_native_src ${wpiutil_jni_src})
file(GLOB_RECURSE wpiutil_unix_src src/main/native/unix/*.cpp)
file(GLOB_RECURSE wpiutil_windows_src src/main/native/windows/*.cpp)
file(GLOB fmtlib_native_src src/main/native/thirdparty/fmtlib/src/*.cpp)
add_library(wpiutil ${wpiutil_native_src} ${wpiutil_resources_src})
set_target_properties(wpiutil PROPERTIES DEBUG_POSTFIX "d")
set_property(TARGET wpiutil PROPERTY FOLDER "libraries")
target_compile_features(wpiutil PUBLIC cxx_std_23)
if(MSVC)
target_compile_options(
wpiutil
PUBLIC /permissive- /Zc:preprocessor /Zc:__cplusplus /Zc:throwingNew /MP /bigobj /utf-8
)
target_compile_definitions(wpiutil PRIVATE -D_CRT_SECURE_NO_WARNINGS)
endif()
wpilib_target_warnings(wpiutil)
target_link_libraries(wpiutil Threads::Threads ${CMAKE_DL_LIBS})
if(ATOMIC)
target_link_libraries(wpiutil ${ATOMIC})
endif()
if(NOT USE_SYSTEM_FMTLIB)
target_sources(wpiutil PRIVATE ${fmtlib_native_src})
install(
DIRECTORY src/main/native/thirdparty/fmtlib/include/
DESTINATION "${include_dest}/wpiutil"
)
target_include_directories(
wpiutil
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/main/native/thirdparty/fmtlib/include>
)
else()
find_package(fmt CONFIG REQUIRED)
target_link_libraries(wpiutil fmt::fmt)
if(MSVC)
get_target_property(fmt_includes fmt::fmt INTERFACE_INCLUDE_DIRECTORIES)
foreach(dir ${fmt_includes})
target_compile_options(wpiutil PUBLIC /external:I "${dir}")
endforeach()
target_compile_options(wpiutil PUBLIC /external:W0)
endif()
endif()
if(MSVC)
target_sources(wpiutil PRIVATE ${wpiutil_windows_src})
else()
target_sources(wpiutil PRIVATE ${wpiutil_unix_src})
endif()
install(
DIRECTORY
src/main/native/include/
src/main/native/thirdparty/argparse/include/
src/main/native/thirdparty/debugging/include/
src/main/native/thirdparty/double-conversion/include/
src/main/native/thirdparty/expected/include/
src/main/native/thirdparty/json/include/
src/main/native/thirdparty/llvm/include/
src/main/native/thirdparty/mpack/include/
src/main/native/thirdparty/nanopb/include/
src/main/native/thirdparty/sigslot/include/
src/main/native/thirdparty/upb/include/
DESTINATION "${include_dest}/wpiutil"
)
target_include_directories(
wpiutil
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/main/native/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/main/native/thirdparty/argparse/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/main/native/thirdparty/debugging/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/main/native/thirdparty/double-conversion/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/main/native/thirdparty/expected/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/main/native/thirdparty/json/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/main/native/thirdparty/llvm/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/main/native/thirdparty/mpack/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/main/native/thirdparty/nanopb/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/main/native/thirdparty/sigslot/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/main/native/thirdparty/upb/include>
$<INSTALL_INTERFACE:${include_dest}/wpiutil>
)
install(TARGETS wpiutil EXPORT wpiutil)
export(TARGETS wpiutil FILE wpiutil.cmake NAMESPACE wpiutil::)
configure_file(wpiutil-config.cmake.in ${WPILIB_BINARY_DIR}/wpiutil-config.cmake)
install(FILES ${WPILIB_BINARY_DIR}/wpiutil-config.cmake DESTINATION share/wpiutil)
install(EXPORT wpiutil DESTINATION share/wpiutil)
add_executable(wpiutildev src/dev/native/cpp/main.cpp)
wpilib_target_warnings(wpiutildev)
target_link_libraries(wpiutildev wpiutil)
subdir_list(wpiutil_examples "${CMAKE_CURRENT_SOURCE_DIR}/examples")
foreach(example ${wpiutil_examples})
file(GLOB wpiutil_example_src examples/${example}/*.cpp)
if(wpiutil_example_src)
add_executable(wpiutil_${example} ${wpiutil_example_src})
wpilib_target_warnings(wpiutil_${example})
target_link_libraries(wpiutil_${example} wpiutil)
set_property(TARGET wpiutil_${example} PROPERTY FOLDER "examples")
endif()
endforeach()
if(WITH_TESTS)
file(GLOB_RECURSE wpiutil_testlib_src src/test/native/include/*.h)
add_library(wpiutil_testlib INTERFACE ${wpiutil_test_src})
target_include_directories(wpiutil_testlib INTERFACE src/test/native/include)
# Not using wpilib_add_test until we migrate more tests
file(GLOB_RECURSE test_src src/test/native/cpp/*.cpp)
file(GLOB catch2_test_src src/test/native/cpp/catch2main.cpp src/test/native/cpp/TestCatch2.cpp)
list(REMOVE_ITEM test_src ${catch2_test_src})
add_executable(wpiutil_test ${test_src})
set_property(TARGET wpiutil_test PROPERTY FOLDER "tests")
wpilib_target_warnings(wpiutil_test)
if(BUILD_SHARED_LIBS)
target_compile_definitions(wpiutil_test PRIVATE -DGTEST_LINKED_AS_SHARED_LIBRARY)
endif()
if(MSVC)
target_compile_options(wpiutil_test PRIVATE /wd4101 /wd4251)
endif()
add_test(NAME wpiutil COMMAND wpiutil_test)
target_include_directories(wpiutil_test PRIVATE src/generated/test/native/cpp)
file(GLOB_RECURSE wpiutil_nanopb_test_src src/generated/test/native/cpp/*.cpp)
target_sources(wpiutil_test PRIVATE ${wpiutil_nanopb_test_src})
target_link_libraries(wpiutil_test wpiutil googletest wpiutil_testlib)
add_executable(wpiutil_catch2_test ${catch2_test_src})
set_property(TARGET wpiutil_catch2_test PROPERTY FOLDER "tests")
wpilib_target_warnings(wpiutil_catch2_test)
if(MSVC)
target_compile_options(wpiutil_catch2_test PRIVATE /wd4101 /wd4251)
endif()
target_link_libraries(wpiutil_catch2_test wpiutil catch2 wpiutil_testlib)
catch_discover_tests(wpiutil_catch2_test)
if(MSVC)
target_compile_options(wpiutil_test PRIVATE /utf-8)
target_compile_options(wpiutil_catch2_test PRIVATE /utf-8)
endif()
endif()