Permalink
Browse files

haskell-bindings-check-dependencies: refactor dependency checking in …

…FindHaskell cmake module
  • Loading branch information...
e1528532 committed Oct 30, 2017
1 parent f72ad5c commit b15d3d94161ca3772c4419faee6c476f721c2762
Showing with 103 additions and 74 deletions.
  1. +89 −0 cmake/Modules/FindHaskell.cmake
  2. +9 −23 cmake/Modules/LibAddHaskellPlugin.cmake
  3. +5 −51 src/bindings/haskell/CMakeLists.txt
@@ -0,0 +1,89 @@
# Find the haskell environment required for the haskell bindings and plugins.
# Only searches for the GHC compiler and not other haskell compilers as it is
# the most widespread and advanced haskell compiler.
#
# CABAL_EXECUTABLE - Path to the cabal executable
# C2HS_EXECUTABLE - Path to the c2hs executable
# GHC_EXECUTABLE - Path to the ghc executable
# GHC-PKG_EXECUTABLE - Path to the ghc-pkg executable
# GHC_HSPEC_FOUND - True if the hspec library is available
# GHC_QUICKCHECK_FOUND - True if the QuickCheck library is available
# HASKELL_FOUND - True if the whole required haskell environment exists
# This variable is set to true if CABAL_EXECUTABLE, C2HS_EXECUTABLE, GHC_EXECUTABLE
# and GHC-PKG_EXECUTABLE are all available. If BUILD_TESTING is enabled, it also
# requires GHC_HSPEC_FOUND and GHC_QUICKCHECK_FOUND to be true.
# HASKELL_NOTFOUND_INFO - A string describing which haskell dependency is missing
#
find_program (GHC_EXECUTABLE ghc)
find_program (CABAL_EXECUTABLE cabal)
find_program (C2HS_EXECUTABLE c2hs)
find_program (GHC-PKG_EXECUTABLE ghc-pkg)
set (HASKELL_FOUND 0)
if (CABAL_EXECUTABLE)
if (C2HS_EXECUTABLE)
if (GHC_EXECUTABLE)
if (GHC-PKG_EXECUTABLE)
# check for hspec and QuickCheck
# ghc-pkg return code is 0 on success, 1 otherwise
execute_process (
COMMAND ${GHC-PKG_EXECUTABLE} latest hspec
RESULT_VARIABLE GHC_HSPEC_FOUND
OUTPUT_QUIET ERROR_QUIET
)
execute_process (
COMMAND ${GHC-PKG_EXECUTABLE} latest QuickCheck
RESULT_VARIABLE GHC_QUICKCHECK_FOUND
OUTPUT_QUIET ERROR_QUIET
)
# normalize the result variables, 0 means success which corresponds to 1 in cmake booleans
if (GHC_HSPEC_FOUND EQUAL 0)
set (GHC_HSPEC_FOUND 1)
else (GHC_HSPEC_FOUND EQUAL 0)
set (GHC_HSPEC_FOUND 0)
endif (GHC_HSPEC_FOUND EQUAL 0)
if (GHC_QUICKCHECK_FOUND EQUAL 0)
set (GHC_QUICKCHECK_FOUND 1)
else (GHC_QUICKCHECK_FOUND EQUAL 0)
set (GHC_QUICKCHECK_FOUND 0)
endif (GHC_QUICKCHECK_FOUND EQUAL 0)
if (GHC_HSPEC_FOUND OR NOT BUILD_TESTING)
if (GHC_QUICKCHECK_FOUND OR NOT BUILD_TESTING)
# all set, have fun with haskell!
set (HASKELL_FOUND 1)
else (GHC_QUICKCHECK_FOUND OR NOT BUILD_TESTING)
set (HASKELL_NOTFOUND_INFO "QuickCheck library not found")
endif (GHC_QUICKCHECK_FOUND OR NOT BUILD_TESTING)
else (GHC_HSPEC_FOUND OR NOT BUILD_TESTING)
set (HASKELL_NOTFOUND_INFO "hspec library not found")
endif (GHC_HSPEC_FOUND OR NOT BUILD_TESTING)
else (GHC-PKG_EXECUTABLE)
set (HASKELL_NOTFOUND_INFO "ghc-pkg not found")
endif (GHC-PKG_EXECUTABLE)
else (GHC_EXECUTABLE)
set (HASKELL_NOTFOUND_INFO "GHC not found")
endif (GHC_EXECUTABLE)
else (C2HS_EXECUTABLE)
set (HASKELL_NOTFOUND_INFO "c2hs not found")
endif (C2HS_EXECUTABLE)
else (CABAL_EXECUTABLE)
set (HASKELL_NOTFOUND_INFO "cabal not found")
endif (CABAL_EXECUTABLE)
set (HASKELL_NOTFOUND_INFO "${HASKELL_NOTFOUND_INFO}, please refer to the readme in src/bindings/haskell/README.md")
mark_as_advanced (
GHC_EXECUTABLE
GHC-PKG_EXECUTABLE
C2HS_EXECUTABLE
CABAL_EXECUTABLE
GHC_HSPEC_FOUND
GHC_QUICKCHECK_FOUND
)
@@ -25,14 +25,10 @@ macro (add_haskell_plugin target)
string (TOUPPER ${PLUGIN_NAME} PLUGIN_NAME_UPPERCASE)
if (DEPENDENCY_PHASE)
find_program (GHC_EXECUTABLE ghc)
find_program (GHC-PKG_EXECUTABLE ghc-pkg)
find_program (CABAL_EXECUTABLE cabal)
find_package (Haskell)
# set by find_program
if (CABAL_EXECUTABLE)
if (GHC_EXECUTABLE)
if (GHC-PKG_EXECUTABLE)
if (HASKELL_FOUND)
list (FIND BINDINGS "haskell" FINDEX)
if (FINDEX GREATER -1)
@@ -202,16 +198,10 @@ macro (add_haskell_plugin target)
else (FINDEX GREATER -1)
remove_plugin (${target} "haskell bindings are not included in the cmake configuration")
endif (FINDEX GREATER -1)
else (GHC-PKG_EXECUTABLE)
remove_plugin (${target} "ghc-pkg not found")
endif (GHC-PKG_EXECUTABLE)
else (GHC_EXECUTABLE)
remove_plugin (${target} "GHC not found")
endif (GHC_EXECUTABLE)
else (CABAL_EXECUTABLE)
remove_plugin (${target} "cabal not found")
endif (CABAL_EXECUTABLE)
endif ()
else (HASKELL_FOUND)
remove_plugin (${target} ${HASKELL_NOTFOUND_INFO})
endif (HASKELL_FOUND)
endif (DEPENDENCY_PHASE)
# compile our c wrapper which takes care of invoking the haskell runtime
# the actual haskell plugin gets linked in dynamically as a library
@@ -227,15 +217,11 @@ macro (add_haskell_plugin target)
${target} c2hs_haskell
ADD_TEST
)
if (ADDTESTING_PHASE)
set_property (TEST testmod_haskell PROPERTY ENVIRONMENT "LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/lib")
endif (ADDTESTING_PHASE)
if (ADDTESTING_PHASE AND BUILD_TESTING)
set_property (TEST testmod_${target} PROPERTY ENVIRONMENT "LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/lib")
endif (ADDTESTING_PHASE AND BUILD_TESTING)
mark_as_advanced (
GHC_EXECUTABLE
GHC-PKG_EXECUTABLE
CABAL_EXECUTABLE
GHC_FFI_LIB
GHC_RTS_LIB
GHC_BASE_LIB
@@ -1,30 +1,8 @@
find_program (GHC_EXECUTABLE ghc)
find_program (CABAL_EXECUTABLE cabal)
find_program (C2HS_EXECUTABLE c2hs)
find_program (GHC-PKG_EXECUTABLE ghc-pkg)
find_package (Haskell)
if (CABAL_EXECUTABLE) # set by find_program
if (C2HS_EXECUTABLE)
if (GHC_EXECUTABLE)
if (GHC-PKG_EXECUTABLE)
if (HASKELL_FOUND)
if (NOT BUILD_STATIC)
# check for hspec and QuickCheck
# ghc-pkg return code is 0 on success, 1 otherwise
execute_process (
COMMAND ${GHC-PKG_EXECUTABLE} latest hspec
RESULT_VARIABLE GHC_HSPEC_FOUND
OUTPUT_QUIET ERROR_QUIET
)
if (GHC_HSPEC_FOUND EQUAL 0)
execute_process (
COMMAND ${GHC-PKG_EXECUTABLE} latest QuickCheck
RESULT_VARIABLE GHC_QUICKCHECK_FOUND
OUTPUT_QUIET ERROR_QUIET
)
if (GHC_QUICKCHECK_FOUND EQUAL 0)
set (CABAL_INCLUDE_DIRS "\"${CMAKE_SOURCE_DIR}/src/include\", \"${CMAKE_BINARY_DIR}/src/include\"")
execute_process (
@@ -147,33 +125,9 @@ if (GHC_QUICKCHECK_FOUND EQUAL 0)
set_property (TEST testhaskell_realworld_optimized PROPERTY ENVIRONMENT "LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/lib")
endif (ENABLE_KDB_TESTING)
endif (BUILD_TESTING)
else (GHC_QUICKCHECK_FOUND EQUAL 0)
remove_binding (haskell "QuickCheck library not found")
endif (GHC_QUICKCHECK_FOUND EQUAL 0)
else (GHC_HSPEC_FOUND EQUAL 0)
remove_binding (haskell "hspec library not found")
endif (GHC_HSPEC_FOUND EQUAL 0)
else (NOT BUILD_STATIC)
remove_binding (haskell "BUILD_STATIC is currently not compatible with the haskell bindings")
endif (NOT BUILD_STATIC)
else (GHC-PKG_EXECUTABLE)
remove_binding (haskell "ghc-pkg not found")
endif (GHC-PKG_EXECUTABLE)
else (GHC_EXECUTABLE)
remove_binding (haskell "GHC not found")
endif (GHC_EXECUTABLE)
else (C2HS_EXECUTABLE)
remove_binding (haskell "c2hs not found")
endif (C2HS_EXECUTABLE)
else (CABAL_EXECUTABLE)
remove_binding (haskell "cabal not found")
endif (CABAL_EXECUTABLE)
mark_as_advanced (
GHC_EXECUTABLE
GHC-PKG_EXECUTABLE
C2HS_EXECUTABLE
CABAL_EXECUTABLE
GHC_HSPEC_FOUND
GHC_QUICKCHECK_FOUND
)
else (HASKELL_FOUND)
remove_binding (haskell ${HASKELL_NOTFOUND_INFO})
endif (HASKELL_FOUND)

0 comments on commit b15d3d9

Please sign in to comment.