source: git/modules/FindHeader.cmake @ fec53d

fieker-DuValspielwiese
Last change on this file since fec53d was 8cc501, checked in by Kai Krüger <krueger@…>, 14 years ago
Added files to compile with cmake. Still experimental. Might not work git-svn-id: file:///usr/local/Singular/svn/trunk@13240 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 4.0 KB
Line 
1# -*- mode: cmake; -*-
2#
3#
4#
5macro(check_header HEADER)
6  STRING(TOUPPER ${HEADER} ENABLE_FLAG)
7  STRING(REGEX REPLACE "/" "_" ENABLE_FLAG ${ENABLE_FLAG})
8  STRING(REGEX REPLACE ".H$" "_H" ENABLE_FLAG ${ENABLE_FLAG})
9
10  FIND_PATH(HAVE_${ENABLE_FLAG}
11     NAMES ${HEADER}
12     PATHS
13     ${CMAKE_ADDITIONAL_PATH}
14#     ${CMAKE_INCLUDE_PATH}
15     /usr/local/include
16     /usr/include
17  )
18  if( "${HAVE_${ENABLE_FLAG}}" STREQUAL "HAVE_${ENABLE_FLAG}-NOTFOUND" )
19    message(STATUS "Checking for ${HEADER} 'HAVE_${ENABLE_FLAG}' ... not found")
20    check_cpp_header(${HEADER})
21  else()
22    message(STATUS "Checking for ${HEADER} 'HAVE_${ENABLE_FLAG}' ... found")
23  endif()
24endmacro()
25
26macro(check_cpp_header HEADER)
27  STRING(TOUPPER ${HEADER} ENABLE_FLAG)
28  STRING(REGEX REPLACE "/" "_" ENABLE_FLAG ${ENABLE_FLAG})
29  STRING(REGEX REPLACE ".H$" "_H" ENABLE_FLAG ${ENABLE_FLAG})
30 
31  set(_srcfile ${CMAKE_BINARY_DIR}/temp.cpp)
32  set(srccode "#include <${HEADER}>\nint main() { return 0\;}")
33  file(WRITE ${_srcfile} ${srccode})
34  #message(STATUS "source='${srccode}'")
35  set(lang CXX)
36  #  try_run(RUN_RESULT_VAR COMPILE_RESULT_VAR
37  #          ${CMAKE_BINARY_DIR} ${_srcfile})
38
39  try_compile(RESULT_VAR ${CMAKE_BINARY_DIR} ${_srcfile}
40    OUTPUT_VARIABLE _output
41    )
42  #              [CMAKE_FLAGS <Flags>]
43  #              [COMPILE_DEFINITIONS <flags> ...]
44  #              [OUTPUT_VARIABLE var]
45  #              [COPY_FILE <filename> )
46  #try_run(RUN_RESULT_VAR COMPILE_RESULT_VAR
47  #          bindir srcfile [CMAKE_FLAGS <Flags>]
48  #          [COMPILE_DEFINITIONS <flags>]
49  #          [COMPILE_OUTPUT_VARIABLE comp]
50  #          [RUN_OUTPUT_VARIABLE run]
51  #          [OUTPUT_VARIABLE var]
52  #          [ARGS <arg1> <arg2>...])
53
54  #  message(STATUS "Compiling ${HEADER} with result '${_output}'")
55  #  message(STATUS "Compiling ${HEADER} with result '${RESULT_VAR}'")
56  if(RESULT_VAR)
57    set(HAVE_${ENABLE_FLAG} "/usr" CACHE PATH "" FORCE)
58  endif(RESULT_VAR)
59  if( "${HAVE_${ENABLE_FLAG}}" STREQUAL "HAVE_${ENABLE_FLAG}-NOTFOUND" )
60    message(STATUS "Checking for ${HEADER} 'HAVE_${ENABLE_FLAG}' ... not found")
61  else()
62    message(STATUS "Checking for ${HEADER} 'HAVE_${ENABLE_FLAG}' ... found")
63  endif()
64#  message(STATUS "Compiling ${HEADER} with result '${COMPILE_RESULT_VAR}'")
65#  message(STATUS "Compiling ${HEADER} with result '${RUN_RESULT_VAR}'")
66endmacro()
67#
68#
69#
70function(check_headers HEADERS)
71  message(STATUS "Headers '${ARGV}'")
72  foreach(loop_var ${ARGV})
73    string(STRIP ${loop_var} HEADER)
74    check_header(${HEADER})
75  endforeach(loop_var)
76endfunction()
77
78#
79#
80#
81function(check_funcs FUNCS)
82  foreach(loop_var ${ARGV})
83    string(STRIP ${loop_var} FUNC)
84    string(TOUPPER ${loop_var} VAR)
85    check_function_exists(${FUNC} HAVE_${VAR})
86  endforeach(loop_var)
87endfunction()
88
89#
90#
91#
92function(check_library NAME )
93#  message(STATUS "libray '${NAME}'")
94#  ac_have_lib_NAME
95
96  message(STATUS "Checking library ${NAME}...")
97  string(TOUPPER ${NAME} VAR)
98  SET(CMAKE_FIND_LIBRARY_SUFFIXES .a )# ${CMAKE_FIND_LIBRARY_SUFFIXES})
99  FIND_LIBRARY(ac_have_lib_${VAR}
100    NAMES ${NAME}
101    PATHS ${CMAKE_LIBRARY_PATH} /usr/lib /usr/local/lib
102    PATH_SUFFIXES lib
103  )
104  message(STATUS "Checking library ${NAME}... ${ac_have_lib_${VAR}}")
105  if(ac_have_lib_${VAR})
106    set(HAVE_LIB${VAR} 1 )
107  else(ac_have_lib_${VAR})
108    set(HAVE_LIB${VAR} 0 )
109  endif(ac_have_lib_${VAR})
110
111  if(NOT HAVE_LIB${VAR})
112    SET(CMAKE_FIND_LIBRARY_SUFFIXES .so )# ${CMAKE_FIND_LIBRARY_SUFFIXES})
113    FIND_LIBRARY(ac_have_lib_${VAR}_DL
114      NAMES ${NAME}
115      PATHS ${CMAKE_LIBRARY_PATH} /usr/lib /usr/local/lib
116      PATH_SUFFIXES lib
117      )
118    message(STATUS "Checking library ${NAME}... ${ac_have_lib_${VAR}_DL}")
119  endif(NOT HAVE_LIB${VAR})
120
121  if(ac_have_lib_${VAR}_DL)
122    set(HAVE_LIB${VAR}_DL 1 )
123  else(ac_have_lib_${VAR}_DL)
124    set(HAVE_LIB${VAR}_DL 0 )
125  endif(ac_have_lib_${VAR}_DL)
126
127  set(HAVE_LIB${VAR} ${HAVE_LIB${VAR}} PARENT_SCOPE)
128  set(HAVE_LIB${VAR}_DL ${HAVE_LIB${VAR}_DL} PARENT_SCOPE)
129
130message(STATUS "1 HAVE_LIB${VAR} =" ${HAVE_LIB${VAR}})
131message(STATUS "1 HAVE_LIB${VAR}_DL =" ${HAVE_LIB${VAR}_DL})
132endfunction(check_library NAME)
Note: See TracBrowser for help on using the repository browser.