[Cmake-commits] CMake branch, next, updated. v2.8.6-1779-g3a283b5

Stephen Kelly steveire at gmail.com
Wed Nov 2 09:05:45 EDT 2011


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "CMake".

The branch, next has been updated
       via  3a283b54b062ad4dd67e114229bed64b634b514f (commit)
       via  3c62297bd2fa92dac3976dbbae566402e602ee4b (commit)
       via  83a2c5047606c69928cf0400f70dfc8ea738c522 (commit)
       via  d6572b1fcfc99998327d79e5dc052ff09d3ef146 (commit)
       via  5e6812c07c646fc7d3a14a72c4805e61c30db6c8 (commit)
       via  96294da626d0b5a01d6dd76d1aac671c851c88dc (commit)
      from  1094aac9d6f119493ae492060c0958471b0dc986 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=3a283b54b062ad4dd67e114229bed64b634b514f
commit 3a283b54b062ad4dd67e114229bed64b634b514f
Merge: 1094aac 3c62297
Author:     Stephen Kelly <steveire at gmail.com>
AuthorDate: Wed Nov 2 09:05:44 2011 -0400
Commit:     CMake Topic Stage <kwrobot at kitware.com>
CommitDate: Wed Nov 2 09:05:44 2011 -0400

    Merge topic 'test-target_link_libraries' into next
    
    3c62297 Merge branch 'target-link-libraries-interfaces' into test-target_link_libraries
    83a2c50 Revert "Revert "Remove unnecessary boolean.""
    d6572b1 Revert "Remove unnecessary boolean."
    5e6812c Merge branch 'target-link-libraries-interfaces' into test-target_link_libraries
    96294da Revert "Remove file that conflicts with another branch."


http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=3c62297bd2fa92dac3976dbbae566402e602ee4b
commit 3c62297bd2fa92dac3976dbbae566402e602ee4b
Merge: 83a2c50 f251ab2
Author:     Stephen Kelly <steveire at gmail.com>
AuthorDate: Wed Nov 2 14:05:02 2011 +0100
Commit:     Stephen Kelly <steveire at gmail.com>
CommitDate: Wed Nov 2 14:05:02 2011 +0100

    Merge branch 'target-link-libraries-interfaces' into test-target_link_libraries


http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=83a2c5047606c69928cf0400f70dfc8ea738c522
commit 83a2c5047606c69928cf0400f70dfc8ea738c522
Author:     Stephen Kelly <steveire at gmail.com>
AuthorDate: Wed Nov 2 14:04:38 2011 +0100
Commit:     Stephen Kelly <steveire at gmail.com>
CommitDate: Wed Nov 2 14:04:38 2011 +0100

    Revert "Revert "Remove unnecessary boolean.""
    
    This reverts commit d6572b1fcfc99998327d79e5dc052ff09d3ef146.

diff --git a/Source/cmTargetLinkLibrariesCommand.cxx b/Source/cmTargetLinkLibrariesCommand.cxx
index 2a40164..ab35c97 100644
--- a/Source/cmTargetLinkLibrariesCommand.cxx
+++ b/Source/cmTargetLinkLibrariesCommand.cxx
@@ -98,8 +98,6 @@ bool cmTargetLinkLibrariesCommand
   // specification if the keyword is encountered as the first argument.
   this->CurrentProcessingState = ProcessingLinkLibraries;
 
-  this->SpecifiesPublicAndPrivate = false;
-
   // add libraries, nothe that there is an optional prefix
   // of debug and optimized than can be used
   for(unsigned int i=1; i < args.size(); ++i)
@@ -128,10 +126,6 @@ bool cmTargetLinkLibrariesCommand
           );
         return true;
         }
-      if (this->CurrentProcessingState == ProcessingPrivateInterface)
-        {
-        this->SpecifiesPublicAndPrivate = true;
-        }
       this->CurrentProcessingState = ProcessingPublicInterface;
       }
     else if(args[i] == "LINK_PRIVATE")
@@ -145,10 +139,6 @@ bool cmTargetLinkLibrariesCommand
           );
         return true;
         }
-      if (this->CurrentProcessingState == ProcessingPublicInterface)
-        {
-        this->SpecifiesPublicAndPrivate = true;
-        }
       this->CurrentProcessingState = ProcessingPrivateInterface;
       }
     else if(args[i] == "debug")
