[cmake-developers] CPack: GetPrerequisites: cross-compiling from Linux to Windows

2012-03-06 Thread Dominik Schmidt
Hey,


I worked on a patch for supporting dep-tracking with GetPrequesites when
cross-compiling for Windows with MinGW.

While doing this I noticed neither WIN32 nor CMAKE_CROSSCOMPILING are
defined at CPack time, why?
This is the reason my code in the patch is not in the WIN32 block above and
I couldn't guess the gp_tool correctly.

A hardcoded list of .dll names is for sure not really elegant, but I don't
know of any way to check if a required .dll is a windows system library. On
Linux of course there are no Windows system dlls in a certain folder and
the absence of such a dll doesn't mean anything either because an import
lib (.dll.a usually) is enough to link against.

The patch is probably not ready to be upstreamed but I'm happy to fix
issues or follow a nicer approach if you point me to it.

Best regards,
Dominik
diff --git a/Modules/GetPrerequisites.cmake b/Modules/GetPrerequisites.cmake
index 8761f40..304a0d6 100644
--- a/Modules/GetPrerequisites.cmake
+++ b/Modules/GetPrerequisites.cmake
@@ -476,6 +476,56 @@ function(gp_resolved_file_type original_file file exepath dirs type_var)
   endif(UNIX)
 endif(WIN32)
 
+set(windows_system_libraries
+advapi32.dll
+cfgmgr32.dll
+comctl32.dll
+comdlg32.dll
+crypt32.dll
+ddraw.dll
+dnsapi.dll
+dsound.dll
+gdi32.dll
+gdiplus.dll
+glu32.dll
+glut32.dll
+imm32.dll
+iphlpapi.dll
+kernel32.dll
+mscms.dll
+mscoree.dll
+msimg32.dll
+msvcr71.dll
+msvcr80.dll
+msvcr90.dll
+msvcrt.dll
+mswsock.dll
+ole32.dll
+oleaut32.dll
+opengl32.dll
+psapi.dll
+rpcrt4.dll
+secur32.dll
+setupapi.dll
+shell32.dll
+shlwapi.dll
+user32.dll
+usp10.dll
+version.dll
+wininet.dll
+winmm.dll
+wldap32.dll
+ws2_32.dll
+wsock32.dll
+)
+
+string(TOLOWER ${file} file_lower)
+foreach(windows_system_library ${windows_system_libraries})
+if( ${file_lower} STREQUAL ${windows_system_library})
+set(is_system 1)
+endif()
+endforeach()
+
 if(NOT is_system)
   get_filename_component(original_path ${original_lower} PATH)
   get_filename_component(path ${lower} PATH)
