FindPerlEmbed.cmake 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. # Find the dependencies for linking with the Perl runtime library.
  2. # Check for the Perl & PerlLib modules
  3. include(LibFindMacros)
  4. libfind_package(PerlEmbed Perl)
  5. libfind_package(PerlEmbed PerlLibs)
  6. # Execute an Alien::Wx module to find the relevant information regarding
  7. # the wxWidgets used by the Perl interpreter.
  8. # Perl specific stuff
  9. set(PerlEmbed_TEMP_INCLUDE ${CMAKE_CURRENT_BINARY_DIR}/PerlEmbed_TEMP_INCLUDE.txt)
  10. execute_process(
  11. COMMAND ${PERL_EXECUTABLE} -MExtUtils::Embed -e "
  12. # Import Perl modules.
  13. use strict;
  14. use warnings;
  15. use Config;
  16. use Text::ParseWords;
  17. use ExtUtils::CppGuess;
  18. # Test for a Visual Studio compiler
  19. my \$cpp_guess = ExtUtils::CppGuess->new;
  20. my \$mswin = \$^O eq 'MSWin32';
  21. my \$msvc = \$cpp_guess->is_msvc;
  22. # Query the available data from Alien::wxWidgets.
  23. my \$ccflags;
  24. my \$ldflags;
  25. { local *STDOUT; open STDOUT, '>', \\\$ccflags; ccflags; }
  26. { local *STDOUT; open STDOUT, '>', \\\$ldflags; ldopts; }
  27. \$ccflags = ' ' . \$ccflags;
  28. \$ldflags = ' ' . \$ldflags;
  29. my \$filename = '${PerlEmbed_TEMP_INCLUDE}';
  30. open(my $fh, '>', \$filename) or die \"Could not open file '\$filename' \$!\";
  31. # Convert a space separated lists to CMake semicolon separated lists,
  32. # escape the backslashes,
  33. # export the resulting list to a temp file.
  34. sub cmake_set_var {
  35. my (\$varname, \$content) = @_;
  36. # Remove line separators.
  37. \$content =~ s/\\r|\\n//g;
  38. # Escape the path separators.
  39. \$content =~ s/\\\\/\\\\\\\\\\\\\\\\/g;
  40. my @words = shellwords(\$content);
  41. print \$fh \"set(PerlEmbed_\$varname \\\"\" . join(';', @words) . \"\\\")\\n\";
  42. }
  43. cmake_set_var('ARCHNAME', \$Config{archname});
  44. cmake_set_var('CCFLAGS', \$ccflags);
  45. \$ldflags =~ s/ -L/ -LIBPATH:/g if \$msvc;
  46. cmake_set_var('LD', \$Config{ld});
  47. cmake_set_var('LDFLAGS', \$ldflags);
  48. cmake_set_var('CCCDLFLAGS', \$Config{cccdlflags});
  49. cmake_set_var('LDDLFLAGS', \$Config{lddlflags});
  50. cmake_set_var('DLEXT', \$Config{dlext});
  51. close \$fh;
  52. ")
  53. include(${PerlEmbed_TEMP_INCLUDE})
  54. file(REMOVE ${PerlEmbed_TEMP_INCLUDE})
  55. unset(PerlEmbed_TEMP_INCLUDE)
  56. if (PerlEmbed_DEBUG)
  57. # First show the configuration extracted by FindPerl & FindPerlLibs:
  58. message(STATUS " PERL_INCLUDE_PATH = ${PERL_INCLUDE_PATH}")
  59. message(STATUS " PERL_LIBRARY = ${PERL_LIBRARY}")
  60. message(STATUS " PERL_EXECUTABLE = ${PERL_EXECUTABLE}")
  61. message(STATUS " PERL_SITESEARCH = ${PERL_SITESEARCH}")
  62. message(STATUS " PERL_SITELIB = ${PERL_SITELIB}")
  63. message(STATUS " PERL_VENDORARCH = ${PERL_VENDORARCH}")
  64. message(STATUS " PERL_VENDORLIB = ${PERL_VENDORLIB}")
  65. message(STATUS " PERL_ARCHLIB = ${PERL_ARCHLIB}")
  66. message(STATUS " PERL_PRIVLIB = ${PERL_PRIVLIB}")
  67. message(STATUS " PERL_EXTRA_C_FLAGS = ${PERL_EXTRA_C_FLAGS}")
  68. # Second show the configuration extracted by this module (FindPerlEmbed):
  69. message(STATUS " PerlEmbed_ARCHNAME = ${PerlEmbed_ARCHNAME}")
  70. message(STATUS " PerlEmbed_CCFLAGS = ${PerlEmbed_CCFLAGS}")
  71. message(STATUS " PerlEmbed_CCCDLFLAGS = ${PerlEmbed_CCCDLFLAGS}")
  72. message(STATUS " LD = ${PerlEmbed_LD}")
  73. message(STATUS " PerlEmbed_LDFLAGS = ${PerlEmbed_LDFLAGS}")
  74. message(STATUS " PerlEmbed_LDDLFLAGS = ${PerlEmbed_LDDLFLAGS}")
  75. endif()
  76. include(FindPackageHandleStandardArgs)
  77. find_package_handle_standard_args(PerlEmbed
  78. REQUIRED_VARS PerlEmbed_CCFLAGS PerlEmbed_LDFLAGS
  79. VERSION_VAR PERL_VERSION)