Le mer. 5 juin 2019 à 12:00, Mathieu Malaterre <mathieu.malate...@gmail.com>
a écrit :

> Hi there,
>
> I am trying to use NuGet generator for GDCM project. Typically my
> install rules are as follow:
>
> add_library(foo SHARED foo.c)
> install(TARGETS foo
>   EXPORT ${MY_TARGETS_NAME}
>   RUNTIME DESTINATION ${MY_INSTALL_BIN_DIR} COMPONENT Applications
>   LIBRARY DESTINATION ${MY_INSTALL_LIB_DIR} COMPONENT Libraries
>   INCLUDES DESTINATION ${MY_INSTALL_INCLUDE_DIR}
>   ARCHIVE DESTINATION ${MY_INSTALL_LIB_DIR} COMPONENT DebugDevel
> )
>
> where:
>
> MY_INSTALL_BIN_DIR='bin'
> MY_INSTALL_LIB_DIR='lib'
> MY_INSTALL_INCLUDE_DIR='include'
>
> this works quite nicely for basic 'make install', as well as binary
> zip or NSIS installer.
> However this directory layout does not seems to be compatible with
> Windows RIDs[*]. For example my native *.dll files would need to be
> moved from the 'bin' directory to something like 'lib/win7-x64'.
>
> How can I handle conditional install() rules based on CPack generator
> (NuGet in my case) ?
>

I'm not sure you can.
install() rules are processed when CMake runs and generate all
cmake_install.cmake files.
then when CPack runs it triggers the install using the files generated at
CMake time.

So while you can achieve some conditional actions when CPack runs using
CPack project config file
https://cmake.org/cmake/help/v3.14/module/CPack.html#variable:CPACK_PROJECT_CONFIG_FILE

AFAIK you cannot (re)write install rule because they have already been
processed.

What you could do (as a workaround) in your CMakeLists.txt is to define
both WinXX specific CPack components
and your "generic" CPack components that can be used as a default.
install(TARGETS foo
  EXPORT ${MY_TARGETS_NAME}
  RUNTIME DESTINATION ${MY_INSTALL_BIN_DIR} COMPONENT Applications
  LIBRARY DESTINATION ${MY_INSTALL_LIB_DIR} COMPONENT Libraries
  INCLUDES DESTINATION ${MY_INSTALL_INCLUDE_DIR}
  ARCHIVE DESTINATION ${MY_INSTALL_LIB_DIR} COMPONENT DebugDevel
)
install(TARGETS foo
  EXPORT ${MY_TARGETS_NAME}
  RUNTIME DESTINATION ${MY_WINXX_INSTALL_BIN_DIR} COMPONENT
Applications-Winxx
  LIBRARY DESTINATION ${MY_WINXX_INSTALL_LIB_DIR} COMPONENT Libraries-Winxx
  INCLUDES DESTINATION ${MY_WINXX_INSTALL_INCLUDE_DIR}
  ARCHIVE DESTINATION ${MY_WINXX_INSTALL_LIB_DIR} COMPONENT DebugDevel-Winxx
)

i.e. install the same thing twice in two places.
and then at CPack time (when CPack runs) code some logic in your CPack
Config file in order
to set  CPACK_COMPONENTS_ALL to appropriate value depending on the value of
https://cmake.org/cmake/help/v3.14/module/CPack.html#variable:CPACK_GENERATOR

something like
if ("${CPACK_GENERATOR}" STREQUAL "NuGet")
   set(CPACK_COMPONENTS_ALL
"Applications-Winxx;Libraries-Winxx;DebugDevel-Winxx")
else()
    set(CPACK_COMPONENTS_ALL "Applications;Libraries;DebugDevel")
endif()

that way CPack depending on the generator will ship either "WinXX"
component or "generic" ones.

I think (not tested) it should work but this is clearly a workaround.


Eric



> Thanks,
>
> [*] https://docs.microsoft.com/en-us/dotnet/core/rid-catalog
>
> --
> Mathieu
> --
>
> Powered by www.kitware.com
>
> Please keep messages on-topic and check the CMake FAQ at:
> http://www.cmake.org/Wiki/CMake_FAQ
>
> Kitware offers various services to support the CMake community. For more
> information on each offering, please visit:
>
> CMake Support: http://cmake.org/cmake/help/support.html
> CMake Consulting: http://cmake.org/cmake/help/consulting.html
> CMake Training Courses: http://cmake.org/cmake/help/training.html
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Follow this link to subscribe/unsubscribe:
> https://cmake.org/mailman/listinfo/cmake
>


-- 
Eric
-- 

Powered by www.kitware.com

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

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

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

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake

Reply via email to