CMP0060-Common.cmake 1.5 KB

123456789101112131415161718192021222324252627282930313233343536
  1. # Always build in a predictable configuration. For multi-config
  2. # generators we depend on RunCMakeTest.cmake to do this for us.
  3. get_property(_isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
  4. if(NOT _isMultiConfig)
  5. set(CMAKE_BUILD_TYPE Debug)
  6. endif()
  7. # Convince CMake that it can instruct the linker to search for the
  8. # library of the proper linkage type, but do not really pass flags.
  9. set(CMAKE_EXE_LINK_STATIC_C_FLAGS " ")
  10. set(CMAKE_EXE_LINK_DYNAMIC_C_FLAGS " ")
  11. # Make a link line asking for the linker to search for the library
  12. # look like a missing object file so we will get predictable content
  13. # in the error message. This also ensures that cases expected to use
  14. # the full path can be verified by confirming that they link.
  15. set(CMAKE_LINK_LIBRARY_FLAG LINKFLAG_)
  16. set(CMAKE_LINK_LIBRARY_SUFFIX _LINKSUFFIX${CMAKE_C_OUTPUT_EXTENSION})
  17. # Convince CMake that our library is in an implicit linker search directory.
  18. list(APPEND CMAKE_C_IMPLICIT_LINK_DIRECTORIES ${CMAKE_CURRENT_BINARY_DIR}/lib)
  19. # Create a simple library file. Place it in our library directory.
  20. add_library(CMP0060 STATIC cmp0060.c)
  21. set_property(TARGET CMP0060 PROPERTY
  22. ARCHIVE_OUTPUT_DIRECTORY_DEBUG ${CMAKE_CURRENT_BINARY_DIR}/lib)
  23. # Add a target to link the library file by full path.
  24. add_executable(main1 main.c)
  25. target_link_libraries(main1 $<TARGET_FILE:CMP0060>)
  26. add_dependencies(main1 CMP0060)
  27. # Add a second target to verify the warning only appears once.
  28. add_executable(main2 main.c)
  29. target_link_libraries(main2 $<TARGET_FILE:CMP0060>)
  30. add_dependencies(main2 CMP0060)