@@ -222,12 +212,12 @@ bool cmTargetLinkLibrariesCommand
     cmSystemTools::SetFatalErrorOccured();
     }
 
-  // If the INTERFACE option was given, make sure the
-  // LINK_INTERFACE_LIBRARIES property exists.  This allows the
-  // command to be used to specify an empty link interface.
-  if((this->CurrentProcessingState == ProcessingLinkInterface
-        || (this->CurrentProcessingState == ProcessingPrivateInterface
-          && !this->SpecifiesPublicAndPrivate))
+  // If any of the LINK_ options were given, make sure the
+  // LINK_INTERFACE_LIBRARIES target property exists.
+  // Use of any of the new keywords implies awareness of
+  // this property. And if no libraries are named, it should
+  // result in an empty link interface.
+  if((this->CurrentProcessingState != ProcessingLinkInterface)
     && !this->Target->GetProperty("LINK_INTERFACE_LIBRARIES"))
     {
     this->Target->SetProperty("LINK_INTERFACE_LIBRARIES", "");
diff --git a/Source/cmTargetLinkLibrariesCommand.h b/Source/cmTargetLinkLibrariesCommand.h
index 3ed815d..e91c46d 100644
--- a/Source/cmTargetLinkLibrariesCommand.h
+++ b/Source/cmTargetLinkLibrariesCommand.h
@@ -158,8 +158,6 @@ private:
 
   ProcessingState CurrentProcessingState;
 
-  bool SpecifiesPublicAndPrivate;
-
   void HandleLibrary(const char* lib, cmTarget::LinkLibraryType llt);
 };
 

http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=d6572b1fcfc99998327d79e5dc052ff09d3ef146
commit d6572b1fcfc99998327d79e5dc052ff09d3ef146
Author:     Stephen Kelly <steveire at gmail.com>
AuthorDate: Wed Nov 2 12:56:58 2011 +0100
Commit:     Stephen Kelly <steveire at gmail.com>
CommitDate: Wed Nov 2 12:56:58 2011 +0100

    Revert "Remove unnecessary boolean."
    
    This reverts commit a8faf5b4ccd611b17399e9a91ee5333f48e3a8aa.

diff --git a/Source/cmTargetLinkLibrariesCommand.cxx b/Source/cmTargetLinkLibrariesCommand.cxx
index ab35c97..2a40164 100644
--- a/Source/cmTargetLinkLibrariesCommand.cxx
+++ b/Source/cmTargetLinkLibrariesCommand.cxx
@@ -98,6 +98,8 @@ bool cmTargetLinkLibrariesCommand
   // specification if the keyword is encountered as the first argument.
   this->CurrentProcessingState = ProcessingLinkLibraries;
 
+  this->SpecifiesPublicAndPrivate = false;
+
   // add libraries, nothe that there is an optional prefix
   // of debug and optimized than can be used
   for(unsigned int i=1; i < args.size(); ++i)
@@ -126,6 +128,10 @@ bool cmTargetLinkLibrariesCommand
           );
         return true;
         }
+      if (this->CurrentProcessingState == ProcessingPrivateInterface)
+        {
+        this->SpecifiesPublicAndPrivate = true;
+        }
       this->CurrentProcessingState = ProcessingPublicInterface;
       }
     else if(args[i] == "LINK_PRIVATE")
@@ -139,6 +145,10 @@ bool cmTargetLinkLibrariesCommand
           );
         return true;
         }
+      if (this->CurrentProcessingState == ProcessingPublicInterface)
+        {
+        this->SpecifiesPublicAndPrivate = true;
+        }
       this->CurrentProcessingState = ProcessingPrivateInterface;
       }
     else if(args[i] == "debug")
@@ -212,12 +222,12 @@ bool cmTargetLinkLibrariesCommand
     cmSystemTools::SetFatalErrorOccured();
     }
 
