CMakeLists.txt 1.0 KB

123456789101112131415161718192021222324252627
  1. cmake_minimum_required(VERSION 2.8.4.20110303 FATAL_ERROR)
  2. project(LinkStatic C)
  3. if(NOT CMAKE_C_COMPILER_ID STREQUAL "GNU")
  4. message(FATAL_ERROR "This test works only with the GNU compiler!")
  5. endif()
  6. find_library(MATH_LIBRARY NAMES libm.a)
  7. if(MATH_LIBRARY)
  8. get_filename_component(MATH_LIB_DIR ${MATH_LIBRARY} PATH)
  9. link_directories(${MATH_LIB_DIR})
  10. # Name the library both with a full path and as "-lm" to
  11. # activate the link type switching code for both cases.
  12. # If the second one links shared then the link will fail.
  13. set(MATH_LIBRARIES ${MATH_LIBRARY} -lm)
  14. else()
  15. message(FATAL_ERROR "Cannot find libm.a needed for this test")
  16. endif()
  17. add_executable(LinkStatic LinkStatic.c)
  18. target_link_libraries(LinkStatic ${MATH_LIBRARIES})
  19. # Enable static linking.
  20. set(LinkStatic_FLAG "-static" CACHE STRING "Flag to link statically")
  21. set_property(TARGET LinkStatic PROPERTY LINK_FLAGS "${LinkStatic_FLAG}")
  22. set_property(TARGET LinkStatic PROPERTY LINK_SEARCH_START_STATIC 1)
  23. #set_property(TARGET LinkStatic PROPERTY LINK_SEARCH_END_STATIC 1) # insufficient