File: CMakeLists.txt

package info (click to toggle)
cmake 2.8.11.1-1~bpo70+1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy-backports
  • size: 37,056 kB
  • sloc: cpp: 157,219; ansic: 137,155; yacc: 3,254; sh: 2,745; xml: 2,483; lex: 1,028; lisp: 215; python: 199; objc: 134; f90: 105; perl: 99; fortran: 93; makefile: 65; tcl: 55; asm: 28; php: 25; ruby: 22; java: 20
file content (27 lines) | stat: -rw-r--r-- 1,075 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
cmake_minimum_required(VERSION 2.8.4.20110303 FATAL_ERROR)
project(LinkStatic C)

if(NOT "${CMAKE_C_COMPILER_ID}" MATCHES "^(GNU)$")
  message(FATAL_ERROR "This test works only with the GNU compiler!")
endif()

find_library(MATH_LIBRARY NAMES libm.a)
if(MATH_LIBRARY)
  get_filename_component(MATH_LIB_DIR ${MATH_LIBRARY} PATH)
  link_directories(${MATH_LIB_DIR})
  # Name the library both with a full path and as "-lm" to
  # activate the link type switching code for both cases.
  # If the second one links shared then the link will fail.
  set(MATH_LIBRARIES ${MATH_LIBRARY} -lm)
else()
  message(FATAL_ERROR "Cannot find libm.a needed for this test")
endif()

add_executable(LinkStatic LinkStatic.c)
target_link_libraries(LinkStatic ${MATH_LIBRARIES})

# Enable static linking.
set(LinkStatic_FLAG "-static" CACHE STRING "Flag to link statically")
set_property(TARGET LinkStatic PROPERTY LINK_FLAGS "${LinkStatic_FLAG}")
set_property(TARGET LinkStatic PROPERTY LINK_SEARCH_START_STATIC 1)
#set_property(TARGET LinkStatic PROPERTY LINK_SEARCH_END_STATIC 1) # insufficient