1 # Based on CheckLibraryExists.cmake from CMake |
|
2 #============================================================================= |
|
3 # Copyright 2002-2009 Kitware, Inc. |
|
4 # |
|
5 # Distributed under the OSI-approved BSD License |
|
6 # |
|
7 # This software is distributed WITHOUT ANY WARRANTY; without even the |
|
8 # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
9 # See the License for more information. |
|
10 #============================================================================= |
|
11 |
|
12 macro(CHECK_HASKELL_MODULE_EXISTS MODULE FUNCTION PARAMCOUNT LIBRARY) |
|
13 set(VARIABLE "HS_MODULE_${LIBRARY}_${FUNCTION}") |
|
14 if(${VARIABLE} MATCHES ^${VARIABLE}$) |
|
15 message(STATUS "Looking for ${FUNCTION} in ${MODULE}") |
|
16 |
|
17 set(PARAMETERS "") |
|
18 |
|
19 if(PARAMCOUNT GREATER 0) |
|
20 foreach(__TRASH__ RANGE 1 ${PARAMCOUNT}) |
|
21 set(PARAMETERS "${PARAMETERS} undefined") |
|
22 endforeach() |
|
23 endif() |
|
24 |
|
25 #set(PARAMETERS "") |
|
26 |
|
27 execute_process(COMMAND ${GHC_EXECUTABLE} |
|
28 "-DMODULE=${MODULE}" |
|
29 "-DFUNCTION=${FUNCTION}" |
|
30 "-DPARAMETERS=${PARAMETERS}" |
|
31 -hide-all-packages |
|
32 -package ${LIBRARY} |
|
33 -package base |
|
34 -cpp |
|
35 -c "${CMAKE_MODULE_PATH}/checkModule.hs" |
|
36 RESULT_VARIABLE COMMAND_RESULT |
|
37 ERROR_VARIABLE BUILD_ERROR |
|
38 OUTPUT_STRIP_TRAILING_WHITESPACE |
|
39 ) |
|
40 if(${COMMAND_RESULT} EQUAL 0) |
|
41 message(STATUS "Looking for ${FUNCTION} in ${MODULE} - found") |
|
42 set(${VARIABLE} 1 CACHE INTERNAL "Have module ${MODULE}") |
|
43 file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log |
|
44 "Determining if the function ${FUNCTION} exists in the ${MODULE} passed\n\n") |
|
45 else() |
|
46 message(STATUS "Looking for ${FUNCTION} in ${MODULE} - not found") |
|
47 set(${VARIABLE} "" CACHE INTERNAL "Have module ${MODULE}") |
|
48 file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log |
|
49 "Determining if the function ${FUNCTION} exists in the ${MODULE} " |
|
50 "failed with the following output:\n" |
|
51 "${BUILD_ERROR}\n\n") |
|
52 message(FATAL_ERROR "Haskell library '${LIBRARY}' required") |
|
53 endif() |
|
54 endif() |
|
55 endmacro() |
|