Skip to content

Commit a33db2f

Browse files
committed
Allow MinGW with CMake.
1 parent 91d52eb commit a33db2f

File tree

1 file changed

+67
-25
lines changed

1 file changed

+67
-25
lines changed

src/CMakeLists.txt

Lines changed: 67 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,16 @@
66
cmake_minimum_required(VERSION 3.20)
77
project(dump1090 LANGUAGES C)
88

9+
#
910
# Windows-only check
11+
#
1012
if(NOT WIN32)
1113
message(FATAL_ERROR "dump1090 is Windows-only")
1214
endif()
1315

16+
#
1417
# Define source files
18+
#
1519
set(SOURCES
1620
aircraft.c
1721
airports.c
@@ -49,27 +53,43 @@ set(SOURCES
4953
externals/SDRplay/sdrplay.c
5054
)
5155

56+
#
5257
# Include directories
58+
#
5359
include_directories(
5460
.
5561
./externals
5662
./externals/PDC-Mod
5763
)
5864

59-
# Preprocessor define and forced include
65+
#
66+
# Preprocessor define; since we have no custom CMake rule to create
67+
# a 'cflags_$(CC).h' and 'ldflags_$(CC).h' yet.
68+
#
6069
add_definitions(-DDOING_MSBUILD)
61-
add_compile_options(/FIdump1090_config.h)
6270

63-
# Create executable
64-
add_executable(dump1090 ${SOURCES})
71+
#
72+
# Forced include header:
73+
#
74+
if (MSVC)
75+
message ("Building for MSVC")
76+
add_compile_options (/FIdump1090_config.h)
77+
else()
78+
#
79+
# Assume MinGW / gcc
80+
#
81+
message ("Building for MinGW")
82+
add_compile_options (--include dump1090_config.h)
83+
endif()
6584

66-
# Compiler options per configuration
67-
target_compile_options(dump1090 PRIVATE
68-
$<$<CONFIG:Debug>:/MDd /W4 /Zi /Od>
69-
$<$<CONFIG:Release>:/MD /W4 /Zi>
70-
)
85+
#
86+
# Create executable
87+
#
88+
add_executable (dump1090 ${SOURCES})
7189

90+
#
7291
# Link Windows libraries
92+
#
7393
target_link_libraries(dump1090 PRIVATE
7494
advapi32
7595
dnsapi
@@ -78,30 +98,52 @@ target_link_libraries(dump1090 PRIVATE
7898
user32
7999
setupapi
80100
shlwapi
101+
winmm
81102
winusb
82103
ws2_32
83104
)
84105

85-
# Console subsystem
86-
set_target_properties(dump1090 PROPERTIES
87-
LINK_FLAGS "/SUBSYSTEM:CONSOLE"
88-
OUTPUT_NAME "dump1090"
89-
)
106+
#
107+
# Compiler options per configuration
108+
#
109+
if (MSVC)
110+
target_compile_options (dump1090 PRIVATE
111+
$<$<CONFIG:Debug>:/MDd /W4 /Zi /Od>
112+
$<$<CONFIG:Release>:/MD /W4 /Zi>)
113+
114+
#
115+
# Console subsystem
116+
#
117+
set_target_properties (dump1090 PROPERTIES
118+
LINK_FLAGS "/SUBSYSTEM:CONSOLE"
119+
OUTPUT_NAME "dump1090"
120+
)
121+
122+
#
123+
# Set machine type based on architecture
124+
#
125+
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
126+
set_target_properties(dump1090 PROPERTIES LINK_FLAGS "${CMAKE_LINK_FLAGS} /MACHINE:X64")
127+
else()
128+
set_target_properties(dump1090 PROPERTIES LINK_FLAGS "${CMAKE_LINK_FLAGS} /MACHINE:X86")
129+
endif()
130+
131+
#
132+
# Enable PDB generation
133+
#
134+
set_target_properties (dump1090 PROPERTIES
135+
COMPILE_PDB_NAME "dump1090"
136+
COMPILE_PDB_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
137+
)
90138

91-
# Set machine type based on architecture
92-
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
93-
set_target_properties(dump1090 PROPERTIES LINK_FLAGS "${CMAKE_LINK_FLAGS} /MACHINE:X64")
94139
else()
95-
set_target_properties(dump1090 PROPERTIES LINK_FLAGS "${CMAKE_LINK_FLAGS} /MACHINE:X86")
140+
set_target_properties (dump1090 PROPERTIES OUTPUT_NAME "dump1090")
96141
endif()
97142

98-
# Enable PDB generation
99-
set_target_properties(dump1090 PROPERTIES
100-
COMPILE_PDB_NAME "dump1090"
101-
COMPILE_PDB_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
102-
)
103-
104-
# Post-build: copy executable to ../dump1090.exe
143+
#
144+
# Post-build: copy executable to ../dump1090.exe.
145+
# Fails with "-G Ninja" !?
146+
#
105147
add_custom_command(TARGET dump1090 POST_BUILD
106148
COMMAND ${CMAKE_COMMAND} -E copy
107149
$<TARGET_FILE:dump1090>

0 commit comments

Comments
 (0)