Merge topic 'link-depends-no-shared'

306796e Teach BuildDepends test to cover LINK_DEPENDS_NO_SHARED
ed97631 Optionally skip link dependencies on shared library files
This commit is contained in:
Brad King 2012-11-13 14:31:54 -05:00 committed by CMake Topic Stage
commit 035c29fee4
9 changed files with 109 additions and 1 deletions

View File

@ -277,6 +277,10 @@ cmComputeLinkInformation
this->UseImportLibrary = this->UseImportLibrary =
this->Makefile->GetDefinition("CMAKE_IMPORT_LIBRARY_SUFFIX")?true:false; this->Makefile->GetDefinition("CMAKE_IMPORT_LIBRARY_SUFFIX")?true:false;
// Check whether we should skip dependencies on shared library files.
this->LinkDependsNoShared =
this->Target->GetPropertyAsBool("LINK_DEPENDS_NO_SHARED");
// On platforms without import libraries there may be a special flag // On platforms without import libraries there may be a special flag
// to use when creating a plugin (module) that obtains symbols from // to use when creating a plugin (module) that obtains symbols from
// the program that will load it. // the program that will load it.
@ -650,7 +654,11 @@ void cmComputeLinkInformation::AddItem(std::string const& item, cmTarget* tgt)
// Pass the full path to the target file. // Pass the full path to the target file.
std::string lib = tgt->GetFullPath(config, implib, true); std::string lib = tgt->GetFullPath(config, implib, true);
if(!this->LinkDependsNoShared ||
tgt->GetType() != cmTarget::SHARED_LIBRARY)
{
this->Depends.push_back(lib); this->Depends.push_back(lib);
}
this->AddTargetItem(lib, tgt); this->AddTargetItem(lib, tgt);
this->AddLibraryRuntimeInfo(lib, tgt); this->AddLibraryRuntimeInfo(lib, tgt);

View File

@ -82,6 +82,7 @@ private:
// Configuration information. // Configuration information.
const char* Config; const char* Config;
const char* LinkLanguage; const char* LinkLanguage;
bool LinkDependsNoShared;
// Modes for dealing with dependent shared libraries. // Modes for dealing with dependent shared libraries.
enum SharedDepMode enum SharedDepMode

View File

