summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2010-10-05 21:10:40 +0200
committerMatthias Schiffer <mschiffer@universe-factory.net>2010-10-05 21:10:40 +0200
commitecc44209d33f59c7c653b1527253a5cfd7227cec (patch)
tree9e233042ba042713d5e558ea2e85d9becf3fd838
parentb54ff0ce652de2864d8ffd863aada8cebbbc621b (diff)
downloadcmake-erlang-ecc44209d33f59c7c653b1527253a5cfd7227cec.tar
cmake-erlang-ecc44209d33f59c7c653b1527253a5cfd7227cec.zip
Implemented erl_check_library
-rw-r--r--ErlangTarget.cmake2
-rw-r--r--FindErlang.cmake61
2 files changed, 61 insertions, 2 deletions
diff --git a/ErlangTarget.cmake b/ErlangTarget.cmake
index 2afbc7a..de5fd92 100644
--- a/ErlangTarget.cmake
+++ b/ErlangTarget.cmake
@@ -1,3 +1,5 @@
+find_package(Erlang REQUIRED)
+
macro(erl_target name)
parse_arguments(ARGS "HEADERS;OPTIONS" "" ${ARGN})
diff --git a/FindErlang.cmake b/FindErlang.cmake
index e7cb60f..6b4d8d8 100644
--- a/FindErlang.cmake
+++ b/FindErlang.cmake
@@ -1,6 +1,63 @@
+find_program(ERL_EXECUTABLE NAMES erl)
find_program(ERLC_EXECUTABLE NAMES erlc)
-
include(FindPackageHandleStandardArgs)
-find_package_handle_standard_args(Erlang DEFAULT_MSG ERLC_EXECUTABLE)
+find_package_handle_standard_args(Erlang DEFAULT_MSG ERL_EXECUTABLE ERLC_EXECUTABLE)
+mark_as_advanced(ERL_EXECUTABLE)
mark_as_advanced(ERLC_EXECUTABLE)
+if(ERLANG_FOUND)
+ execute_process(COMMAND ${ERL_EXECUTABLE} "-noinput" "-eval" "io:format(\"~s\", [code:root_dir()])" "-eval" "halt()"
+ OUTPUT_VARIABLE "ERLANG_ROOT_DIR")
+ execute_process(COMMAND ${ERL_EXECUTABLE} "-noinput" "-eval" "io:format(\"~s\", [code:lib_dir()])" "-eval" "halt()"
+ OUTPUT_VARIABLE "ERLANG_LIB_DIR")
+endif(ERLANG_FOUND)
+
+
+macro(erl_check_library name)
+ find_package(Erlang REQUIRED)
+
+ if(NOT ${name}_FOUND)
+
+ foreach(arg ${ARGN})
+ if (arg STREQUAL "REQUIRED")
+ set(required 1)
+ elseif (arg STREQUAL "QUIET")
+ set(quiet 1)
+ endif (arg STREQUAL "REQUIRED")
+ endforeach(arg ${ARGN})
+
+ set(pkgs ${ARGN})
+ list(REMOVE_ITEM pkgs "REQUIRED")
+ list(REMOVE_ITEM pkgs "QUIET")
+
+ list(GET pkgs 0 lib)
+
+ if(NOT quiet)
+ message("-- checking for Erlang library '${lib}'")
+ endif(NOT quiet)
+
+ execute_process(COMMAND ${ERL_EXECUTABLE} "-noinput"
+ "-eval" "Dir=code:lib_dir('${lib}'), if is_list(Dir) -> io:format(\"~s\", [Dir]); true -> ok end"
+ "-eval" "halt()" OUTPUT_VARIABLE "${name}_dir")
+
+ if(NOT quiet)
+ if(NOT ${name}_DIR STREQUAL "")
+ message("-- found ${lib}")
+ else(NOT ${name}_DIR STREQUAL "")
+ message("-- library '${lib}' not found")
+ endif(NOT ${name}_DIR STREQUAL "")
+ endif(NOT quiet)
+
+ if(${name}_DIR STREQUAL "")
+ if(required)
+ message(SEND_ERROR "A required library was not found")
+ endif(required)
+ else(${name}_DIR STREQUAL "")
+ set(${name}_FOUND 1 CACHE INTERNAL "")
+ set(${name}_DIR "${${name}_dir}" CACHE INTERNAL "")
+ set(${name}_INCLUDE_DIR "${${name}_dir}/include" CACHE INTERNAL "")
+ set(${name}_LIBRARY_DIR "${${name}_dir}/lib" CACHE INTERNAL "")
+ endif(${name}_DIR STREQUAL "")
+
+ endif(NOT ${name}_FOUND)
+endmacro(erl_check_library) \ No newline at end of file