-  // If any of the LINK_ options were given, make sure the
-  // LINK_INTERFACE_LIBRARIES target property exists.
-  // Use of any of the new keywords implies awareness of
-  // this property. And if no libraries are named, it should
-  // result in an empty link interface.
-  if((this->CurrentProcessingState != ProcessingLinkInterface)
+  // If the INTERFACE option was given, make sure the
+  // LINK_INTERFACE_LIBRARIES property exists.  This allows the
+  // command to be used to specify an empty link interface.
+  if((this->CurrentProcessingState == ProcessingLinkInterface
+        || (this->CurrentProcessingState == ProcessingPrivateInterface
+          && !this->SpecifiesPublicAndPrivate))
     && !this->Target->GetProperty("LINK_INTERFACE_LIBRARIES"))
     {
     this->Target->SetProperty("LINK_INTERFACE_LIBRARIES", "");
diff --git a/Source/cmTargetLinkLibrariesCommand.h b/Source/cmTargetLinkLibrariesCommand.h
index e91c46d..3ed815d 100644
--- a/Source/cmTargetLinkLibrariesCommand.h
+++ b/Source/cmTargetLinkLibrariesCommand.h
@@ -158,6 +158,8 @@ private:
 
   ProcessingState CurrentProcessingState;
 
+  bool SpecifiesPublicAndPrivate;
+
   void HandleLibrary(const char* lib, cmTarget::LinkLibraryType llt);
 };
 

http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=5e6812c07c646fc7d3a14a72c4805e61c30db6c8
commit 5e6812c07c646fc7d3a14a72c4805e61c30db6c8
Merge: 96294da 8587bc2
Author:     Stephen Kelly <steveire at gmail.com>
AuthorDate: Wed Nov 2 12:54:57 2011 +0100
Commit:     Stephen Kelly <steveire at gmail.com>
CommitDate: Wed Nov 2 12:54:57 2011 +0100

    Merge branch 'target-link-libraries-interfaces' into test-target_link_libraries
    
    Conflicts:
    	Tests/CMakeCommands/target_link_libraries/CMakeLists.txt

diff --cc Tests/CMakeCommands/target_link_libraries/CMakeLists.txt
index fdd53eb,1faa888..6df1b4c
--- a/Tests/CMakeCommands/target_link_libraries/CMakeLists.txt
+++ b/Tests/CMakeCommands/target_link_libraries/CMakeLists.txt
@@@ -13,271 -13,46 +13,315 @@@ add_executable
    "${CMAKE_CURRENT_BINARY_DIR}/main.cxx"
  )
  