@ -1221,6 +1221,15 @@ void cmDocumentVariables::DefineVariables(cmake* cm)
false, false,
"Variables that Control the Build"); "Variables that Control the Build");
cm->DefineProperty
("CMAKE_LINK_DEPENDS_NO_SHARED", cmProperty::VARIABLE,
"Whether to skip link dependencies on shared library files.",
"This variable initializes the LINK_DEPENDS_NO_SHARED "
"property on targets when they are created. "
"See that target property for additional information.",
false,
"Variables that Control the Build");
cm->DefineProperty cm->DefineProperty
("CMAKE_AUTOMOC", cmProperty::VARIABLE, ("CMAKE_AUTOMOC", cmProperty::VARIABLE,
"Whether to handle moc automatically for Qt targets.", "Whether to handle moc automatically for Qt targets.",

View File

@ -650,6 +650,22 @@ void cmTarget::DefineProperties(cmake *cm)
"It is intended to specify dependencies on \"linker scripts\" for " "It is intended to specify dependencies on \"linker scripts\" for "
"custom Makefile link rules."); "custom Makefile link rules.");
cm->DefineProperty
("LINK_DEPENDS_NO_SHARED", cmProperty::TARGET,
"Do not depend on linked shared library files.",
"Set this property to true to tell CMake generators not to add "
"file-level dependencies on the shared library files linked by "
"this target. "
"Modification to the shared libraries will not be sufficient to "
"re-link this target. "
"Logical target-level dependencies will not be affected so the "
"linked shared libraries will still be brought up to date before "
"this target is built."
"\n"
"This property is initialized by the value of the variable "
"CMAKE_LINK_DEPENDS_NO_SHARED if it is set when a target is "
"created.");
cm->DefineProperty cm->DefineProperty
("LINK_INTERFACE_LIBRARIES", cmProperty::TARGET, ("LINK_INTERFACE_LIBRARIES", cmProperty::TARGET,
"List public interface libraries for a shared library or executable.", "List public interface libraries for a shared library or executable.",
@ -1314,6 +1330,7 @@ void cmTarget::SetMakefile(cmMakefile* mf)
this->SetPropertyDefault("OSX_ARCHITECTURES", 0); this->SetPropertyDefault("OSX_ARCHITECTURES", 0);
this->SetPropertyDefault("AUTOMOC", 0); this->SetPropertyDefault("AUTOMOC", 0);
this->SetPropertyDefault("AUTOMOC_MOC_OPTIONS", 0); this->SetPropertyDefault("AUTOMOC_MOC_OPTIONS", 0);
this->SetPropertyDefault("LINK_DEPENDS_NO_SHARED", 0);
this->SetPropertyDefault("LINK_INTERFACE_LIBRARIES", 0); this->SetPropertyDefault("LINK_INTERFACE_LIBRARIES", 0);
this->SetPropertyDefault("WIN32_EXECUTABLE", 0); this->SetPropertyDefault("WIN32_EXECUTABLE", 0);
this->SetPropertyDefault("MACOSX_BUNDLE", 0); this->SetPropertyDefault("MACOSX_BUNDLE", 0);

View File

@ -60,6 +60,12 @@ file(WRITE ${BuildDepends_BINARY_DIR}/Project/zot_macro_dir.hxx
file(WRITE ${BuildDepends_BINARY_DIR}/Project/zot_macro_tgt.hxx file(WRITE ${BuildDepends_BINARY_DIR}/Project/zot_macro_tgt.hxx
"static const char* zot_macro_tgt = \"zot_macro_tgt\";\n") "static const char* zot_macro_tgt = \"zot_macro_tgt\";\n")
file(WRITE ${BuildDepends_BINARY_DIR}/Project/link_depends_no_shared_lib.h
"#define link_depends_no_shared_lib_value 1\n")
file(WRITE ${BuildDepends_BINARY_DIR}/Project/link_depends_no_shared_exe.h
"#define link_depends_no_shared_exe_value 0\n")
set(link_depends_no_shared_check_txt ${BuildDepends_BINARY_DIR}/Project/link_depends_no_shared_check.txt)
help_xcode_depends() help_xcode_depends()
message("Building project first time") message("Building project first time")
@ -125,6 +131,19 @@ else()
message(SEND_ERROR "Project did not initially build properly: ${out}") message(SEND_ERROR "Project did not initially build properly: ${out}")
endif() endif()
if(EXISTS "${link_depends_no_shared_check_txt}")
file(STRINGS "${link_depends_no_shared_check_txt}" link_depends_no_shared_check LIMIT_COUNT 1)
if("${link_depends_no_shared_check}" STREQUAL "1")
message(STATUS "link_depends_no_shared_exe is newer than link_depends_no_shared_lib as expected.")
else()
message(SEND_ERROR "Project did not initially build properly: "
"link_depends_no_shared_exe is older than link_depends_no_shared_lib.")
endif()
else()
message(SEND_ERROR "Project did not initially build properly: "
"Targets link_depends_no_shared_lib and link_depends_no_shared_exe not both built.")
endif()
message("Waiting 3 seconds...") message("Waiting 3 seconds...")
# any additional argument will cause ${bar} to wait forever # any additional argument will cause ${bar} to wait forever
execute_process(COMMAND ${bar} -infinite TIMEOUT 3 OUTPUT_VARIABLE out) execute_process(COMMAND ${bar} -infinite TIMEOUT 3 OUTPUT_VARIABLE out)
@ -141,6 +160,9 @@ file(WRITE ${BuildDepends_BINARY_DIR}/Project/zot_macro_dir.hxx
file(WRITE ${BuildDepends_BINARY_DIR}/Project/zot_macro_tgt.hxx file(WRITE ${BuildDepends_BINARY_DIR}/Project/zot_macro_tgt.hxx
"static const char* zot_macro_tgt = \"zot_macro_tgt changed\";\n") "static const char* zot_macro_tgt = \"zot_macro_tgt changed\";\n")
file(WRITE ${BuildDepends_BINARY_DIR}/Project/link_depends_no_shared_lib.h
"#define link_depends_no_shared_lib_value 0\n")
if(TEST_LINK_DEPENDS) if(TEST_LINK_DEPENDS)
file(WRITE ${TEST_LINK_DEPENDS} "2") file(WRITE ${TEST_LINK_DEPENDS} "2")
endif() endif()
@ -219,3 +241,15 @@ is not newer than dependency
") ")
endif() endif()
endif() endif()
if(EXISTS "${link_depends_no_shared_check_txt}")
file(STRINGS "${link_depends_no_shared_check_txt}" link_depends_no_shared_check LIMIT_COUNT 1)
if("${link_depends_no_shared_check}" STREQUAL "0")
message(STATUS "link_depends_no_shared_exe is older than link_depends_no_shared_lib as expected.")
else()
message(SEND_ERROR "Project did not rebuild properly: link_depends_no_shared_exe is newer than link_depends_no_shared_lib.")
endif()
else()
message(SEND_ERROR "Project did not rebuild properly. "
"Targets link_depends_no_shared_lib and link_depends_no_shared_exe not both built.")
endif()

View File

@ -108,3 +108,18 @@ if(TEST_LINK_DEPENDS)
add_executable(linkdep linkdep.cxx) add_executable(linkdep linkdep.cxx)
set_property(TARGET linkdep PROPERTY LINK_DEPENDS ${TEST_LINK_DEPENDS}) set_property(TARGET linkdep PROPERTY LINK_DEPENDS ${TEST_LINK_DEPENDS})
endif() endif()
add_library(link_depends_no_shared_lib SHARED link_depends_no_shared_lib.c
${CMAKE_CURRENT_BINARY_DIR}/link_depends_no_shared_lib.h)
add_executable(link_depends_no_shared_exe link_depends_no_shared_exe.c
${CMAKE_CURRENT_BINARY_DIR}/link_depends_no_shared_exe.h)
target_link_libraries(link_depends_no_shared_exe link_depends_no_shared_lib)
set_property(TARGET link_depends_no_shared_exe PROPERTY LINK_DEPENDS_NO_SHARED 1)
add_custom_target(link_depends_no_shared_check ALL
COMMAND ${CMAKE_COMMAND}
-Dlib=$<TARGET_FILE:link_depends_no_shared_lib>
-Dexe=$<TARGET_FILE:link_depends_no_shared_exe>
-Dout=${CMAKE_CURRENT_BINARY_DIR}/link_depends_no_shared_check.txt
-P ${CMAKE_CURRENT_SOURCE_DIR}/link_depends_no_shared_check.cmake
)
add_dependencies(link_depends_no_shared_check link_depends_no_shared_exe)

View File

@ -0,0 +1,7 @@
if(NOT EXISTS "${lib}" OR NOT EXISTS "${exe}")
file(REMOVE "${out}")
elseif("${exe}" IS_NEWER_THAN "${lib}")
file(WRITE "${out}" "1\n")
else()
file(WRITE "${out}" "0\n")
endif()

View File

@ -0,0 +1,9 @@
#include "link_depends_no_shared_exe.h"
#ifdef _WIN32
__declspec(dllimport)
#endif
int link_depends_no_shared_lib(void);
int main()
{
return link_depends_no_shared_lib() + link_depends_no_shared_exe_value;
}

View File

@ -0,0 +1,8 @@
#include "link_depends_no_shared_lib.h"
#ifdef _WIN32
__declspec(dllexport)
#endif
int link_depends_no_shared_lib(void)
{
return link_depends_no_shared_lib_value;
}