Files
allwpilib/wpinet/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

242 lines
8.3 KiB
CMake

project(wpinet)
include(SubDirList)
include(GenResources)
include(CompileWarnings)
include(AddTest)
file(GLOB wpinet_jni_src src/main/native/cpp/jni/WPINetJNI.cpp)
# Java bindings
if(WITH_JAVA)
include(UseJava)
set(CMAKE_JNI_TARGET true)
file(GLOB_RECURSE JAVA_SOURCES src/main/java/*.java)
add_jar(
wpinet_jar
${JAVA_SOURCES}
INCLUDE_JARS wpiutil_jar
OUTPUT_NAME wpinet
OUTPUT_DIR ${WPILIB_BINARY_DIR}/${java_lib_dest}
GENERATE_NATIVE_HEADERS wpinet_jni_headers
)
set_property(TARGET wpinet_jar PROPERTY FOLDER "java")
install_jar(wpinet_jar DESTINATION ${java_lib_dest})
install_jar_exports(TARGETS wpinet_jar FILE wpinet_jar.cmake DESTINATION share/wpinet)
add_library(wpinetjni ${wpinet_jni_src})
wpilib_target_warnings(wpinetjni)
target_link_libraries(wpinetjni PUBLIC wpinet)
set_property(TARGET wpinetjni PROPERTY FOLDER "libraries")
target_link_libraries(wpinetjni PRIVATE wpinet_jni_headers)
add_dependencies(wpinetjni wpinet_jar)
install(TARGETS wpinetjni EXPORT wpinetjni)
export(TARGETS wpinetjni FILE wpinetjni.cmake NAMESPACE wpinetjni::)
endif()
if(WITH_JAVA_SOURCE)
include(UseJava)
include(CreateSourceJar)
add_source_jar(
wpinet_src_jar
BASE_DIRECTORIES ${CMAKE_CURRENT_SOURCE_DIR}/src/main/java
OUTPUT_NAME wpinet-sources
OUTPUT_DIR ${WPILIB_BINARY_DIR}/${java_lib_dest}
)
set_property(TARGET wpinet_src_jar PROPERTY FOLDER "java")
install_jar(wpinet_src_jar DESTINATION ${java_lib_dest})
endif()
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
if(NOT MSVC AND NOT APPLE)
find_library(ATOMIC NAMES atomic libatomic.so.1)
if(ATOMIC)
message(STATUS "Found libatomic: ${ATOMIC}")
endif()
endif()
file(
GLOB_RECURSE wpinet_native_src
src/main/native/cpp/*.cpp
src/main/native/thirdparty/tcpsockets/cpp/*.cpp
)
list(REMOVE_ITEM wpinet_native_src ${wpinet_jni_src})
file(GLOB_RECURSE wpinet_unix_src src/main/native/unix/*.cpp)
file(GLOB_RECURSE wpinet_linux_src src/main/native/linux/*.cpp)
file(GLOB_RECURSE wpinet_macos_src src/main/native/macOS/*.cpp)
file(GLOB_RECURSE wpinet_windows_src src/main/native/windows/*.cpp)
file(GLOB uv_native_src src/main/native/thirdparty/libuv/src/*.cpp)
file(GLOB uv_windows_src src/main/native/thirdparty/libuv/src/win/*.cpp)
set(uv_unix_src
src/main/native/thirdparty/libuv/src/unix/async.cpp
src/main/native/thirdparty/libuv/src/unix/core.cpp
src/main/native/thirdparty/libuv/src/unix/dl.cpp
src/main/native/thirdparty/libuv/src/unix/fs.cpp
src/main/native/thirdparty/libuv/src/unix/getaddrinfo.cpp
src/main/native/thirdparty/libuv/src/unix/getnameinfo.cpp
src/main/native/thirdparty/libuv/src/unix/loop-watcher.cpp
src/main/native/thirdparty/libuv/src/unix/loop.cpp
src/main/native/thirdparty/libuv/src/unix/pipe.cpp
src/main/native/thirdparty/libuv/src/unix/poll.cpp
src/main/native/thirdparty/libuv/src/unix/process.cpp
src/main/native/thirdparty/libuv/src/unix/random-devurandom.cpp
src/main/native/thirdparty/libuv/src/unix/random-getentropy.cpp
src/main/native/thirdparty/libuv/src/unix/random-getrandom.cpp
src/main/native/thirdparty/libuv/src/unix/signal.cpp
src/main/native/thirdparty/libuv/src/unix/stream.cpp
src/main/native/thirdparty/libuv/src/unix/tcp.cpp
src/main/native/thirdparty/libuv/src/unix/thread.cpp
src/main/native/thirdparty/libuv/src/unix/tty.cpp
src/main/native/thirdparty/libuv/src/unix/udp.cpp
)
set(uv_darwin_src
src/main/native/thirdparty/libuv/src/unix/bsd-ifaddrs.cpp
src/main/native/thirdparty/libuv/src/unix/darwin.cpp
src/main/native/thirdparty/libuv/src/unix/darwin-proctitle.cpp
src/main/native/thirdparty/libuv/src/unix/fsevents.cpp
src/main/native/thirdparty/libuv/src/unix/kqueue.cpp
src/main/native/thirdparty/libuv/src/unix/proctitle.cpp
)
set(uv_linux_src
src/main/native/thirdparty/libuv/src/unix/linux.cpp
src/main/native/thirdparty/libuv/src/unix/procfs-exepath.cpp
src/main/native/thirdparty/libuv/src/unix/proctitle.cpp
src/main/native/thirdparty/libuv/src/unix/random-sysctl-linux.cpp
)
add_library(wpinet ${wpinet_native_src})
set_target_properties(wpinet PROPERTIES DEBUG_POSTFIX "d")
set_property(TARGET wpinet PROPERTY FOLDER "libraries")
target_compile_features(wpinet PUBLIC cxx_std_23)
wpilib_target_warnings(wpinet)
target_link_libraries(wpinet PUBLIC wpiutil)
if(USE_LINKED_AVAHI)
find_library(AVAHI_COMMON REQUIRED NAMES avahi-common)
if(AVAHI_COMMON)
message(STATUS "Found avahi common: ${AVAHI_COMMON}")
endif()
find_library(AVAHI_CLIENT REQUIRED NAMES avahi-client)
if(AVAHI_CLIENT)
message(STATUS "Found avahi client: ${AVAHI_CLIENT}")
endif()
target_link_libraries(wpinet PUBLIC ${AVAHI_COMMON} ${AVAHI_CLIENT})
target_compile_definitions(wpinet PRIVATE DIRECT_LINK_AVAHI)
endif()
if(NOT USE_SYSTEM_LIBUV)
target_sources(wpinet PRIVATE ${uv_native_src})
install(
DIRECTORY src/main/native/thirdparty/libuv/include/
DESTINATION "${include_dest}/wpinet"
)
target_include_directories(wpinet PRIVATE src/main/native/thirdparty/libuv/src)
target_include_directories(
wpinet
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/main/native/thirdparty/libuv/include>
)
if(NOT MSVC)
target_sources(wpinet PRIVATE ${uv_unix_src})
if(APPLE)
target_sources(wpinet PRIVATE ${uv_darwin_src})
else()
target_sources(wpinet PRIVATE ${uv_linux_src})
endif()
target_compile_definitions(wpinet PRIVATE -D_GNU_SOURCE)
else()
target_sources(wpinet PRIVATE ${uv_windows_src})
if(BUILD_SHARED_LIBS)
target_compile_definitions(wpinet PRIVATE -DBUILDING_UV_SHARED)
endif()
endif()
else()
find_package(libuv CONFIG REQUIRED)
target_link_libraries(wpinet PUBLIC $<IF:$<TARGET_EXISTS:libuv::uv_a>,libuv::uv_a,libuv::uv>)
endif()
if(MSVC)
target_sources(wpinet PRIVATE ${wpinet_windows_src})
else()
target_sources(wpinet PRIVATE ${wpinet_unix_src})
if(APPLE)
target_sources(wpinet PRIVATE ${wpinet_macos_src})
else()
target_sources(wpinet PRIVATE ${wpinet_linux_src})
endif()
endif()
install(
DIRECTORY src/main/native/include/ src/main/native/thirdparty/tcpsockets/include/
DESTINATION "${include_dest}/wpinet"
)
target_include_directories(
wpinet
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/main/native/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/main/native/thirdparty/tcpsockets/include>
$<INSTALL_INTERFACE:${include_dest}/wpinet>
)
install(TARGETS wpinet EXPORT wpinet)
export(TARGETS wpinet FILE wpinet.cmake NAMESPACE wpinet::)
configure_file(wpinet-config.cmake.in ${WPILIB_BINARY_DIR}/wpinet-config.cmake)
install(FILES ${WPILIB_BINARY_DIR}/wpinet-config.cmake DESTINATION share/wpinet)
install(EXPORT wpinet DESTINATION share/wpinet)
subdir_list(wpinet_examples "${CMAKE_CURRENT_SOURCE_DIR}/examples")
foreach(example ${wpinet_examples})
file(GLOB wpinet_example_src examples/${example}/*.cpp)
if(wpinet_example_src)
add_executable(wpinet_${example} ${wpinet_example_src})
wpilib_target_warnings(wpinet_${example})
target_link_libraries(wpinet_${example} wpinet)
set_property(TARGET wpinet_${example} PROPERTY FOLDER "examples")
endif()
endforeach()
if(UNIX AND NOT APPLE AND NOT ANDROID)
set(LIBUTIL -lutil)
else()
set(LIBUTIL)
endif()
file(GLOB netconsoleServer_src src/netconsoleServer/native/cpp/*.cpp)
add_executable(netconsoleServer ${netconsoleServer_src})
wpilib_target_warnings(netconsoleServer)
target_link_libraries(netconsoleServer wpinet ${LIBUTIL})
file(GLOB netconsoleTee_src src/netconsoleTee/native/cpp/*.cpp)
add_executable(netconsoleTee ${netconsoleTee_src})
wpilib_target_warnings(netconsoleTee)
target_link_libraries(netconsoleTee wpinet)
set_property(TARGET netconsoleServer PROPERTY FOLDER "examples")
set_property(TARGET netconsoleTee PROPERTY FOLDER "examples")
if(WITH_TESTS)
wpilib_add_test(wpinet src/test/native/cpp)
target_include_directories(wpinet_test PRIVATE src/test/native/include src/main/native/cpp)
target_link_libraries(wpinet_test wpinet ${LIBUTIL} googletest wpiutil_testlib)
endif()