FindAlienWx.cmake 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. # Find the wxWidgets module based on the information provided by the Perl Alien::wxWidgets module.
  2. # Check for the Perl & PerlLib modules
  3. include(LibFindMacros)
  4. libfind_package(AlienWx Perl)
  5. libfind_package(AlienWx PerlLibs)
  6. if (AlienWx_DEBUG)
  7. message(STATUS " AlienWx_FIND_COMPONENTS=${AlienWx_FIND_COMPONENTS}")
  8. endif()
  9. # Execute an Alien::Wx module to find the relevant information regarding
  10. # the wxWidgets used by the Perl interpreter.
  11. # Perl specific stuff
  12. set(AlienWx_TEMP_INCLUDE ${CMAKE_CURRENT_BINARY_DIR}/AlienWx_TEMP_INCLUDE.txt)
  13. execute_process(
  14. COMMAND ${PERL_EXECUTABLE} -e "
  15. # Import Perl modules.
  16. use strict;
  17. use warnings;
  18. use Text::ParseWords;
  19. BEGIN {
  20. # CMake sets the environment variables CC and CXX to the detected C compiler.
  21. # There is an issue with the Perl ExtUtils::CBuilder, which does not handle whitespaces
  22. # in the paths correctly on Windows, so we rather drop the CMake auto-detected paths.
  23. delete \$ENV{CC};
  24. delete \$ENV{CXX};
  25. }
  26. use Alien::wxWidgets;
  27. use ExtUtils::CppGuess;
  28. # Test for a Visual Studio compiler
  29. my \$cpp_guess = ExtUtils::CppGuess->new;
  30. my \$mswin = \$^O eq 'MSWin32';
  31. my \$msvc = \$cpp_guess->is_msvc;
  32. # List of wxWidgets components to be used.
  33. my @components = split /;/, '${AlienWx_FIND_COMPONENTS}';
  34. # Query the available data from Alien::wxWidgets.
  35. my \$version = Alien::wxWidgets->version;
  36. my \$config = Alien::wxWidgets->config;
  37. my \$compiler = Alien::wxWidgets->compiler;
  38. my \$linker = Alien::wxWidgets->linker;
  39. my \$include_path = ' ' . Alien::wxWidgets->include_path;
  40. my \$defines = ' ' . Alien::wxWidgets->defines;
  41. my \$cflags = Alien::wxWidgets->c_flags;
  42. my \$linkflags = Alien::wxWidgets->link_flags;
  43. my \$libraries = ' ' . Alien::wxWidgets->libraries(@components);
  44. my \$gui_toolkit = Alien::wxWidgets->config->{toolkit};
  45. #my @libraries = Alien::wxWidgets->link_libraries(@components);
  46. #my @implib = Alien::wxWidgets->import_libraries(@components);
  47. #my @shrlib = Alien::wxWidgets->shared_libraries(@components);
  48. #my @keys = Alien::wxWidgets->library_keys; # 'gl', 'adv', ...
  49. #my \$library_path = Alien::wxWidgets->shared_library_path;
  50. #my \$key = Alien::wxWidgets->key;
  51. #my \$prefix = Alien::wxWidgets->prefix;
  52. my \$filename = '${AlienWx_TEMP_INCLUDE}';
  53. open(my $fh, '>', \$filename) or die \"Could not open file '\$filename' \$!\";
  54. # Convert a space separated lists to CMake semicolon separated lists,
  55. # escape the backslashes,
  56. # export the resulting list to a temp file.
  57. sub cmake_set_var {
  58. my (\$varname, \$content) = @_;
  59. # Remove line separators.
  60. \$content =~ s/\\r|\\n//g;
  61. # Escape the path separators.
  62. \$content =~ s/\\\\/\\\\\\\\\\\\\\\\/g;
  63. my @words = shellwords(\$content);
  64. print \$fh \"set(AlienWx_\$varname \\\"\" . join(';', @words) . \"\\\")\\n\";
  65. }
  66. cmake_set_var('VERSION', \$version);
  67. \$include_path =~ s/ -I/ /g;
  68. cmake_set_var('INCLUDE_DIRS', \$include_path);
  69. \$libraries =~ s/ -L/ -LIBPATH:/g if \$msvc;
  70. cmake_set_var('LIBRARIES', \$libraries);
  71. #cmake_set_var('LIBRARY_DIRS', );
  72. #\$defines =~ s/ -D/ /g;
  73. cmake_set_var('DEFINITIONS', \$defines);
  74. #cmake_set_var('DEFINITIONS_DEBUG', );
  75. cmake_set_var('CXX_FLAGS', \$cflags);
  76. cmake_set_var('GUI_TOOLKIT', \$gui_toolkit);
  77. close \$fh;
  78. ")
  79. include(${AlienWx_TEMP_INCLUDE})
  80. file(REMOVE ${AlienWx_TEMP_INCLUDE})
  81. unset(AlienWx_TEMP_INCLUDE)
  82. if (AlienWx_DEBUG)
  83. message(STATUS " AlienWx_VERSION = ${AlienWx_VERSION}")
  84. message(STATUS " AlienWx_INCLUDE_DIRS = ${AlienWx_INCLUDE_DIRS}")
  85. message(STATUS " AlienWx_LIBRARIES = ${AlienWx_LIBRARIES}")
  86. message(STATUS " AlienWx_LIBRARY_DIRS = ${AlienWx_LIBRARY_DIRS}")
  87. message(STATUS " AlienWx_DEFINITIONS = ${AlienWx_DEFINITIONS}")
  88. message(STATUS " AlienWx_DEFINITIONS_DEBUG = ${AlienWx_DEFINITIONS_DEBUG}")
  89. message(STATUS " AlienWx_CXX_FLAGS = ${AlienWx_CXX_FLAGS}")
  90. message(STATUS " AlienWx_GUI_TOOLKIT = ${AlienWx_GUI_TOOLKIT}")
  91. endif()
  92. include(FindPackageHandleStandardArgs)
  93. find_package_handle_standard_args(AlienWx
  94. REQUIRED_VARS AlienWx_INCLUDE_DIRS AlienWx_LIBRARIES
  95. # HANDLE_COMPONENTS
  96. VERSION_VAR AlienWx_VERSION)