MantisBT - CMake
View Issue Details
0008953CMakeCMakepublic2009-04-30 12:442016-06-10 14:30
Rob Blake 
Bill Hoffman 
normalminoralways
closedmoved 
CMake-2-6 
 
0008953: LANGUAGE property ignored when set from parent directory.
I used file(GLOB_RECURSE...) to find all *.c files in my project and set their language property to CXX. This was advised to me to get around bug 0008851. When I set the LANGUAGE property on a .c file that lives in a subdirectory, Cmake still thinks the file is a C file. If I call get_property within the subdirectory's makefile, I see LANGUAGE is set to CXX.

I've attached a test case that reproduces this behavior.
My test case has 3 files:
CMakeLists.txt:
cmake_minimum_required(VERSION 2.6)

PROJECT(BuildCToCXXSubdir)
file(GLOB_RECURSE C_FILES ${CMAKE_CURRENT_SOURCE_DIR} *.c)
set_source_files_properties(${C_FILES} PROPERTIES LANGUAGE CXX)

add_subdirectory(subdir)

subdir/CMakeLists.txt:
add_executable(test main.c)

subdir/main.c
#include <iostream>
using namespace std;

int main() {
  cout << "Hello World!" << endl;
  return 0;
}


When I run cmake and try to compile the above project, I get:
[100%] Building C object subdir/CMakeFiles/test.dir/main.c.o

If I try to access the LANGUAGE property of main.c, I see that it's set to CXX.
If I rewrite the entire project so that it lives in one directory, main.c is built as a CXX file. The bug only seems to appear when you have subdirectories.
No tags attached.
tgz cmake_cpp_test.tgz (543) 2009-04-30 12:44
https://public.kitware.com/Bug/file/2202/cmake_cpp_test.tgz
Issue History
2009-04-30 12:44Rob BlakeNew Issue
2009-04-30 12:44Rob BlakeFile Added: cmake_cpp_test.tgz
2009-09-14 13:00Bill HoffmanNote Added: 0017443
2009-09-14 13:00Bill HoffmanStatusnew => assigned
2009-09-14 13:00Bill HoffmanAssigned To => Bill Hoffman
2016-06-10 14:27Kitware RobotNote Added: 0041550
2016-06-10 14:27Kitware RobotStatusassigned => resolved
2016-06-10 14:27Kitware RobotResolutionopen => moved
2016-06-10 14:30Kitware RobotStatusresolved => closed

Notes
(0017443)
Bill Hoffman   
2009-09-14 13:00   
Source files are not global, but are directory based... You might want to try another approach. Maybe have your own add_exectuable macro or keep your files in variables, and create a macro, set_lang_cxx that would set the source file properties on a list of sources to CXX.
(0041550)
Kitware Robot   
2016-06-10 14:27   
Resolving issue as `moved`.

This issue tracker is no longer used. Further discussion of this issue may take place in the current CMake Issues page linked in the banner at the top of this page.