From 8c8305f286dab4e374bb8142ee991e00c57e418b Mon Sep 17 00:00:00 2001 From: Alex Neundorf Date: Mon, 31 Oct 2011 22:07:12 +0100 Subject: don't crash in automoc with empty COMPILE_DEFINITIONS property Reported by Laszlo Papp: http://www.cmake.org/pipermail/cmake/2011-October/047089.html Alex --- Source/cmQtAutomoc.cxx | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/Source/cmQtAutomoc.cxx b/Source/cmQtAutomoc.cxx index a839489..fdc19e4 100644 --- a/Source/cmQtAutomoc.cxx +++ b/Source/cmQtAutomoc.cxx @@ -124,21 +124,22 @@ void cmQtAutomoc::SetupAutomocTarget(cmTarget* target) } } - std::string _moc_incs = makefile->GetProperty("INCLUDE_DIRECTORIES"); - std::string _moc_defs = makefile->GetProperty("DEFINITIONS"); - std::string _moc_compile_defs = makefile->GetProperty("COMPILE_DEFINITIONS"); + const char* _moc_incs = makefile->GetProperty("INCLUDE_DIRECTORIES"); + const char* _moc_defs = makefile->GetProperty("DEFINITIONS"); + const char* _moc_compile_defs = makefile->GetProperty("COMPILE_DEFINITIONS"); // forget the variables added here afterwards again: cmMakefile::ScopePushPop varScope(makefile); static_cast(varScope); makefile->AddDefinition("_moc_target_name", automocTargetName.c_str()); - makefile->AddDefinition("_moc_incs", _moc_incs.c_str()); - makefile->AddDefinition("_moc_defs", _moc_defs.c_str()); - makefile->AddDefinition("_moc_compile_defs", _moc_compile_defs.c_str()); + makefile->AddDefinition("_moc_incs", _moc_incs!=0 ? _moc_incs : ""); + makefile->AddDefinition("_moc_defs", _moc_defs!=0 ? _moc_defs : ""); + makefile->AddDefinition("_moc_compile_defs", + _moc_compile_defs!=0 ? _moc_compile_defs : ""); makefile->AddDefinition("_moc_files", _moc_files.c_str()); makefile->AddDefinition("_moc_headers", _moc_headers.c_str()); - const char* cmakeRoot = makefile->GetDefinition("CMAKE_ROOT"); + const char* cmakeRoot = makefile->GetSafeDefinition("CMAKE_ROOT"); std::string inputFile = cmakeRoot; inputFile += "/Modules/AutomocInfo.cmake.in"; std::string outputFile = targetDir; -- cgit v0.12 From 1ecc55aa7b95a487996654e81d6493e7b72961c0 Mon Sep 17 00:00:00 2001 From: Alex Neundorf Date: Tue, 1 Nov 2011 13:59:14 +0100 Subject: Automoc: fix the fix, need to use std::string, not just char* pointer We need to take a copy of the property values, since the returned char* pointer is reused by the following GetProperty() calls Alex --- Source/cmQtAutomoc.cxx | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/Source/cmQtAutomoc.cxx b/Source/cmQtAutomoc.cxx index fdc19e4..e9cc9d1 100644 --- a/Source/cmQtAutomoc.cxx +++ b/Source/cmQtAutomoc.cxx @@ -124,18 +124,21 @@ void cmQtAutomoc::SetupAutomocTarget(cmTarget* target) } } - const char* _moc_incs = makefile->GetProperty("INCLUDE_DIRECTORIES"); - const char* _moc_defs = makefile->GetProperty("DEFINITIONS"); - const char* _moc_compile_defs = makefile->GetProperty("COMPILE_DEFINITIONS"); + const char* tmp = makefile->GetProperty("INCLUDE_DIRECTORIES"); + std::string _moc_incs = (tmp!=0 ? tmp : ""); + tmp = makefile->GetProperty("DEFINITIONS"); + std::string _moc_defs = (tmp!=0 ? tmp : ""); + tmp = makefile->GetProperty("COMPILE_DEFINITIONS"); + std::string _moc_compile_defs = (tmp!=0 ? tmp : ""); + // forget the variables added here afterwards again: cmMakefile::ScopePushPop varScope(makefile); static_cast(varScope); makefile->AddDefinition("_moc_target_name", automocTargetName.c_str()); - makefile->AddDefinition("_moc_incs", _moc_incs!=0 ? _moc_incs : ""); - makefile->AddDefinition("_moc_defs", _moc_defs!=0 ? _moc_defs : ""); - makefile->AddDefinition("_moc_compile_defs", - _moc_compile_defs!=0 ? _moc_compile_defs : ""); + makefile->AddDefinition("_moc_incs", _moc_incs.c_str()); + makefile->AddDefinition("_moc_defs", _moc_defs.c_str()); + makefile->AddDefinition("_moc_compile_defs", _moc_compile_defs.c_str()); makefile->AddDefinition("_moc_files", _moc_files.c_str()); makefile->AddDefinition("_moc_headers", _moc_headers.c_str()); -- cgit v0.12