+ macro(ASSERT_PROPERTY _target _property _value)
+   get_target_property(_out ${_target} ${_property})
+   if (NOT _out)
+     set(_out "")
+   endif()
+   if (NOT "${_out}" STREQUAL "${_value}")
+     message(SEND_ERROR "Target ${_target} does not have property ${_property} with value ${_value}. Actual value: ${_out}")
+   endif()
+ endmacro()
+ 
+ include(GenerateExportHeader)
+ set(CMAKE_INCLUDE_CURRENT_DIR ON)
+ 
+ add_library(depA SHARED depA.cpp)
+ generate_export_header(depA)
+ 
+ add_library(depB SHARED depB.cpp)
+ generate_export_header(depB)
+ 
+ target_link_libraries(depB LINK_PRIVATE depA)
+ 
+ add_library(depC SHARED depC.cpp)
+ generate_export_header(depC)
+ 
+ target_link_libraries(depC LINK_PUBLIC depA)
+ 
+ assert_property(depA LINK_INTERFACE_LIBRARIES "")
+ assert_property(depB LINK_INTERFACE_LIBRARIES "")
+ assert_property(depC LINK_INTERFACE_LIBRARIES "depA")
+ 
+ add_executable(targetA targetA.cpp)
+ 
+ target_link_libraries(targetA LINK_INTERFACE_LIBRARIES depA depB)
+ 
+ assert_property(targetA LINK_INTERFACE_LIBRARIES "depA;depB")
+ 
+ set_target_properties(targetA PROPERTIES LINK_INTERFACE_LIBRARIES "")
+ 
+ assert_property(targetA LINK_INTERFACE_LIBRARIES "")
+ 
+ target_link_libraries(targetA depB depC)
+ 
+ assert_property(targetA LINK_INTERFACE_LIBRARIES "")
++
 +try_compile(LINK_INTERFACE_LIBRARIES_FAILS
 +  "${CMAKE_CURRENT_BINARY_DIR}/control_point"
 +  "${CMAKE_CURRENT_SOURCE_DIR}/control_point"
 +  control_point
 +)
 +
 +if (LINK_INTERFACE_LIBRARIES_FAILS)
 +  message("\n\n#######################\nTHIS PLATFORM DOES NOT SUPPORT LINK_INTERFACE_LIBRARIES\n\n")
 +  return()
 +endif()
 +
 +set(Bools True False)
 +
 +foreach(B1 ${Bools})
 +  foreach(B2 ${Bools})
 +    execute_process(COMMAND ${CMAKE_COMMAND} -E copy_directory
 +      "${CMAKE_CURRENT_SOURCE_DIR}/libs"
 +      "${CMAKE_CURRENT_BINARY_DIR}/libs_${B1}_${B2}"
 +    )
 +  endforeach()
 +endforeach()
 +
 +foreach(B1 ${Bools})
 +  file(APPEND "${CMAKE_CURRENT_BINARY_DIR}/libs_True_${B1}/CMakeLists.txt"
 +    "set(CMAKE_LINK_INTERFACE_LIBRARIES \"\")\n"
 +  )
 +endforeach()
 +
 +foreach(B1 ${Bools})
 +  foreach(B2 ${Bools})
 +    file(APPEND "${CMAKE_CURRENT_BINARY_DIR}/libs_${B1}_${B2}/CMakeLists.txt"
 +
 +      "add_library(libA SHARED classA.cpp)\n"
 +      "add_library(libB SHARED classB.cpp)\n"
 +      "add_library(libC SHARED classC.cpp)\n"
 +
 +      "generate_export_header(libA)\n"
 +      "generate_export_header(libB)\n"
 +      "generate_export_header(libC)\n"
 +
 +      "target_link_libraries(libB libA)\n"
 +      "target_link_libraries(libC libA libB)\n"
 +    )
 +  endforeach()
 +endforeach()
 +
 +foreach(B1 ${Bools})
 +  file(APPEND "${CMAKE_CURRENT_BINARY_DIR}/libs_${B1}_True/CMakeLists.txt"
 +      "target_link_libraries(libB LINK_INTERFACE_LIBRARIES libA)\n"
 +      "target_link_libraries(libC LINK_INTERFACE_LIBRARIES libA)\n"
 +    )
 +endforeach()
 +
 +foreach(B1 ${Bools})
 +  foreach(B2 ${Bools})
 +    file(APPEND "${CMAKE_CURRENT_BINARY_DIR}/libs_${B1}_${B2}/CMakeLists.txt"
 +      "export(TARGETS libA libB libC FILE Targets.cmake)\n"
 +    )
 +
 +    try_compile(Result "${CMAKE_CURRENT_BINARY_DIR}/libs_build_${B1}_${B2}"
 +      "${CMAKE_CURRENT_BINARY_DIR}/libs_${B1}_${B2}"
 +      libs
 +      OUTPUT_VARIABLE Out
 +    )
 +    if (NOT Result)
 +      message("Libs CLEAR_LINK_INTERFACE_LIBRARIES: ${B1}\n"
 +              "Libs SPECIFY_LINK_INTERFACE_LIBRARIES: ${B2}\n\n\n${Out}")
 +      message("\n\n#######################\nTHIS PLATFORM DOES NOT SUPPORT LINK_INTERFACE_LIBRARIES\n\n")
 +      return()
 +    endif()
 +  endforeach()
 +endforeach()
 +
 +
 +set (COUNT 0)
 +macro(_do_build CLEAR_LINK_INTERFACE_LIBRARIES
 +                SPECIFY_LINK_INTERFACE_LIBRARIES)
 +  math(EXPR COUNT "${COUNT} + 1" )
 +
 +  execute_process(COMMAND ${CMAKE_COMMAND} -E copy_directory
 +    "${CMAKE_CURRENT_SOURCE_DIR}/src"
 +    "${CMAKE_CURRENT_BINARY_DIR}/test${COUNT}"
 +  )
 +
 +  # Set local short variables to avoid long lines
 +  set(B1 ${CLEAR_LINK_INTERFACE_LIBRARIES})
 +  set(B2 ${SPECIFY_LINK_INTERFACE_LIBRARIES})
 +  set(Libs_Build_Dir "${CMAKE_CURRENT_BINARY_DIR}/libs_build_${B1}_${B2}")
 +
 +  file(APPEND "${CMAKE_CURRENT_BINARY_DIR}/test${COUNT}/CMakeLists.txt"
 +    "include_directories(\"${CMAKE_CURRENT_BINARY_DIR}/libs_${B1}_${B2}\"\n"
 +    "                    \"${Libs_Build_Dir}\"\n"
 +    ")\n"
 +    "include(\"${Libs_Build_Dir}/Targets.cmake\")\n"
 +  )
 +
 +  file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/test${COUNT}/main.cpp"
 +    ""
 +  )
 +
 +  foreach(klass ${ARGN})
 +    if (klass STREQUAL "LIBS")
 +      break()
 +    endif()
 +    file(APPEND "${CMAKE_CURRENT_BINARY_DIR}/test${COUNT}/main.cpp"
 +      "#include \"${klass}.h\"\n"
 +    )
 +  endforeach()
 +
 +  file(APPEND "${CMAKE_CURRENT_BINARY_DIR}/test${COUNT}/main.cpp"
 +    "int main(int, char **) {"
 +  )
 +
 +  foreach(klass ${ARGN})
 +    if (klass STREQUAL "LIBS")
 +      break()
 +    endif()
 +    file(APPEND "${CMAKE_CURRENT_BINARY_DIR}/test${COUNT}/main.cpp"
 +      "${klass} ${klass}_;\n"
 +    )
 +  endforeach()
 +
 +  file(APPEND "${CMAKE_CURRENT_BINARY_DIR}/test${COUNT}/main.cpp"
 +    "return 0;"
 +    "}\n"
 +  )
 +
 +  file(APPEND "${CMAKE_CURRENT_BINARY_DIR}/test${COUNT}/CMakeLists.txt"
 +
 +    "add_executable(exec \n"
 +    "\"${CMAKE_CURRENT_BINARY_DIR}/test${COUNT}/main.cpp\")\n"
 +  )
 +
 +  file(APPEND "${CMAKE_CURRENT_BINARY_DIR}/test${COUNT}/CMakeLists.txt"
 +    "target_link_libraries(exec "
 +  )
 +
 +  set(continue True)
 +  foreach(klass ${ARGN})
 +    if (klass STREQUAL "LIBS")
 +      # CMake has no continue() command
 +      set(continue False)
 +    endif()
 +    if (NOT continue AND NOT klass STREQUAL "LIBS")
 +      file(APPEND "${CMAKE_CURRENT_BINARY_DIR}/test${COUNT}/CMakeLists.txt"
 +        "${klass} "
 +      )
 +    endif()
 +  endforeach()
 +
 +  file(APPEND "${CMAKE_CURRENT_BINARY_DIR}/test${COUNT}/CMakeLists.txt"
 +    ")\n"
 +  )
 +
 +  try_compile(Result "${CMAKE_CURRENT_BINARY_DIR}/fail${COUNT}"
 +    "${CMAKE_CURRENT_BINARY_DIR}/test${COUNT}"
 +    src
 +    OUTPUT_VARIABLE Out
 +  )
 +endmacro()
 +
 +macro(EXPECT_PASS)
 +  _do_build(${ARGN})
 +  if (NOT ${Result})
 +    message(SEND_ERROR "Failed! \n\n${Out}")
 +  endif()
 +endmacro()
 +
 +macro(EXPECT_FAIL)
 +  _do_build(${ARGN})
 +  if (${Result})
 +    message(SEND_ERROR "Failed! \n\n${Out}")
 +  endif()
 +endmacro()
 +
 +macro(all_pass)
 +  expect_pass(False False ${ARGN})
 +  expect_pass(True False ${ARGN})
 +  expect_pass(False True ${ARGN})
 +  expect_pass(True True ${ARGN})
 +endmacro()
 +
 +# If we specify all libs to the executable, it will always pass
 +all_pass(
 +    classA
 +  LIBS
 +    libA
 +)
 +
 +all_pass(
 +    classA classB
 +  LIBS
 +    libA libB
 +)
 +
 +all_pass(
 +    classA classC
 +  LIBS
 +    libA libC
 +)
 +
 +all_pass(
 +    classA classB classC
 +  LIBS
 +    libA libB libC
 +)
 +
 +# If we don't set the CMAKE_LINK_INTERFACE_LIBRARIES to empty and
 +# we don't explicitly specify the LINK_INTERFACE_LIBRARIES, the
 +# executable can use all classes if linked
 +# indirectly to them
 +expect_pass(False False
 +    classA classB
 +  LIBS
 +    libB
 +)
 +
 +# Although libC is linked to libA, libA is not part of the link interface of
 +# libC.
 +# Because we don't clear the CMAKE_LINK_INTERFACE_LIBRARIES it still works.
 +expect_pass(False False
 +    classA classC
 +  LIBS
 +    libC
 +)
 +
 +# However, if we do clear it and don't explicitly link the executable to it,
 +# it fails,
 +# whether we specify the link_interface_libraries properly or not.
 +if (NOT APPLE)
 +  expect_fail(True False
 +    classB classC
 +  LIBS
 +    libC
 +  )
 +  expect_fail(True True
 +      classB classC
 +    LIBS
 +      libC
 +  )
 +endif()
 +
 +
 +# Then we can still link the executable to libA directly of course to pass
 +expect_pass(True False
 +    classA classC
 +  LIBS
 +    libC libA
 +)
 +expect_pass(True True
 +    classA classC
 +  LIBS
 +    libC libA
 +)
 +
 +# Also, if we clear and specify the link interface, we can use classes defined
 +# in that interface without linking to the library directly
 +expect_pass(True True
 +    classA classB
 +  LIBS
 +    libB
 +)
 +
 +expect_pass(True True
 +    classA classC
 +  LIBS
 +    libC
 +)

