@@ -163,11 +163,6 @@ if(WIN32)
163163 src/getopt.c
164164 src/minidump-win32.cc
165165 )
166- # Build getopt.c, which can be compiled as either C or C++, as C++
167- # so that build environments which lack a C compiler, but have a C++
168- # compiler may build ninja.
169- set_source_files_properties (src/getopt.c PROPERTIES LANGUAGE CXX)
170-
171166 # windows.h defines min() and max() which conflict with std::min()
172167 # and std::max(), which both might be used in sources. Avoid compile
173168 # errors by telling windows.h to not define those two.
@@ -179,17 +174,20 @@ else()
179174 )
180175 if (CMAKE_SYSTEM_NAME STREQUAL "OS400" OR CMAKE_SYSTEM_NAME STREQUAL "AIX" )
181176 target_sources (libninja PRIVATE src/getopt.c )
182- # Build getopt.c, which can be compiled as either C or C++, as C++
183- # so that build environments which lack a C compiler, but have a C++
184- # compiler may build ninja.
185- set_source_files_properties (src/getopt.c PROPERTIES LANGUAGE CXX)
186177 endif ()
187178
188179 # Needed for perfstat_cpu_total
189180 if (CMAKE_SYSTEM_NAME STREQUAL "AIX" )
190181 target_link_libraries (libninja PUBLIC "-lperfstat" )
191182 endif ()
192183endif ()
184+ get_property (_src_ninja TARGET libninja PROPERTY SOURCES )
185+ if ("src/getopt.c" IN_LIST _src_ninja)
186+ # Build getopt.c, which can be compiled as either C or C++, as C++
187+ # so that build environments which lack a C compiler, but have a C++
188+ # compiler may build ninja.
189+ set_property (SOURCE src/getopt.c PROPERTY LANGUAGE CXX)
190+ endif ()
193191
194192target_compile_features (libninja PUBLIC cxx_std_17 )
195193target_compile_features (libninja-re2c PUBLIC cxx_std_17 )
@@ -216,9 +214,7 @@ if(NINJA_BUILD_BINARY)
216214
217215 option (NINJA_CLANG_TIDY "Run clang-tidy on source files" OFF )
218216 if (NINJA_CLANG_TIDY)
219- set_target_properties (libninja-re2c PROPERTIES CXX_CLANG_TIDY "clang-tidy;--use-color" )
220- set_target_properties (libninja PROPERTIES CXX_CLANG_TIDY "clang-tidy;--use-color" )
221- set_target_properties (ninja PROPERTIES CXX_CLANG_TIDY "clang-tidy;--use-color" )
217+ set_target_properties (libninja-re2c libninja ninja PROPERTIES CXX_CLANG_TIDY "clang-tidy;--use-color" )
222218 endif ()
223219endif ()
224220
0 commit comments