66cmake_minimum_required (VERSION 3.20 )
77project (dump1090 LANGUAGES C )
88
9+ #
910# Windows-only check
11+ #
1012if (NOT WIN32 )
1113 message (FATAL_ERROR "dump1090 is Windows-only" )
1214endif ()
1315
16+ #
1417# Define source files
18+ #
1519set (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+ #
5359include_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+ #
6069add_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+ #
7393target_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" )
94139else ()
95- set_target_properties (dump1090 PROPERTIES LINK_FLAGS " ${CMAKE_LINK_FLAGS} /MACHINE:X86 " )
140+ set_target_properties (dump1090 PROPERTIES OUTPUT_NAME "dump1090 " )
96141endif ()
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+ #
105147add_custom_command (TARGET dump1090 POST_BUILD
106148 COMMAND ${CMAKE_COMMAND} -E copy
107149 $<TARGET_FILE :dump1090 >
0 commit comments