ENH: Added NOT_IN_ALL option for ADD_LIBRARY and ADD_EXECUTABLE to avoid building the targets by default.
This commit is contained in:
parent
603b47c87a
commit
1d9f287af7
|
@ -31,6 +31,7 @@ bool cmAddExecutableCommand::InitialPass(std::vector<std::string> const& args)
|
|||
++s;
|
||||
bool use_win32 = false;
|
||||
bool use_macbundle = false;
|
||||
bool in_all = true;
|
||||
while ( s != args.end() )
|
||||
{
|
||||
if (*s == "WIN32")
|
||||
|
@ -43,6 +44,11 @@ bool cmAddExecutableCommand::InitialPass(std::vector<std::string> const& args)
|
|||
++s;
|
||||
use_macbundle = true;
|
||||
}
|
||||
else if(*s == "NOT_IN_ALL")
|
||||
{
|
||||
++s;
|
||||
in_all = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
|
@ -57,7 +63,8 @@ bool cmAddExecutableCommand::InitialPass(std::vector<std::string> const& args)
|
|||
}
|
||||
|
||||
std::vector<std::string> srclists(s, args.end());
|
||||
cmTarget* tgt = this->Makefile->AddExecutable(exename.c_str(), srclists);
|
||||
cmTarget* tgt = this->Makefile->AddExecutable(exename.c_str(), srclists,
|
||||
in_all);
|
||||
if ( use_win32 )
|
||||
{
|
||||
tgt->SetProperty("WIN32_EXECUTABLE", "ON");
|
||||
|
|
|
@ -62,8 +62,8 @@ public:
|
|||
virtual const char* GetFullDocumentation()
|
||||
{
|
||||
return
|
||||
" ADD_EXECUTABLE(exename [WIN32] [MACOSX_BUNDLE] source1\n"
|
||||
" source2 ... sourceN)\n"
|
||||
" ADD_EXECUTABLE(exename [WIN32] [MACOSX_BUNDLE] [NOT_IN_ALL]\n"
|
||||
" source1 source2 ... sourceN)\n"
|
||||
"This command adds an executable target to the current directory. "
|
||||
"The executable will be built from the list of source files "
|
||||
"specified.\n"
|
||||
|
@ -86,6 +86,9 @@ public:
|
|||
" MACOSX_BUNDLE_SHORT_VERSION_STRING\n"
|
||||
" MACOSX_BUNDLE_BUNDLE_VERSION\n"
|
||||
" MACOSX_BUNDLE_COPYRIGHT\n"
|
||||
"If NOT_IN_ALL is given the target will not be built by default. "
|
||||
"It will be built only if the user explicitly builds the target or "
|
||||
"another target that requires the target depends on it."
|
||||
;
|
||||
}
|
||||
|
||||
|
|
|
@ -28,6 +28,7 @@ bool cmAddLibraryCommand::InitialPass(std::vector<std::string> const& args)
|
|||
// otherwise it defaults to static library.
|
||||
int shared =
|
||||
!cmSystemTools::IsOff(this->Makefile->GetDefinition("BUILD_SHARED_LIBS"));
|
||||
bool in_all = true;
|
||||
|
||||
std::vector<std::string>::const_iterator s = args.begin();
|
||||
|
||||
|
@ -56,6 +57,11 @@ bool cmAddLibraryCommand::InitialPass(std::vector<std::string> const& args)
|
|||
++s;
|
||||
shared = 2;
|
||||
}
|
||||
else if(*s == "NOT_IN_ALL")
|
||||
{
|
||||
++s;
|
||||
in_all = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (s == args.end())
|
||||
|
@ -74,7 +80,8 @@ bool cmAddLibraryCommand::InitialPass(std::vector<std::string> const& args)
|
|||
++s;
|
||||
}
|
||||
|
||||
this->Makefile->AddLibrary(this->LibName.c_str(), shared, srclists);
|
||||
this->Makefile->AddLibrary(this->LibName.c_str(), shared, srclists,
|
||||
in_all);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -61,7 +61,7 @@ public:
|
|||
virtual const char* GetFullDocumentation()
|
||||
{
|
||||
return
|
||||
" ADD_LIBRARY(libname [SHARED | STATIC | MODULE]\n"
|
||||
" ADD_LIBRARY(libname [SHARED | STATIC | MODULE] [NOT_IN_ALL]\n"
|
||||
" source1 source2 ... sourceN)\n"
|
||||
"Adds a library target. SHARED, STATIC or MODULE keywords are used "
|
||||
"to set the library type. If the keyword MODULE appears, the library "
|
||||
|
@ -69,7 +69,10 @@ public:
|
|||
"without dyld, MODULE is treated like SHARED. If no keywords appear "
|
||||
" as the second argument, the type defaults to the current value of "
|
||||
"BUILD_SHARED_LIBS. If this variable is not set, the type defaults "
|
||||
"to STATIC.";
|
||||
"to STATIC.\n"
|
||||
"If NOT_IN_ALL is given the target will not be built by default. "
|
||||
"It will be built only if the user explicitly builds the target or "
|
||||
"another target that requires the target depends on it.";
|
||||
}
|
||||
|
||||
cmTypeMacro(cmAddLibraryCommand, cmCommand);
|
||||
|
|
|
@ -1281,7 +1281,8 @@ void cmMakefile::AddGlobalLinkInformation(const char* name, cmTarget& target)
|
|||
|
||||
|
||||
void cmMakefile::AddLibrary(const char* lname, int shared,
|
||||
const std::vector<std::string> &srcs)
|
||||
const std::vector<std::string> &srcs,
|
||||
bool in_all)
|
||||
{
|
||||
cmTarget target;
|
||||
switch (shared)
|
||||
|
@ -1303,7 +1304,7 @@ void cmMakefile::AddLibrary(const char* lname, int shared,
|
|||
// over changes in CMakeLists.txt, making the information stale and
|
||||
// hence useless.
|
||||
target.ClearDependencyInformation( *this, lname );
|
||||
target.SetInAll(true);
|
||||
target.SetInAll(in_all);
|
||||
target.GetSourceLists() = srcs;
|
||||
target.SetMakefile(this);
|
||||
this->AddGlobalLinkInformation(lname, target);
|
||||
|
@ -1313,11 +1314,12 @@ void cmMakefile::AddLibrary(const char* lname, int shared,
|
|||
}
|
||||
|
||||
cmTarget* cmMakefile::AddExecutable(const char *exeName,
|
||||
const std::vector<std::string> &srcs)
|
||||
const std::vector<std::string> &srcs,
|
||||
bool in_all)
|
||||
{
|
||||
cmTarget target;
|
||||
target.SetType(cmTarget::EXECUTABLE, exeName);
|
||||
target.SetInAll(true);
|
||||
target.SetInAll(in_all);
|
||||
target.GetSourceLists() = srcs;
|
||||
target.SetMakefile(this);
|
||||
this->AddGlobalLinkInformation(exeName, target);
|
||||
|
|
|
@ -176,7 +176,8 @@ public:
|
|||
* Add an executable to the build.
|
||||
*/
|
||||
cmTarget* AddExecutable(const char *exename,
|
||||
const std::vector<std::string> &srcs);
|
||||
const std::vector<std::string> &srcs,
|
||||
bool in_all = true);
|
||||
|
||||
/**
|
||||
* Add a utility to the build. A utiltity target is a command that
|
||||
|
@ -285,7 +286,8 @@ public:
|
|||
* Set the name of the library.
|
||||
*/
|
||||
void AddLibrary(const char *libname, int shared,
|
||||
const std::vector<std::string> &srcs);
|
||||
const std::vector<std::string> &srcs,
|
||||
bool in_all = true);
|
||||
|
||||
#if defined(CMAKE_BUILD_WITH_CMAKE)
|
||||
/**
|
||||
|
|
|
@ -101,6 +101,14 @@ ADD_CUSTOM_COMMAND(
|
|||
DEPENDS ${CMAKE_COMMAND}
|
||||
)
|
||||
|
||||
# Test creating an executable that is not built by default.
|
||||
ADD_EXECUTABLE(notInAllExe NOT_IN_ALL notInAllExe.cxx)
|
||||
TARGET_LINK_LIBRARIES(notInAllExe notInAllLib)
|
||||
|
||||
# Test creating a custom target that builds not-in-all targets.
|
||||
ADD_CUSTOM_TARGET(notInAllCustom)
|
||||
ADD_DEPENDENCIES(notInAllCustom notInAllExe)
|
||||
|
||||
#
|
||||
# Output the files required by 'complex' to a file.
|
||||
#
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
extern int notInAllLibFunc();
|
||||
|
||||
int main()
|
||||
{
|
||||
return notInAllLibFunc();
|
||||
}
|
||||
|
||||
#if 1
|
||||
# error "This target should not be compiled by ALL."
|
||||
#endif
|
|
@ -103,6 +103,9 @@ SET_SOURCE_FILES_PROPERTIES(file2 PROPERTIES ABSTRACT 1)
|
|||
INSTALL_FILES(/tmp .h ${Complex_BINARY_DIR}/cmTestConfigure.h)
|
||||
INSTALL_FILES(/tmp .cxx ${Complex_BINARY_DIR}/cmTestConfigure.h)
|
||||
|
||||
# Test creating a library that is not built by default.
|
||||
ADD_LIBRARY(notInAllLib NOT_IN_ALL notInAllLib.cxx)
|
||||
|
||||
# Test generation of preprocessed sources.
|
||||
IF("${CMAKE_GENERATOR}" MATCHES "Makefile" AND CMAKE_MAKE_PROGRAM)
|
||||
IF(CMAKE_CXX_CREATE_PREPROCESSED_SOURCE)
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
int notInAllLibFunc() { return 0; }
|
||||
|
||||
#if 1
|
||||
# error "This target should not be compiled by ALL."
|
||||
#endif
|
|
@ -101,6 +101,14 @@ ADD_CUSTOM_COMMAND(
|
|||
DEPENDS ${CMAKE_COMMAND}
|
||||
)
|
||||
|
||||
# Test creating an executable that is not built by default.
|
||||
ADD_EXECUTABLE(notInAllExe NOT_IN_ALL notInAllExe.cxx)
|
||||
TARGET_LINK_LIBRARIES(notInAllExe notInAllLib)
|
||||
|
||||
# Test creating a custom target that builds not-in-all targets.
|
||||
ADD_CUSTOM_TARGET(notInAllCustom)
|
||||
ADD_DEPENDENCIES(notInAllCustom notInAllExe)
|
||||
|
||||
#
|
||||
# Output the files required by 'complex' to a file.
|
||||
#
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
extern int notInAllLibFunc();
|
||||
|
||||
int main()
|
||||
{
|
||||
return notInAllLibFunc();
|
||||
}
|
||||
|
||||
#if 1
|
||||
# error "This target should not be compiled by ALL."
|
||||
#endif
|
|
@ -103,6 +103,9 @@ SET_SOURCE_FILES_PROPERTIES(file2 PROPERTIES ABSTRACT 1)
|
|||
INSTALL_FILES(/tmp .h ${Complex_BINARY_DIR}/cmTestConfigure.h)
|
||||
INSTALL_FILES(/tmp .cxx ${Complex_BINARY_DIR}/cmTestConfigure.h)
|
||||
|
||||
# Test creating a library that is not built by default.
|
||||
ADD_LIBRARY(notInAllLib NOT_IN_ALL notInAllLib.cxx)
|
||||
|
||||
# Test generation of preprocessed sources.
|
||||
IF("${CMAKE_GENERATOR}" MATCHES "Makefile" AND CMAKE_MAKE_PROGRAM)
|
||||
IF(CMAKE_CXX_CREATE_PREPROCESSED_SOURCE)
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
int notInAllLibFunc() { return 0; }
|
||||
|
||||
#if 1
|
||||
# error "This target should not be compiled by ALL."
|
||||
#endif
|
|
@ -101,6 +101,14 @@ ADD_CUSTOM_COMMAND(
|
|||
DEPENDS ${CMAKE_COMMAND}
|
||||
)
|
||||
|
||||
# Test creating an executable that is not built by default.
|
||||
ADD_EXECUTABLE(notInAllExe NOT_IN_ALL notInAllExe.cxx)
|
||||
TARGET_LINK_LIBRARIES(notInAllExe notInAllLib)
|
||||
|
||||
# Test creating a custom target that builds not-in-all targets.
|
||||
ADD_CUSTOM_TARGET(notInAllCustom)
|
||||
ADD_DEPENDENCIES(notInAllCustom notInAllExe)
|
||||
|
||||
#
|
||||
# Output the files required by 'complex' to a file.
|
||||
#
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
extern int notInAllLibFunc();
|
||||
|
||||
int main()
|
||||
{
|
||||
return notInAllLibFunc();
|
||||
}
|
||||
|
||||
#if 1
|
||||
# error "This target should not be compiled by ALL."
|
||||
#endif
|
|
@ -103,6 +103,9 @@ SET_SOURCE_FILES_PROPERTIES(file2 PROPERTIES ABSTRACT 1)
|
|||
INSTALL_FILES(/tmp .h ${Complex_BINARY_DIR}/cmTestConfigure.h)
|
||||
INSTALL_FILES(/tmp .cxx ${Complex_BINARY_DIR}/cmTestConfigure.h)
|
||||
|
||||
# Test creating a library that is not built by default.
|
||||
ADD_LIBRARY(notInAllLib NOT_IN_ALL notInAllLib.cxx)
|
||||
|
||||
# Test generation of preprocessed sources.
|
||||
IF("${CMAKE_GENERATOR}" MATCHES "Makefile" AND CMAKE_MAKE_PROGRAM)
|
||||
IF(CMAKE_CXX_CREATE_PREPROCESSED_SOURCE)
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
int notInAllLibFunc() { return 0; }
|
||||
|
||||
#if 1
|
||||
# error "This target should not be compiled by ALL."
|
||||
#endif
|
Loading…
Reference in New Issue