Reputation: 1841
I want to change the LANGUAGE
property of all .c
files to be CXX
so that they're compiled with g++
.
However, when I use the result of a GLOB_RECURSE
in set_source_files_properties
, it seems to have no effect.
I have the following in my CMakeLists.txt
and its output is not making sense to me.
get_source_file_property(property_before ${CMAKE_SOURCE_DIR}/examples/one/file.c LANGUAGE)
message(STATUS ${property_before})
# OUTPUT: NOTFOUND
file(GLOB_RECURSE c_sources "*.c")
foreach(c_file ${c_sources})
message(STATUS ${c_file})
# examples/one/file.c is included in the list of files
endforeach(c_file)
set_source_files_properties(c_sources PROPERTIES LANGUAGE CXX)
get_source_file_property(property_after ${CMAKE_SOURCE_DIR}/examples/one/file.c LANGUAGE)
message(STATUS ${property_after})
# OUTPUT: NOTFOUND
set_source_files_properties(${CMAKE_SOURCE_DIR}/examples/one/file.c PROPERTIES LANGUAGE CXX)
get_source_file_property(property_after_manual ${CMAKE_SOURCE_DIR}/examples/one/file.c LANGUAGE)
message(STATUS ${property_after_manual})
# OUTPUT: CXX
Source tree is something like:
.
├── CMakeLists.txt
├── examples # that use my library
│ ├── one
│ │ ├── file.c
│ │ └── CMakeLists.txt
│ ├── …
│ └── CMakeLists.txt
├── include # my library headers
│ ├── header1.h
│ ├── header2.h
│ └── …
├── src
│ ├── src1.cpp
│ ├── src2.cpp
│ └── …
└── test #tests
└── …
Pretty sure I'm doing something dumb and it's an easy fix, but I've wasted over an hour and I didn't find the issue. I really don't want to add manually all the .c
files :-)
Upvotes: 1
Views: 3049
Reputation: 3088
You need to expand the c_sources
variable like so: set_source_files_properties(${c_sources} PROPERTIES LANGUAGE CXX)
, like you already do it correctly in the foreach
above.
Upvotes: 2