http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=96294da626d0b5a01d6dd76d1aac671c851c88dc
commit 96294da626d0b5a01d6dd76d1aac671c851c88dc
Author:     Stephen Kelly <steveire at gmail.com>
AuthorDate: Wed Nov 2 12:54:06 2011 +0100
Commit:     Stephen Kelly <steveire at gmail.com>
CommitDate: Wed Nov 2 12:54:06 2011 +0100

    Revert "Remove file that conflicts with another branch."
    
    This reverts commit c7b4d9dc9d9aaa670184364747a942532a6ebf98.

diff --git a/Tests/CMakeCommands/target_link_libraries/CMakeLists.txt b/Tests/CMakeCommands/target_link_libraries/CMakeLists.txt
new file mode 100644
index 0000000..fdd53eb
--- /dev/null
+++ b/Tests/CMakeCommands/target_link_libraries/CMakeLists.txt
@@ -0,0 +1,283 @@
+cmake_minimum_required(VERSION 2.8)
+
+project(target_link_libraries)
+
+file(WRITE
+  "${CMAKE_CURRENT_BINARY_DIR}/main.cxx"
+  "int main() { return 0; }
+"
+)
+
+add_executable(
+  target_link_libraries
+  "${CMAKE_CURRENT_BINARY_DIR}/main.cxx"
+)
+
+try_compile(LINK_INTERFACE_LIBRARIES_FAILS
+  "${CMAKE_CURRENT_BINARY_DIR}/control_point"
+  "${CMAKE_CURRENT_SOURCE_DIR}/control_point"
+  control_point
+)
+
+if (LINK_INTERFACE_LIBRARIES_FAILS)
+  message("\n\n#######################\nTHIS PLATFORM DOES NOT SUPPORT LINK_INTERFACE_LIBRARIES\n\n")
+  return()
+endif()
+
+set(Bools True False)
+
+foreach(B1 ${Bools})
+  foreach(B2 ${Bools})
+    execute_process(COMMAND ${CMAKE_COMMAND} -E copy_directory
+      "${CMAKE_CURRENT_SOURCE_DIR}/libs"
+      "${CMAKE_CURRENT_BINARY_DIR}/libs_${B1}_${B2}"
+    )
+  endforeach()
+endforeach()
+
+foreach(B1 ${Bools})
+  file(APPEND "${CMAKE_CURRENT_BINARY_DIR}/libs_True_${B1}/CMakeLists.txt"
+    "set(CMAKE_LINK_INTERFACE_LIBRARIES \"\")\n"
+  )
+endforeach()
+
+foreach(B1 ${Bools})
+  foreach(B2 ${Bools})
+    file(APPEND "${CMAKE_CURRENT_BINARY_DIR}/libs_${B1}_${B2}/CMakeLists.txt"
+
+      "add_library(libA SHARED classA.cpp)\n"
+      "add_library(libB SHARED classB.cpp)\n"
+      "add_library(libC SHARED classC.cpp)\n"
+
+      "generate_export_header(libA)\n"
+      "generate_export_header(libB)\n"
+      "generate_export_header(libC)\n"
+
+      "target_link_libraries(libB libA)\n"
+      "target_link_libraries(libC libA libB)\n"
+    )
+  endforeach()
+endforeach()
+
+foreach(B1 ${Bools})
+  file(APPEND "${CMAKE_CURRENT_BINARY_DIR}/libs_${B1}_True/CMakeLists.txt"
+      "target_link_libraries(libB LINK_INTERFACE_LIBRARIES libA)\n"
+      "target_link_libraries(libC LINK_INTERFACE_LIBRARIES libA)\n"
+    )
+endforeach()
+
+foreach(B1 ${Bools})
+  foreach(B2 ${Bools})
+    file(APPEND "${CMAKE_CURRENT_BINARY_DIR}/libs_${B1}_${B2}/CMakeLists.txt"
+      "export(TARGETS libA libB libC FILE Targets.cmake)\n"
+    )
+
+    try_compile(Result "${CMAKE_CURRENT_BINARY_DIR}/libs_build_${B1}_${B2}"
+      "${CMAKE_CURRENT_BINARY_DIR}/libs_${B1}_${B2}"
+      libs
+      OUTPUT_VARIABLE Out
+    )
+    if (NOT Result)
+      message("Libs CLEAR_LINK_INTERFACE_LIBRARIES: ${B1}\n"
+              "Libs SPECIFY_LINK_INTERFACE_LIBRARIES: ${B2}\n\n\n${Out}")
+      message("\n\n#######################\nTHIS PLATFORM DOES NOT SUPPORT LINK_INTERFACE_LIBRARIES\n\n")
+      return()
+    endif()
+  endforeach()
+endforeach()
+
+
+set (COUNT 0)
+macro(_do_build CLEAR_LINK_INTERFACE_LIBRARIES
+                SPECIFY_LINK_INTERFACE_LIBRARIES)
+  math(EXPR COUNT "${COUNT} + 1" )
+
+  execute_process(COMMAND ${CMAKE_COMMAND} -E copy_directory
+    "${CMAKE_CURRENT_SOURCE_DIR}/src"
+    "${CMAKE_CURRENT_BINARY_DIR}/test${COUNT}"
+  )
+
+  # Set local short variables to avoid long lines
+  set(B1 ${CLEAR_LINK_INTERFACE_LIBRARIES})
+  set(B2 ${SPECIFY_LINK_INTERFACE_LIBRARIES})
+  set(Libs_Build_Dir "${CMAKE_CURRENT_BINARY_DIR}/libs_build_${B1}_${B2}")
+
+  file(APPEND "${CMAKE_CURRENT_BINARY_DIR}/test${COUNT}/CMakeLists.txt"
+    "include_directories(\"${CMAKE_CURRENT_BINARY_DIR}/libs_${B1}_${B2}\"\n"
+    "                    \"${Libs_Build_Dir}\"\n"
+    ")\n"
+    "include(\"${Libs_Build_Dir}/Targets.cmake\")\n"
+  )
+
+  file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/test${COUNT}/main.cpp"
+    ""
+  )
+
+  foreach(klass ${ARGN})
+    if (klass STREQUAL "LIBS")
+      break()
+    endif()
+    file(APPEND "${CMAKE_CURRENT_BINARY_DIR}/test${COUNT}/main.cpp"
+      "#include \"${klass}.h\"\n"
+    )
+  endforeach()
+
+  file(APPEND "${CMAKE_CURRENT_BINARY_DIR}/test${COUNT}/main.cpp"
+    "int main(int, char **) {"
+  )
+
+  foreach(klass ${ARGN})
+    if (klass STREQUAL "LIBS")
+      break()
+    endif()
+    file(APPEND "${CMAKE_CURRENT_BINARY_DIR}/test${COUNT}/main.cpp"
+      "${klass} ${klass}_;\n"
+    )
+  endforeach()
+
+  file(APPEND "${CMAKE_CURRENT_BINARY_DIR}/test${COUNT}/main.cpp"
+    "return 0;"
+    "}\n"
+  )
+
+  file(APPEND "${CMAKE_CURRENT_BINARY_DIR}/test${COUNT}/CMakeLists.txt"
+
+    "add_executable(exec \n"
+    "\"${CMAKE_CURRENT_BINARY_DIR}/test${COUNT}/main.cpp\")\n"
+  )
+
+  file(APPEND "${CMAKE_CURRENT_BINARY_DIR}/test${COUNT}/CMakeLists.txt"
+    "target_link_libraries(exec "
+  )
+
+  set(continue True)
+  foreach(klass ${ARGN})
+    if (klass STREQUAL "LIBS")
+      # CMake has no continue() command
+      set(continue False)
+    endif()
+    if (NOT continue AND NOT klass STREQUAL "LIBS")
+      file(APPEND "${CMAKE_CURRENT_BINARY_DIR}/test${COUNT}/CMakeLists.txt"
+        "${klass} "
+      )
+    endif()
+  endforeach()
+
+  file(APPEND "${CMAKE_CURRENT_BINARY_DIR}/test${COUNT}/CMakeLists.txt"
+    ")\n"
+  )
+
+  try_compile(Result "${CMAKE_CURRENT_BINARY_DIR}/fail${COUNT}"
+    "${CMAKE_CURRENT_BINARY_DIR}/test${COUNT}"
+    src
+    OUTPUT_VARIABLE Out
+  )
+endmacro()
+
+macro(EXPECT_PASS)
+  _do_build(${ARGN})
+  if (NOT ${Result})
+    message(SEND_ERROR "Failed! \n\n${Out}")
+  endif()
+endmacro()
+
+macro(EXPECT_FAIL)
+  _do_build(${ARGN})
+  if (${Result})
+    message(SEND_ERROR "Failed! \n\n${Out}")
+  endif()
+endmacro()
+
+macro(all_pass)
+  expect_pass(False False ${ARGN})
+  expect_pass(True False ${ARGN})
+  expect_pass(False True ${ARGN})
+  expect_pass(True True ${ARGN})
+endmacro()
+
+# If we specify all libs to the executable, it will always pass
+all_pass(
+    classA
+  LIBS
+    libA
+)
+
+all_pass(
+    classA classB
+  LIBS
+    libA libB
+)
+
+all_pass(
+    classA classC
+  LIBS
+    libA libC
+)
+
+all_pass(
+    classA classB classC
+  LIBS
+    libA libB libC
+)
+
+# If we don't set the CMAKE_LINK_INTERFACE_LIBRARIES to empty and
+# we don't explicitly specify the LINK_INTERFACE_LIBRARIES, the
+# executable can use all classes if linked
+# indirectly to them
+expect_pass(False False
+    classA classB
+  LIBS
+    libB
+)
+
+# Although libC is linked to libA, libA is not part of the link interface of
+# libC.
+# Because we don't clear the CMAKE_LINK_INTERFACE_LIBRARIES it still works.
+expect_pass(False False
+    classA classC
+  LIBS
+    libC
+)
+
+# However, if we do clear it and don't explicitly link the executable to it,
+# it fails,
+# whether we specify the link_interface_libraries properly or not.
+if (NOT APPLE)
+  expect_fail(True False
+    classB classC
+  LIBS
+    libC
+  )
+  expect_fail(True True
+      classB classC
+    LIBS
+      libC
+  )
+endif()
+
+
+# Then we can still link the executable to libA directly of course to pass
+expect_pass(True False
+    classA classC
+  LIBS
+    libC libA
+)
+expect_pass(True True
+    classA classC
+  LIBS
+    libC libA
+)
+
+# Also, if we clear and specify the link interface, we can use classes defined
+# in that interface without linking to the library directly
+expect_pass(True True
+    classA classB
+  LIBS
+    libB
+)
+
+expect_pass(True True
+    classA classC
+  LIBS
+    libC
+)

-----------------------------------------------------------------------

Summary of changes:
 .../target_link_libraries/CMakeLists.txt           |  269 ++++++++++++++++++++
 1 files changed, 269 insertions(+), 0 deletions(-)


hooks/post-receive
-- 
CMake


More information about the Cmake-commits mailing list