From 8cd1f87ef61555b45a3fdebd75fe81a999f0b1e6 Mon Sep 17 00:00:00 2001 From: Davide Gerhard Date: Mon, 2 Sep 2019 11:40:16 +0200 Subject: [PATCH] cmake: windows build fixes works with cygwin and x86_64-w64-mingw32-gcc/x86_64-w64-mingw32-g++ from the package installer of cygwin. To use that add the following lines to .bash_profile export CC=x86_64-w64-mingw32-gcc export CXX=x86_64-w64-mingw32-g++ you also need cmake from cygwin --- CMakeLists.txt | 20 ++++--- cmake/modules/FindGPSD.cmake | 1 + conf/CMakeLists.txt | 4 +- data/CMakeLists.txt | 4 +- external/geotranz/CMakeLists.txt | 5 +- external/misc/CMakeLists.txt | 19 ++++--- external/regex/CMakeLists.txt | 15 +++-- scripts/CMakeLists.txt | 2 +- src/CMakeLists.txt | 62 ++++++++++++++++++--- src/beacon.c | 1 - src/direwolf.h | 3 +- src/dtime_now.c | 1 - test/CMakeLists.txt | 94 +++++++++++++++++++++++++++++--- 13 files changed, 184 insertions(+), 47 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 793aed0..5946460 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -31,7 +31,7 @@ add_definitions("-DCOPYRIGHT=\"${COPYRIGHT}\"") set(IDENTIFIER "com.${COMPANY}.${APPLICATION_NAME}") add_definitions("-DIDENTIFIER=\"${IDENTIFIER}\"") # raspberry as only lxterminal not xterm -if(NOT WIN32) +if(NOT (WIN32 OR CYGWIN)) find_program(BINARY_TERMINAL_BIN lxterminal) if(BINARY_TERMINAL_BIN) set(APPLICATION_DESKTOP_EXEC "${BINARY_TERMINAL_BIN} -e ${CMAKE_PROJECT_NAME}") @@ -86,6 +86,7 @@ if(NOT DEFINED CMAKE_BUILD_TYPE OR "${CMAKE_BUILD_TYPE}" STREQUAL "") set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type" FORCE) endif() message(STATUS "Build type set to: ${CMAKE_BUILD_TYPE}") +message("CMake system: ${CMAKE_SYSTEM_NAME}") # set compiler include(FindCompiler) @@ -174,12 +175,19 @@ if(LINUX) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DUSE_CM108") endif() -elseif (NOT WIN32) +elseif (NOT WIN32 AND NOT CYGWIN) find_package(portaudio REQUIRED) if(PORTAUDIO_FOUND) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DUSE_PORTAUDIO") endif() +else() + set(ALSA_INCLUDE_DIRS "") + set(ALSA_LIBRARIES "") + set(UDEV_INCLUDE_DIRS "") + set(UDEV_LIBRARIES "") + set(PORTAUDIO_INCLUDE_DIRS "") + set(PORTAUDIO_LIBRARIES "") endif() # manage and fetch new data @@ -194,13 +202,9 @@ add_subdirectory(${CUSTOM_MISC_DIR}) add_subdirectory(src) # ctest -# Note CMake will generate tests only if the enable_testing() command -# has been invoked. The CTest module invokes the command automatically -# when the BUILD_TESTING option is ON. include(CTest) -if(BUILD_TESTING) - add_subdirectory(test) -endif() +enable_testing() +add_subdirectory(test) # manage scripts add_subdirectory(scripts) diff --git a/cmake/modules/FindGPSD.cmake b/cmake/modules/FindGPSD.cmake index 7973b35..d21b331 100644 --- a/cmake/modules/FindGPSD.cmake +++ b/cmake/modules/FindGPSD.cmake @@ -80,6 +80,7 @@ else (GPSD_LIBRARIES AND GPSD_INCLUDE_DIRS) endif (GPSD_LIBRARIES AND GPSD_INCLUDE_DIRS) +# maybe on CYGWIN gpsd works if (WIN32) set(GPSD_FOUND FALSE) set(GPSD_LIBRARIES "") diff --git a/conf/CMakeLists.txt b/conf/CMakeLists.txt index 6cdf1f2..df0e27b 100644 --- a/conf/CMakeLists.txt +++ b/conf/CMakeLists.txt @@ -5,7 +5,7 @@ if(LINUX) string(REGEX REPLACE "\n%W%[^\n]*" "" file_content "${file_content}") string(REGEX REPLACE "\n%M%[^\n]*" "" file_content "${file_content}") string(REGEX REPLACE "\n%L%([^\n]*)" "\n\\1" file_content "${file_content}") -elseif(WIN32) +elseif(WIN32 OR CYGWIN) string(REGEX REPLACE "\n%M%[^\n]*" "" file_content "${file_content}") string(REGEX REPLACE "\n%L%[^\n]*" "" file_content "${file_content}") string(REGEX REPLACE "\n%W%([^\n]*)" "\n\\1" file_content "${file_content}") @@ -36,7 +36,7 @@ install(FILES "${CUSTOM_CONF_DIR}/sdr.conf" DESTINATION share/doc/${CMAKE_PROJEC # This step would be done as ordinary user. # Some people like to put the direwolf config file in /etc/ax25. # Note that all of these are also in $(DESTDIR)/share/doc/direwolf/examples/. -if(NOT WIN32) +if(NOT (WIN32 OR CYGWIN)) add_custom_target(install-conf COMMAND ${CMAKE_COMMAND} -DCUSTOM_BINARY_DIR="${CMAKE_BINARY_DIR}" diff --git a/data/CMakeLists.txt b/data/CMakeLists.txt index 7675b95..f15886a 100644 --- a/data/CMakeLists.txt +++ b/data/CMakeLists.txt @@ -86,8 +86,8 @@ ExternalProject_Add(download_symbolsx TEST_COMMAND "" ) -add_custom_target(data-update) -add_dependencies(data-update data_rename download_tocalls download_symbols-new download_symbolsx) +add_custom_target(update-data) +add_dependencies(update-data data_rename download_tocalls download_symbols-new download_symbolsx) install(FILES "${CUSTOM_BINARY_DATA_DIR}/${TOCALLS_TXT}" DESTINATION share/${PROJECT_NAME}) install(FILES "${CUSTOM_BINARY_DATA_DIR}/${SYMBOLS-NEW_TXT}" DESTINATION share/${PROJECT_NAME}) diff --git a/external/geotranz/CMakeLists.txt b/external/geotranz/CMakeLists.txt index 2da168a..576d8b8 100644 --- a/external/geotranz/CMakeLists.txt +++ b/external/geotranz/CMakeLists.txt @@ -2,8 +2,7 @@ set(GEOTRANZ_LIBRARIES geotranz CACHE INTERNAL "geotranz") -set(geotranz_SOURCES - ${geotranz_SOURCES} +list(APPEND geotranz_SOURCES error_string.c mgrs.c polarst.c @@ -13,6 +12,6 @@ set(geotranz_SOURCES utm.c ) -ADD_LIBRARY(geotranz STATIC +add_library(geotranz STATIC ${geotranz_SOURCES} ) diff --git a/external/misc/CMakeLists.txt b/external/misc/CMakeLists.txt index 379d0f6..07b10b2 100644 --- a/external/misc/CMakeLists.txt +++ b/external/misc/CMakeLists.txt @@ -6,19 +6,20 @@ include_directories( ) if(LINUX) - set(misc_SOURCES - ${misc_SOURCES} + list(APPEND misc_SOURCES # Provide our own copy of strlcpy and strlcat # because they are not included with Linux. ${CUSTOM_MISC_DIR}/strlcpy.c ${CUSTOM_MISC_DIR}/strlcat.c ) - ADD_LIBRARY(misc STATIC + + add_library(misc STATIC ${misc_SOURCES} ) -elseif(WIN32) # windows - set(misc_SOURCES - ${misc_SOURCES} + +elseif(WIN32 OR CYGWIN) # windows + + list(APPEND misc_SOURCES # There are several string functions found in Linux # but not on Windows. Need to provide our own copy. ${CUSTOM_MISC_DIR}/strsep.c @@ -27,10 +28,14 @@ elseif(WIN32) # windows ${CUSTOM_MISC_DIR}/strlcpy.c ${CUSTOM_MISC_DIR}/strlcat.c ) - ADD_LIBRARY(misc STATIC + + add_library(misc STATIC ${misc_SOURCES} ) + else() + # on macOS, OpenBSD and FreeBSD not misc is necessary set(MISC_LIBRARIES "" CACHE INTERNAL "") + endif() diff --git a/external/regex/CMakeLists.txt b/external/regex/CMakeLists.txt index b33c708..6720763 100644 --- a/external/regex/CMakeLists.txt +++ b/external/regex/CMakeLists.txt @@ -1,21 +1,24 @@ set(REGEX_LIBRARIES "" CACHE INTERNAL "") -if(WIN32) # windows +if(WIN32 OR CYGWIN) # windows set(REGEX_LIBRARIES regex CACHE INTERNAL "regex") - set(regex_SOURCES - ${regex_SOURCES} + list(APPEND regex_SOURCES # When building for Linux, we use regular expression # functions supplied by the gnu C library. # For the native WIN32 version, we need to use our own copy. # These were copied from http://gnuwin32.sourceforge.net/packages/regex.htm # Consider upgrading from https://www.gnu.org/software/libc/sources.html - # - # check if needed: -Dbool=int -Dtrue=1 -Dfalse=0 ${CUSTOM_REGEX_DIR}/regex.c ) - ADD_LIBRARY(regex STATIC + + add_library(regex STATIC ${regex_SOURCES} ) + + set_target_properties(regex + PROPERTIES COMPILE_FLAGS "-Dbool=int -Dtrue=1 -Dfalse=0 -DUSE_REGEX_STATIC" + ) + endif() diff --git a/scripts/CMakeLists.txt b/scripts/CMakeLists.txt index dae8d50..7f849d6 100644 --- a/scripts/CMakeLists.txt +++ b/scripts/CMakeLists.txt @@ -1,5 +1,5 @@ -if(NOT WIN32) +if(NOT (WIN32 OR CYGWIN)) install(PROGRAMS "${CUSTOM_SCRIPTS_DIR}/dwespeak.sh" DESTINATION bin) install(PROGRAMS "${CUSTOM_SCRIPTS_DIR}/dw-start.sh" DESTINATION share/doc/${CMAKE_PROJECT_NAME}/examples) add_subdirectory(telemetry-toolkit) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 4210892..76c233d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -10,6 +10,12 @@ include_directories( ${CUSTOM_GEOTRANZ_DIR} ) +if(WIN32 OR CYGWIN) + include_directories( + ${CUSTOM_REGEX_DIR} + ) +endif() + # build gen_fff to create fsk_fast_filter.h # optimization for slow processors list(APPEND gen_fff_SOURCES @@ -105,17 +111,21 @@ if(LINUX) cm108.c ) endif() - elseif(WIN32) # windows + elseif(WIN32 OR CYGWIN) # windows list(APPEND direwolf_SOURCES audio_win.c # icon - ${CMAKE_SOURCE_DIR}/cmake/cpack/direwolf.rc + # require plain gcc binary or link + #${CMAKE_SOURCE_DIR}/cmake/cpack/direwolf.rc + ) + list(REMOVE_ITEM direwolf_SOURCES + dwgpsd.c + ) + else() # macOS freebsd openbsd + list(APPEND direwolf_SOURCES + audio_portaudio.c ) - else() # macOS freebsd openbsd - list(APPEND direwolf_SOURCES - audio_portaudio.c - ) endif() add_executable(direwolf @@ -136,6 +146,13 @@ target_link_libraries(direwolf ${PORTAUDIO_LIBRARIES} ) +if(WIN32 OR CYGWIN) + set_target_properties(direwolf + PROPERTIES COMPILE_FLAGS "-DUSE_REGEX_STATIC" + ) + target_link_libraries(direwolf winmm ws2_32) +endif() + # decode_aprs list(APPEND decode_aprs_SOURCES decode_aprs.c @@ -154,6 +171,12 @@ list(APPEND decode_aprs_SOURCES tt_text.c ) +if(WIN32 OR CYGWIN) + list(REMOVE_ITEM decode_aprs_SOURCES + dwgpsd.c + ) +endif() + add_executable(decode_aprs ${decode_aprs_SOURCES} ) @@ -161,11 +184,12 @@ add_executable(decode_aprs add_dependencies(decode_aprs gen_fff) set_target_properties(decode_aprs - PROPERTIES COMPILE_FLAGS "-DDECAMAIN" + PROPERTIES COMPILE_FLAGS "-DDECAMAIN -DUSE_REGEX_STATIC" ) target_link_libraries(decode_aprs ${MISC_LIBRARIES} + ${REGEX_LIBRARIES} Threads::Threads ${GPSD_LIBRARIES} ) @@ -306,6 +330,12 @@ list(APPEND atest_SOURCES textcolor.c ) +if(WIN32 OR CYGWIN) + list(REMOVE_ITEM atest_SOURCES + dwgpsd.c + ) +endif() + add_executable(atest ${atest_SOURCES} ) @@ -315,9 +345,16 @@ add_dependencies(atest gen_fff) target_link_libraries(atest ${MISC_LIBRARIES} ${GPSD_LIBRARIES} + ${REGEX_LIBRARIES} Threads::Threads ) +if(WIN32 OR CYGWIN) + set_target_properties(atest + PROPERTIES COMPILE_FLAGS "-DUSE_REGEX_STATIC" + ) +endif() + # Multiple AGWPE network or serial port clients to test TNCs side by side. # aclients @@ -337,6 +374,10 @@ target_link_libraries(aclients Threads::Threads ) +if(WIN32 OR CYGWIN) + target_link_libraries(aclients ws2_32) +endif() + # Talk to a KISS TNC. # Note: kiss_frame.c has conditional compilation on KISSUTIL. @@ -365,6 +406,10 @@ target_link_libraries(kissutil Threads::Threads ) +if(WIN32 OR CYGWIN) + target_link_libraries(kissutil ws2_32) +endif() + # List USB audio adapters than can use GPIO for PTT. # cm108 @@ -406,6 +451,9 @@ target_link_libraries(ttcalc ${MISC_LIBRARIES} ) +if(WIN32 OR CYGWIN) + target_link_libraries(ttcalc ws2_32) +endif() install(TARGETS direwolf DESTINATION bin) install(TARGETS decode_aprs DESTINATION bin) diff --git a/src/beacon.c b/src/beacon.c index 0bd5e98..07ea0d0 100644 --- a/src/beacon.c +++ b/src/beacon.c @@ -59,7 +59,6 @@ #include "mheard.h" - /* * Save pointers to configuration settings. */ diff --git a/src/direwolf.h b/src/direwolf.h index 6df28ad..efc329b 100644 --- a/src/direwolf.h +++ b/src/direwolf.h @@ -113,7 +113,6 @@ #define SLEEP_MS(n) usleep((n)*1000) #endif - #if __WIN32__ #define PTW32_STATIC_LIB @@ -124,7 +123,7 @@ #define _POSIX_C_SOURCE 1 #else -#include + #include #endif diff --git a/src/dtime_now.c b/src/dtime_now.c index 380f6e9..af7b98a 100644 --- a/src/dtime_now.c +++ b/src/dtime_now.c @@ -84,7 +84,6 @@ double dtime_now (void) } - /*------------------------------------------------------------------ * * Name: timestamp_now diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 63160c8..3562dd0 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,4 +1,4 @@ -# this is a trick to avoid to more complication +# this is a trick to avoid more complication # because configure_file() is done a configuration time set(CUSTOM_TEST_BINARY_DIR "${CMAKE_BINARY_DIR}/test") set(GEN_PACKETS_BIN "${CMAKE_BINARY_DIR}/src/gen_packets${CMAKE_EXECUTABLE_SUFFIX}") @@ -83,6 +83,12 @@ include_directories( ${CMAKE_BINARY_DIR}/src ) +if(WIN32 OR CYGWIN) + include_directories( + ${CUSTOM_REGEX_DIR} + ) +endif() + # Unit test for demodulators list(APPEND atest9_SOURCES @@ -111,6 +117,12 @@ list(APPEND atest9_SOURCES ${CUSTOM_SRC_DIR}/tt_text.c ) +if(WIN32 OR CYGWIN) + list(REMOVE_ITEM atest9_SOURCES + ${CUSTOM_SRC_DIR}/dwgpsd.c + ) +endif() + add_executable(atest9 ${atest9_SOURCES} ) @@ -119,10 +131,18 @@ add_dependencies(atest9 gen_fff) target_link_libraries(atest9 ${MISC_LIBRARIES} + ${REGEX_LIBRARIES} ${GPSD_LIBRARIES} Threads::Threads ) +if(WIN32 OR CYGWIN) + set_target_properties(atest9 + PROPERTIES COMPILE_FLAGS "-DUSE_REGEX_STATIC" + ) + target_link_libraries(atest9 ws2_32) +endif() + # Unit test for inner digipeater algorithm list(APPEND dtest_SOURCES @@ -144,12 +164,18 @@ list(APPEND dtest_SOURCES ${CUSTOM_SRC_DIR}/tt_text.c ) +if(WIN32 OR CYGWIN) + list(REMOVE_ITEM dtest_SOURCES + ${CUSTOM_SRC_DIR}/dwgpsd.c + ) +endif() + add_executable(dtest ${dtest_SOURCES} ) set_target_properties(dtest - PROPERTIES COMPILE_FLAGS "-DDIGITEST" + PROPERTIES COMPILE_FLAGS "-DDIGITEST -DUSE_REGEX_STATIC" ) target_link_libraries(dtest @@ -159,6 +185,10 @@ target_link_libraries(dtest Threads::Threads ) +if(WIN32 OR CYGWIN) + target_link_libraries(dtest ws2_32) +endif() + # Unit test for APRStt tone seqence parsing. list(APPEND ttest_SOURCES @@ -218,12 +248,18 @@ list(APPEND pftest_SOURCES ${CUSTOM_SRC_DIR}/tt_text.c ) +if(WIN32 OR CYGWIN) + list(REMOVE_ITEM pftest_SOURCES + ${CUSTOM_SRC_DIR}/dwgpsd.c + ) +endif() + add_executable(pftest ${pftest_SOURCES} ) set_target_properties(pftest - PROPERTIES COMPILE_FLAGS "-DPFTEST" + PROPERTIES COMPILE_FLAGS "-DPFTEST -DUSE_REGEX_STATIC" ) target_link_libraries(pftest @@ -233,6 +269,9 @@ target_link_libraries(pftest Threads::Threads ) +if(WIN32 OR CYGWIN) + target_link_libraries(pftest ws2_32) +endif() # Unit test for telemetry decoding. list(APPEND tlmtest_SOURCES @@ -242,12 +281,18 @@ list(APPEND tlmtest_SOURCES ${CUSTOM_SRC_DIR}/textcolor.c ) +if(WIN32 OR CYGWIN) + list(REMOVE_ITEM tlmtest_SOURCES + ${CUSTOM_SRC_DIR}/dwgpsd.c + ) +endif() + add_executable(tlmtest ${tlmtest_SOURCES} ) set_target_properties(tlmtest - PROPERTIES COMPILE_FLAGS "-DTEST" + PROPERTIES COMPILE_FLAGS "-DTEST -DUSE_REGEX_STATIC" ) target_link_libraries(tlmtest @@ -255,6 +300,10 @@ target_link_libraries(tlmtest ${REGEX_LIBRARIES} ) +if(WIN32 OR CYGWIN) + target_link_libraries(tlmtest ws2_32) +endif() + # Unit test for location coordinate conversion. list(APPEND lltest_SOURCES @@ -322,7 +371,7 @@ add_executable(pad2test ) set_target_properties(pad2test - PROPERTIES COMPILE_FLAGS "-DPAD2TEST" + PROPERTIES COMPILE_FLAGS "-DPAD2TEST -DUSE_REGEX_STATIC" ) target_link_libraries(pad2test @@ -330,6 +379,10 @@ target_link_libraries(pad2test ${REGEX_LIBRARIES} ) +if(WIN32 OR CYGWIN) + target_link_libraries(pad2test ws2_32) +endif() + # Unit Test for XID frame encode/decode. list(APPEND xidtest_SOURCES @@ -414,6 +467,12 @@ if(OPTIONAL_TEST) ${CUSTOM_SRC_DIR}/symbols.c ) + if(WIN32 OR CYGWIN) + list(REMOVE_ITEM itest_SOURCES + ${CUSTOM_SRC_DIR}/dwgpsd.c + ) + endif() + add_executable(itest ${itest_SOURCES} ) @@ -428,6 +487,10 @@ if(OPTIONAL_TEST) Threads::Threads ) + if(WIN32 OR CYGWIN) + target_link_libraries(itest ws2_32) + endif() + # For demodulator tweaking experiments. list(APPEND testagc_SOURCES @@ -456,6 +519,12 @@ if(OPTIONAL_TEST) ${CUSTOM_SRC_DIR}/textcolor.c ) + if(WIN32 OR CYGWIN) + list(REMOVE_ITEM testagc_SOURCES + ${CUSTOM_SRC_DIR}/dwgpsd.c + ) + endif() + add_executable(testagc ${testagc_SOURCES} ) @@ -468,6 +537,10 @@ if(OPTIONAL_TEST) Threads::Threads ) + if(WIN32 OR CYGWIN) + target_link_libraries(testagc ws2_32) + endif() + # Send GPS location to KISS TNC each second. list(APPEND walk96_SOURCES @@ -515,10 +588,13 @@ if(OPTIONAL_TEST) ${CUSTOM_SRC_DIR}/cm108.c ) endif() - elseif(WIN32) # windows + elseif(WIN32 OR CYGWIN) # windows list(APPEND walk96_SOURCES ${CUSTOM_SRC_DIR}/audio_win.c ) + list(REMOVE_ITEM walk96_SOURCES + ${CUSTOM_SRC_DIR}/dwgpsd.c + ) else() # macOS freebsd openbsd list(APPEND walk96_SOURCES ${CUSTOM_SRC_DIR}/audio_portaudio.c @@ -530,7 +606,7 @@ if(OPTIONAL_TEST) ) set_target_properties(walk96 - PROPERTIES COMPILE_FLAGS "-DWALK96" + PROPERTIES COMPILE_FLAGS "-DWALK96 -DUSE_REGEX_STATIC" ) target_link_libraries(walk96 @@ -544,6 +620,10 @@ if(OPTIONAL_TEST) Threads::Threads ) + if(WIN32 OR CYGWIN) + target_link_libraries(walk96 ws2_32) + endif() + # TODO miss the audio file