[waffle] [PATCH 3/4] cmake: Add the installed package files to the registry on windows

Jose Fonseca jfonseca at vmware.com
Mon Dec 29 03:35:20 PST 2014


On 22/12/14 22:36, Dylan Baker wrote:
> This adds the locations of the package files to the registry on windows,
> which should allow them to be auto detected by cmake on windows when
> linking against waffle in other projects.
>
> Signed-off-by: Dylan Baker <dylanx.c.baker at intel.com>
> ---
>
> This patch is completely untested (I don't have access to a windows
> development machine, nor do I want to maintain one), I've sent this as a
> courtesy to windows users, and hopefully it can point an interested part
> in the correct direction.
>
> Note that this installs into the local machine registry, and there is
> also the option of using local user registry instead, and that can be
> done by changing waffle to use export(), though I'm not exactly sure how
> that works either
>
>   CMakeLists.txt | 10 ++++++++++
>   1 file changed, 10 insertions(+)
>
> diff --git a/CMakeLists.txt b/CMakeLists.txt
> index 729ebc1..0ac2d4b 100644
> --- a/CMakeLists.txt
> +++ b/CMakeLists.txt
> @@ -182,6 +182,16 @@ install(
>       COMPONENT Devel
>   )
>
> +# If running on windows add waffle to the registry so it can be auto detected
> +# by consuming projects
> +if (WIN32)

This will break cross-compiling from Linux to Windows (via MinGW), 
because "WIN32" is true.

Replacing it with

   if (WIN32 AND NOT CMAKE_CROSSCOMPILING)

should do the trick.


> +    execute_process(
> +        COMMAND "REG ADD HKEY_LOCAL_MACHINE\Software\Kitware\CMake\Packages\Waffle /v Waffle-1 /t REG_SZ /d ${ConfigPackageLocation} /f"

I suspect this will fail when there are spaces in the path (e.g., when 
waffle is in "C:\Program Files\..."


> +        ERROR_QUIET
> +        OUTPUT_QUIET
> +    )
> +endif ()

Also I believe execute_process() will execute the command when 
configuring -- not when building --, or even better, not when installing.




I'm not sure this is a great idea overall.  Are any other packages doing 
anything like this?  It all seems very non-standard, so I wonder if this 
will really simplify things or be too surprising.


FWIW, IMO the best way of finding things with CMake on Windows is using 
the `-C` cmake option.

For example, this is part of my MSVC Cmake cache:

$ cat msvc32/Cache.cmake
set (CMAKE_ASM_MASM_COMPILER "${CMAKE_CURRENT_LIST_DIR}/masm/ml.exe" 
CACHE FILEPATH "" FORCE)

set (GLEXT_INCLUDE_DIR "H:/noarch/glext" CACHE PATH "" FORCE)

set (GLEW_INCLUDE_DIR "${CMAKE_CURRENT_LIST_DIR}/glew/include" CACHE 
PATH "" FORCE)
set (GLEW_glew_LIBRARY "${CMAKE_CURRENT_LIST_DIR}/glew/lib/glew32.lib" 
CACHE FILEPATH "" FORCE)

set (GLFW_INCLUDE_DIR "${CMAKE_CURRENT_LIST_DIR}/glfw/include" CACHE 
PATH "" FORCE)
set (GLFW_LIBRARY "${CMAKE_CURRENT_LIST_DIR}/glfw/lib/glfw32.lib" CACHE 
FILEPATH "" FORCE)

set (GLUT_INCLUDE_DIR "H:/msvc32/freeglut/include" CACHE PATH "" FORCE)
set (GLUT_glut_LIBRARY "H:/msvc32/freeglut/lib/freeglut.lib" CACHE 
FILEPATH "" FORCE)

set (PNG_PNG_INCLUDE_DIR "${CMAKE_CURRENT_LIST_DIR}/libpng/include" 
CACHE PATH "" FORCE)
set (PNG_LIBRARY "${CMAKE_CURRENT_LIST_DIR}/libpng/lib/libpng.lib" CACHE 
FILEPATH "" FORCE)

set (ZLIB_INCLUDE_DIR "${CMAKE_CURRENT_LIST_DIR}/zlib/include" CACHE 
PATH "" FORCE)
set (ZLIB_LIBRARY "${CMAKE_CURRENT_LIST_DIR}/zlib/lib/zlib.lib" CACHE 
FILEPATH "" FORCE)

[...]


So all I need to do when building any Cmake project is to pass -C 
/path/to/Cache.cmake and it will find everything I need.  All this is in 
a network share so it can be used both from my Windows development 
machines and build slaves.


Of course, this only works if the cmake project is not too smart for its 
own good.


Jose


More information about the waffle mailing list