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