Add ability to include a file in a project via a cache variable.
If a variable exists called CMAKE_PROJECT_<projectName>_INCLUDE, the file pointed to by that variable will be included as the last step of the project command.
This commit is contained in:
parent
e2042b68d3
commit
9090572f5c
|
@ -77,6 +77,24 @@ bool cmProjectCommand
|
||||||
languages.push_back("CXX");
|
languages.push_back("CXX");
|
||||||
}
|
}
|
||||||
this->Makefile->EnableLanguage(languages, false);
|
this->Makefile->EnableLanguage(languages, false);
|
||||||
|
std::string extraInclude = "CMAKE_PROJECT_" + args[0] + "_INCLUDE";
|
||||||
|
const char* include = this->Makefile->GetDefinition(extraInclude.c_str());
|
||||||
|
if(include)
|
||||||
|
{
|
||||||
|
std::string fullFilePath;
|
||||||
|
bool readit =
|
||||||
|
this->Makefile->ReadListFile( this->Makefile->GetCurrentListFile(),
|
||||||
|
include);
|
||||||
|
if(!readit && !cmSystemTools::GetFatalErrorOccured())
|
||||||
|
{
|
||||||
|
std::string m =
|
||||||
|
"could not find load file:\n"
|
||||||
|
" ";
|
||||||
|
m += include;
|
||||||
|
this->SetError(m.c_str());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -68,7 +68,10 @@ public:
|
||||||
"By default C and CXX are enabled. E.g. if you do not have a "
|
"By default C and CXX are enabled. E.g. if you do not have a "
|
||||||
"C++ compiler, you can disable the check for it by explicitly listing "
|
"C++ compiler, you can disable the check for it by explicitly listing "
|
||||||
"the languages you want to support, e.g. C. By using the special "
|
"the languages you want to support, e.g. C. By using the special "
|
||||||
"language \"NONE\" all checks for any language can be disabled.";
|
"language \"NONE\" all checks for any language can be disabled. "
|
||||||
|
"If a variable exists called CMAKE_PROJECT_<projectName>_INCLUDE_FILE, "
|
||||||
|
"the file pointed to by that variable will be included as the last step "
|
||||||
|
"of the project command.";
|
||||||
}
|
}
|
||||||
|
|
||||||
cmTypeMacro(cmProjectCommand, cmCommand);
|
cmTypeMacro(cmProjectCommand, cmCommand);
|
||||||
|
|
|
@ -22,3 +22,11 @@ add_CMakeOnly_test(CheckLanguage)
|
||||||
add_CMakeOnly_test(AllFindModules)
|
add_CMakeOnly_test(AllFindModules)
|
||||||
|
|
||||||
add_CMakeOnly_test(TargetScope)
|
add_CMakeOnly_test(TargetScope)
|
||||||
|
|
||||||
|
add_CMakeOnly_test(ProjectInclude)
|
||||||
|
|
||||||
|
add_test(CMakeOnly.ProjectInclude ${CMAKE_CMAKE_COMMAND}
|
||||||
|
-DTEST=ProjectInclude
|
||||||
|
-DCMAKE_ARGS=-DCMAKE_PROJECT_ProjectInclude_INCLUDE=${CMAKE_CURRENT_SOURCE_DIR}/ProjectInclude/include.cmake
|
||||||
|
-P ${CMAKE_CURRENT_BINARY_DIR}/Test.cmake
|
||||||
|
)
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
project(ProjectInclude)
|
||||||
|
if(NOT AUTO_INCLUDE)
|
||||||
|
message(FATAL_ERROR "include file not found")
|
||||||
|
endif()
|
|
@ -0,0 +1 @@
|
||||||
|
set(AUTO_INCLUDE TRUE)
|
|
@ -3,7 +3,8 @@ set(binary_dir "@CMAKE_CURRENT_BINARY_DIR@/${TEST}-build")
|
||||||
file(REMOVE_RECURSE "${binary_dir}")
|
file(REMOVE_RECURSE "${binary_dir}")
|
||||||
file(MAKE_DIRECTORY "${binary_dir}")
|
file(MAKE_DIRECTORY "${binary_dir}")
|
||||||
execute_process(
|
execute_process(
|
||||||
COMMAND ${CMAKE_COMMAND} "${source_dir}" -G "@CMAKE_TEST_GENERATOR@"
|
COMMAND ${CMAKE_COMMAND} ${CMAKE_ARGS}
|
||||||
|
"${source_dir}" -G "@CMAKE_TEST_GENERATOR@"
|
||||||
WORKING_DIRECTORY "${binary_dir}"
|
WORKING_DIRECTORY "${binary_dir}"
|
||||||
RESULT_VARIABLE result
|
RESULT_VARIABLE result
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue