From d7594860b09562a1909dbcf8a396afca65bb0d0b Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Sun, 17 Mar 2019 11:07:07 -0400 Subject: [PATCH] CMake: fix calamares_add_library - Remove the commented-out cruft and the whinging - Fix use of COMPILE_DEFINITIONS with a list passed in - Remove unused arguments (TYPE, TARGET) - Document calamares_add_library - Document how to use COMPILE_DEFINITIONS (in calamares_add_plugin) --- CMakeModules/CalamaresAddLibrary.cmake | 50 ++++++++++++++------------ CMakeModules/CalamaresAddPlugin.cmake | 4 +++ 2 files changed, 32 insertions(+), 22 deletions(-) diff --git a/CMakeModules/CalamaresAddLibrary.cmake b/CMakeModules/CalamaresAddLibrary.cmake index f6e96d12a..d5d734989 100644 --- a/CMakeModules/CalamaresAddLibrary.cmake +++ b/CMakeModules/CalamaresAddLibrary.cmake @@ -19,27 +19,41 @@ ### # # Support functions for building plugins. - +# +# Usage: +# +# calamares_add_library( +# library-name +# EXPORT_MACRO macro-name +# TARGET_TYPE +# EXPORT export-name +# VERSION version +# SOVERSION version +# INSTALL_BINDIR dir +# RESOURCES resource-file +# SOURCES source-file... +# UI ui-file... +# LINK_LIBRARIES lib... +# LINK_PRIVATE_LIBRARIES lib... +# COMPILE_DEFINITIONS def... +# [NO_INSTALL] +# [NO_VERSION] +# ) +# +# The COMPILE_DEFINITIONS are set on the resulting module with a suitable +# flag (i.e. `-D`) so only state the name (optionally, also the value) +# without a `-D` prefixed to it. Pass in a CMake list as needed. include( CMakeParseArguments ) function(calamares_add_library) # parse arguments (name needs to be saved before passing ARGN into the macro) set(NAME ${ARGV0}) set(options NO_INSTALL NO_VERSION) - set(oneValueArgs NAME TYPE EXPORT_MACRO TARGET TARGET_TYPE EXPORT VERSION SOVERSION INSTALL_BINDIR RESOURCES) - set(multiValueArgs SOURCES UI LINK_LIBRARIES LINK_PRIVATE_LIBRARIES COMPILE_DEFINITIONS QT5_MODULES) + set(oneValueArgs NAME EXPORT_MACRO TARGET_TYPE EXPORT VERSION SOVERSION INSTALL_BINDIR RESOURCES) + set(multiValueArgs SOURCES UI LINK_LIBRARIES LINK_PRIVATE_LIBRARIES COMPILE_DEFINITIONS) cmake_parse_arguments(LIBRARY "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) set(LIBRARY_NAME ${NAME}) - -# message("*** Arguments for ${LIBRARY_NAME}") -# message("Sources: ${LIBRARY_SOURCES}") -# message("Link libraries: ${LIBRARY_LINK_LIBRARIES}") -# message("UI: ${LIBRARY_UI}") -# message("TARGET_TYPE: ${LIBRARY_TARGET_TYPE}") -# message("EXPORT_MACRO: ${LIBRARY_EXPORT_MACRO}") -# message("NO_INSTALL: ${LIBRARY_NO_INSTALL}") - set(target ${LIBRARY_NAME}) # qt stuff @@ -76,13 +90,8 @@ function(calamares_add_library) endif() if(LIBRARY_COMPILE_DEFINITIONS) - # Dear CMake, i hate you! Sincerely, domme - # At least in CMake 2.8.8, you CANNOT set more than one COMPILE_DEFINITIONS value - # only takes the first one if called multiple times or bails out with wrong number of arguments - # when passing in a list, thus i redefine the export macro here in hope it won't mess up other targets - add_definitions( "-D${LIBRARY_EXPORT_MACRO}" ) - - set_target_properties(${target} PROPERTIES COMPILE_DEFINITIONS ${LIBRARY_COMPILE_DEFINITIONS}) + set( _lib_definitions "${LIBRARY_EXPORT_MACRO}" ${LIBRARY_COMPILE_DEFINITIONS} ) + set_target_properties(${target} PROPERTIES COMPILE_DEFINITIONS "${_lib_definitions}") endif() # add link targets @@ -119,9 +128,6 @@ function(calamares_add_library) set(LIBRARY_INSTALL_LIBDIR "${LIBRARY_INSTALL_BINDIR}") endif() - #message("INSTALL_BINDIR: ${LIBRARY_INSTALL_BINDIR}") - #message("INSTALL_LIBDIR: ${LIBRARY_INSTALL_LIBDIR}") - # make installation optional, maybe useful for dummy plugins one day if(NOT LIBRARY_NO_INSTALL) include(GNUInstallDirs) diff --git a/CMakeModules/CalamaresAddPlugin.cmake b/CMakeModules/CalamaresAddPlugin.cmake index 886501a56..1d749d51c 100644 --- a/CMakeModules/CalamaresAddPlugin.cmake +++ b/CMakeModules/CalamaresAddPlugin.cmake @@ -40,6 +40,10 @@ # [SHARED_LIB] # [EMERGENCY] # ) +# +# The COMPILE_DEFINITIONS are set on the resulting module with a suitable +# flag (i.e. `-D`) so only state the name (optionally, also the value) +# without a `-D` prefixed to it. include( CMakeParseArguments ) include( CalamaresAddLibrary )