[CMake] Windows: install conditionnaly an executable

ycollette.nospam at free.fr ycollette.nospam at free.fr
Mon Sep 19 09:29:04 EDT 2011


Hello,

I would like to do this kind of installation:

My package contains several executable with a version number by application

- first install: install all the application and write a version number into the windows registry

- update install: install only the application which have a greater version number.

I tryied the following example:

project (Test)

cmake_minimum_required (VERSION 2.6)

set(TEST_MAJOR 1)
set(TEST_MINOR 1)
set(TEST_REVISION 1)

get_filename_component(REG_TEST_MAJOR [HKEY_LOCAL_MACHINE\\Software\\Arpack\\Test;Major] NAME)
get_filename_component(REG_TEST_MINOR [HKEY_LOCAL_MACHINE\\Software\\Arpack\\Test;Minor] NAME)
get_filename_component(REG_TEST_REVISION [HKEY_LOCAL_MACHINE\\Software\\Arpack\\Test;Revision] NAME)

message(STATUS "TEST_MAJOR    = in registry - ${REG_TEST_MAJOR} - in cmake - ${TEST_MAJOR}")
message(STATUS "TEST_MINOR    = in registry - ${REG_TEST_MINOR} - in cmake - ${TEST_MINOR}")
message(STATUS "TEST_REVISION = in registry - ${REG_TEST_REVISION} - in cmake - ${TEST_REVISION}")

set(REG_VERSION "${REG_MAJOR}.${REG_MINOR}.${REG_REVISION}")
set(VERSION "${MAJOR}.${MINOR}.${REVISION}")

if ((${REG_VERSION} VERSION_LESS ${VERSION}) OR (${REG_TEST_MAJOR} STREQUAL "/registry"))
  message(STATUS "Test Not installed")
  
  install(FILES machine.h
          DESTINATION include/)

  set(CPACK_NSIS_EXTRA_INSTALL_COMMANDS "
                                         WriteRegStr HKLM 'SOFTWARE\\\\Arpack\\\\Test' 'Major' '${TEST_MAJOR}'
                                         WriteRegStr HKLM 'SOFTWARE\\\\Arpack\\\\Test' 'Minor' '${TEST_MINOR}'
                                         WriteRegStr HKLM 'SOFTWARE\\\\Arpack\\\\Test' 'Revision' '${TEST_REVISION}'")

else ()
  message(STATUS "Test Already installed")
endif ()

include(CPack)




But it works only once (the version number are red only while the package is created by cpack).

How can I read with cmake the registry key "dynamically" in the installer and use this version number to install conditionnaly some applications ?

Best regards,

YC


More information about the CMake mailing list