summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2006-10-02 15:14:00 (GMT)
committerBrad King <brad.king@kitware.com>2006-10-02 15:14:00 (GMT)
commit1d9f287af758b4a9cf8c35463ce98af1169cccf6 (patch)
tree6b437cb7c5e9de4ae2ea2d7c357095a2026b0e9a
parent603b47c87a6b7bbf99dfd13e4b874ee51e528434 (diff)
downloadCMake-1d9f287af758b4a9cf8c35463ce98af1169cccf6.zip
CMake-1d9f287af758b4a9cf8c35463ce98af1169cccf6.tar.gz
CMake-1d9f287af758b4a9cf8c35463ce98af1169cccf6.tar.bz2
ENH: Added NOT_IN_ALL option for ADD_LIBRARY and ADD_EXECUTABLE to avoid building the targets by default.
-rw-r--r--Source/cmAddExecutableCommand.cxx9
-rw-r--r--Source/cmAddExecutableCommand.h7
-rw-r--r--Source/cmAddLibraryCommand.cxx9
-rw-r--r--Source/cmAddLibraryCommand.h7
-rw-r--r--Source/cmMakefile.cxx10
-rw-r--r--Source/cmMakefile.h6
-rw-r--r--Tests/Complex/Executable/CMakeLists.txt8
-rw-r--r--Tests/Complex/Executable/notInAllExe.cxx10
-rw-r--r--Tests/Complex/Library/CMakeLists.txt3
-rw-r--r--Tests/Complex/Library/notInAllLib.cxx5
-rw-r--r--Tests/ComplexOneConfig/Executable/CMakeLists.txt8
-rw-r--r--Tests/ComplexOneConfig/Executable/notInAllExe.cxx10
-rw-r--r--Tests/ComplexOneConfig/Library/CMakeLists.txt3
-rw-r--r--Tests/ComplexOneConfig/Library/notInAllLib.cxx5
-rw-r--r--Tests/ComplexRelativePaths/Executable/CMakeLists.txt8
-rw-r--r--Tests/ComplexRelativePaths/Executable/notInAllExe.cxx10
-rw-r--r--Tests/ComplexRelativePaths/Library/CMakeLists.txt3
-rw-r--r--Tests/ComplexRelativePaths/Library/notInAllLib.cxx5
18 files changed, 114 insertions, 12 deletions
diff --git a/Source/cmAddExecutableCommand.cxx b/Source/cmAddExecutableCommand.cxx
index d44fa9a..2fe544d 100644
--- a/Source/cmAddExecutableCommand.cxx
+++ b/Source/cmAddExecutableCommand.cxx
@@ -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");
diff --git a/Source/cmAddExecutableCommand.h b/Source/cmAddExecutableCommand.h
index 77140c5..0ed838a 100644
--- a/Source/cmAddExecutableCommand.h
+++ b/Source/cmAddExecutableCommand.h
@@ -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."
;
}
diff --git a/Source/cmAddLibraryCommand.cxx b/Source/cmAddLibraryCommand.cxx
index afcac0b..6b85d5f 100644
--- a/Source/cmAddLibraryCommand.cxx
+++ b/Source/cmAddLibraryCommand.cxx
@@ -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;
}
diff --git a/Source/cmAddLibraryCommand.h b/Source/cmAddLibraryCommand.h
index 86a9eb9..adb6246 100644
--- a/Source/cmAddLibraryCommand.h
+++ b/Source/cmAddLibraryCommand.h
@@ -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);
diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx
index 8799e52..29c3bde 100644
--- a/Source/cmMakefile.cxx
+++ b/Source/cmMakefile.cxx
@@ -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);
diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h
index 49071c4..5f3ff61 100644
--- a/Source/cmMakefile.h
+++ b/Source/cmMakefile.h
@@ -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)
/**
diff --git a/Tests/Complex/Executable/CMakeLists.txt b/Tests/Complex/Executable/CMakeLists.txt
index 61624c9..e2caf6a 100644
--- a/Tests/Complex/Executable/CMakeLists.txt
+++ b/Tests/Complex/Executable/CMakeLists.txt
@@ -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.
#
diff --git a/Tests/Complex/Executable/notInAllExe.cxx b/Tests/Complex/Executable/notInAllExe.cxx
new file mode 100644
index 0000000..70275cd
--- /dev/null
+++ b/Tests/Complex/Executable/notInAllExe.cxx
@@ -0,0 +1,10 @@
+extern int notInAllLibFunc();
+
+int main()
+{
+ return notInAllLibFunc();
+}
+
+#if 1
+# error "This target should not be compiled by ALL."
+#endif
diff --git a/Tests/Complex/Library/CMakeLists.txt b/Tests/Complex/Library/CMakeLists.txt
index 55d6ddb..d07bf48 100644
--- a/Tests/Complex/Library/CMakeLists.txt
+++ b/Tests/Complex/Library/CMakeLists.txt
@@ -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)
diff --git a/Tests/Complex/Library/notInAllLib.cxx b/Tests/Complex/Library/notInAllLib.cxx
new file mode 100644
index 0000000..5d928f4
--- /dev/null
+++ b/Tests/Complex/Library/notInAllLib.cxx
@@ -0,0 +1,5 @@
+int notInAllLibFunc() { return 0; }
+
+#if 1
+# error "This target should not be compiled by ALL."
+#endif
diff --git a/Tests/ComplexOneConfig/Executable/CMakeLists.txt b/Tests/ComplexOneConfig/Executable/CMakeLists.txt
index 61624c9..e2caf6a 100644
--- a/Tests/ComplexOneConfig/Executable/CMakeLists.txt
+++ b/Tests/ComplexOneConfig/Executable/CMakeLists.txt
@@ -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.
#
diff --git a/Tests/ComplexOneConfig/Executable/notInAllExe.cxx b/Tests/ComplexOneConfig/Executable/notInAllExe.cxx
new file mode 100644
index 0000000..70275cd
--- /dev/null
+++ b/Tests/ComplexOneConfig/Executable/notInAllExe.cxx
@@ -0,0 +1,10 @@
+extern int notInAllLibFunc();
+
+int main()
+{
+ return notInAllLibFunc();
+}
+
+#if 1
+# error "This target should not be compiled by ALL."
+#endif
diff --git a/Tests/ComplexOneConfig/Library/CMakeLists.txt b/Tests/ComplexOneConfig/Library/CMakeLists.txt
index 55d6ddb..d07bf48 100644
--- a/Tests/ComplexOneConfig/Library/CMakeLists.txt
+++ b/Tests/ComplexOneConfig/Library/CMakeLists.txt
@@ -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)
diff --git a/Tests/ComplexOneConfig/Library/notInAllLib.cxx b/Tests/ComplexOneConfig/Library/notInAllLib.cxx
new file mode 100644
index 0000000..5d928f4
--- /dev/null
+++ b/Tests/ComplexOneConfig/Library/notInAllLib.cxx
@@ -0,0 +1,5 @@
+int notInAllLibFunc() { return 0; }
+
+#if 1
+# error "This target should not be compiled by ALL."
+#endif
diff --git a/Tests/ComplexRelativePaths/Executable/CMakeLists.txt b/Tests/ComplexRelativePaths/Executable/CMakeLists.txt
index 61624c9..e2caf6a 100644
--- a/Tests/ComplexRelativePaths/Executable/CMakeLists.txt
+++ b/Tests/ComplexRelativePaths/Executable/CMakeLists.txt
@@ -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.
#
diff --git a/Tests/ComplexRelativePaths/Executable/notInAllExe.cxx b/Tests/ComplexRelativePaths/Executable/notInAllExe.cxx
new file mode 100644
index 0000000..70275cd
--- /dev/null
+++ b/Tests/ComplexRelativePaths/Executable/notInAllExe.cxx
@@ -0,0 +1,10 @@
+extern int notInAllLibFunc();
+
+int main()
+{
+ return notInAllLibFunc();
+}
+
+#if 1
+# error "This target should not be compiled by ALL."
+#endif
diff --git a/Tests/ComplexRelativePaths/Library/CMakeLists.txt b/Tests/ComplexRelativePaths/Library/CMakeLists.txt
index 55d6ddb..d07bf48 100644
--- a/Tests/ComplexRelativePaths/Library/CMakeLists.txt
+++ b/Tests/ComplexRelativePaths/Library/CMakeLists.txt
@@ -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)
diff --git a/Tests/ComplexRelativePaths/Library/notInAllLib.cxx b/Tests/ComplexRelativePaths/Library/notInAllLib.cxx
new file mode 100644
index 0000000..5d928f4
--- /dev/null
+++ b/Tests/ComplexRelativePaths/Library/notInAllLib.cxx
@@ -0,0 +1,5 @@
+int notInAllLibFunc() { return 0; }
+
+#if 1
+# error "This target should not be compiled by ALL."
+#endif