CMakeLists.txt 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. # Still WIP! Use the regular Makefile for now!
  2. cmake_minimum_required(VERSION 3.6)
  3. set(CMAKE_OSX_ARCHITECTURES "arm64;x86_64" CACHE STRING "" FORCE)
  4. project(nmrpflash)
  5. if (NOT DEFINED NMRPFLASH_VERSION)
  6. find_package(Git)
  7. if(GIT_FOUND)
  8. execute_process(
  9. COMMAND ${GIT_EXECUTABLE} describe --always
  10. WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
  11. OUTPUT_VARIABLE GIT_VERSION
  12. OUTPUT_STRIP_TRAILING_WHITESPACE
  13. )
  14. string(SUBSTRING ${GIT_VERSION} 1 -1 GIT_VERSION)
  15. string(REGEX REPLACE "-g.*$" "" GIT_VERSION_CMAKE ${GIT_VERSION})
  16. string(REPLACE "-" "." GIT_VERSION_CMAKE ${GIT_VERSION_CMAKE})
  17. project(${CMAKE_PROJECT_NAME} VERSION ${GIT_VERSION_CMAKE})
  18. set(NMRPFLASH_VERSION ${GIT_VERSION})
  19. else()
  20. message(FATAL_ERROR "Git not found, and no NMRPFLASH_VERSION defined")
  21. endif()
  22. else()
  23. project(${CMAKE_PROJECT_NAME} VERSION ${NMRPFLASH_VERSION})
  24. endif()
  25. set(PROJECT_SOURCE_DIR ${CMAKE_SOURCE_DIR})
  26. add_executable(nmrpflash main.c nmrp.c tftp.c util.c ethsock.c)
  27. target_compile_definitions(nmrpflash PUBLIC -DNMRPFLASH_VERSION=\"${NMRPFLASH_VERSION}\")
  28. target_compile_options(nmrpflash PUBLIC -Wall)
  29. if (CMAKE_SYSTEM_NAME STREQUAL "Darwin")
  30. target_link_libraries(nmrpflash -lpcap "-framework CoreFoundation")
  31. elseif (CMAKE_SYSTEM_NAME STREQUAL "Windows")
  32. target_sources(nmrpflash PRIVATE nmrpflash.rc)
  33. target_compile_definitions(nmrpflash PUBLIC -D_WIN32_WINNT=0x0600 -DWIN32_LEAN_AND_MEAN -D__USE_MINGW_ANSI_STDIO)
  34. target_link_libraries(nmrpflash -lwpcap -lPacket -liphlpapi -lws2_32 -ladvapi32)
  35. target_include_directories(nmrpflash PUBLIC ./Npcap/Include)
  36. if (CMAKE_SIZEOF_VOID_P EQUAL 8)
  37. target_link_directories(nmrpflash PUBLIC ./Npcap/Lib/x64)
  38. else()
  39. target_link_directories(nmrpflash PUBLIC ./Npcap/Lib)
  40. endif()
  41. else()
  42. find_package(PkgConfig)
  43. pkg_check_modules(PCAP REQUIRED IMPORTED_TARGET libpcap)
  44. target_link_libraries(nmrpflash PkgConfig::PCAP)
  45. if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
  46. pkg_check_modules(NLROUTE REQUIRED IMPORTED_TARGET libnl-route-3.0)
  47. target_link_libraries(nmrpflash PkgConfig::NLROUTE)
  48. endif()
  49. endif()