@@ -573,6 +623,7 @@ function(get_prerequisites target prerequisites_var exclude_system recurse exepa
 endif(WIN32 AND NOT UNIX)
   endif(${gp_tool} STREQUAL )
 
+  set(gp_tool objdump)
   set(gp_tool_known 0)
 
   if(${gp_tool} STREQUAL ldd)
@@ -603,6 +654,15 @@ function(get_prerequisites target prerequisites_var exclude_system recurse exepa
 set(ENV{VS_UNICODE_OUTPUT} ) # Block extra output from inside VS IDE.
   endif(${gp_tool} STREQUAL dumpbin)
 
+  if(${gp_tool} STREQUAL objdump)
+set(gp_cmd_args -p)
+set(gp_regex .*DLL Name: ([^ ]*[Dd][Ll][Ll])${eol_char}$)
+set(gp_regex_error )
+set(gp_regex_fallback )
+set(gp_regex_cmp_count 0)
+set(gp_tool_known 1)
+  endif()
+
   if(NOT gp_tool_known)
 message(STATUS warning: gp_tool='${gp_tool}' is an unknown tool...)
 message(STATUS CMake function get_prerequisites needs more code to handle '${gp_tool}')
--

Powered by www.kitware.com

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/cgi-bin/mailman/listinfo/cmake-developers

Re: [cmake-developers] CPack: GetPrerequisites: cross-compiling from Linux to Windows

2012-03-06 Thread Dominik Schmidt
Hey Eric,

thanks for the quick reply!

On Tue, Mar 6, 2012 at 1:16 PM, Eric Noulard eric.noul...@gmail.com wrote:

  While doing this I noticed neither WIN32 nor CMAKE_CROSSCOMPILING are
  defined at CPack time, why?


 May be because no one did really tackle the cross-packaging problem?
 Cross-compiling is one thing, cross packaging is another one
 (which may be difficult or impossible in the general case).


Ah okay :-)


  This is the reason my code in the patch is not in the WIN32 block above
 and
  I couldn't guess the gp_tool correctly.

 In order to be sure that nothing else is breaking you can try to
 [manually] add the missing definition in the CPackConfig.cmake file.
 This file is loaded by CPack at CPack-time so that any definitions in there
 will be seen during CPack run.


Went fine.

An alternative would be to do it in a CPack Project Config file:

 http://www.cmake.org/Wiki/CMake:CPackPackageGenerators#Overall_usage_.28common_to_all_generators.29


Might make sense, indeed. That way you could explicitly say if you want to
cross-package or not.

By the way how does GetPrerequisite get called ? Is it does through
 BundleUtilities?
 I'm not using those so, are they called at [CPack-]install time ?


Yes. I'm using DeployQt4, which uses BundleUtilities, which use
GetPrerequisites.


  A hardcoded list of .dll names is for sure not really elegant, but I
 don't
  know of any way to check if a required .dll is a windows system library.
 On
  Linux of course there are no Windows system dlls in a certain folder and
 the
  absence of such a dll doesn't mean anything either because an import lib
  (.dll.a usually) is enough to link against.
 
  The patch is probably not ready to be upstreamed but I'm happy to fix
 issues
  or follow a nicer approach if you point me to it.

 Before going on may be you could explain us what kind of
 cross-packaging your are targeting:
 NSIS, Archive generator, etc...


NSIS is the one I'm aiming for :-)


 Setting WIN32 and/or CMAKE_CROSSCOMPILING may be done in CPack list
 interpreter
 but it remains to be seen whether it would be enough in order to
 achieve what you want.


I think so, it already works when gp_tool is manually set to objdump!

--
 Erk
 Le gouvernement représentatif n'est pas la démocratie --
 http://www.le-message.org


Best regards,
Dominik
--

Powered by www.kitware.com

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/cgi-bin/mailman/listinfo/cmake-developers

Re: [cmake-developers] CPack: GetPrerequisites: cross-compiling from Linux to Windows

2012-03-06 Thread Eric Noulard
2012/3/6 Dominik Schmidt do...@tomahawk-player.org:
 Hey Eric,

 thanks for the quick reply!

You are welcome.

  This is the reason my code in the patch is not in the WIN32 block above
  and
  I couldn't guess the gp_tool correctly.

 In order to be sure that nothing else is breaking you can try to
 [manually] add the missing definition in the CPackConfig.cmake file.
 This file is loaded by CPack at CPack-time so that any definitions in
 there
 will be seen during CPack run.

 Went fine.

 An alternative would be to do it in a CPack Project Config file:

 http://www.cmake.org/Wiki/CMake:CPackPackageGenerators#Overall_usage_.28common_to_all_generators.29

 Might make sense, indeed. That way you could explicitly say if you want to
 cross-package or not.

It is even necessary for more than just testing because the
CPackConfig.cmake file may be
overwritten by CPack next time you change your CMakeLists.txt.

CPackConfig.cmake is generated by the
include(CPack)
in your CMakeLists.txt.

Ultimately it may be useful to configure_file your
CPackProjectConfig.cmake.[in]
and put some generated logic in it depending on any CMake variable.

  The patch is probably not ready to be upstreamed but I'm happy to fix
  issues
  or follow a nicer approach if you point me to it.

 Before going on may be you could explain us what kind of
 cross-packaging your are targeting:
 NSIS, Archive generator, etc...

 NSIS is the one I'm aiming for :-)

Ok.

 Setting WIN32 and/or CMAKE_CROSSCOMPILING may be done in CPack list
 interpreter
 but it remains to be seen whether it would be enough in order to
 achieve what you want.


 I think so, it already works when gp_tool is manually set to objdump!

If you manage to do that kind of cross-packaging it could be worth a
page on the Wiki.

-- 
Erk
Le gouvernement représentatif n'est pas la démocratie --
http://www.le-message.org
--

Powered by www.kitware.com

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/cgi-bin/mailman/listinfo/cmake-developers