Просмотр исходного кода

ENH: Added cmake macro: ctkMacroCtkLibraryOptions.cmake allowing to retrieve
option specific for a library and expose them both at the superbuild level and the inner
project level.

The macro is looking for a file named: ctk_library_options.cmake in
the given library directory, for example, Libs/<DIR>/<LIBNAME>/.

The content of this file could look like (for example):
set(ctk_library_options
OPT1:ON
OPT2:OFF
)

In case such file is found, in addition
to 'CTK_LIB_<DIR>/<LIBNAME>' option,

the following ones will also be available in CMake configure menu:
CTK_LIB_<DIR>/<LIBNAME>_OPT1 (set to OFF)
CTK_LIB_<DIR>/<LIBNAME>_OPT2 (set to ON)

Jean-Christophe Fillion-Robin лет назад: 15
Родитель
Сommit
f935917bb0
1 измененных файлов с 36 добавлено и 0 удалено
  1. 36 0
      CMake/ctkMacroAddCtkLibraryOptions.cmake

+ 36 - 0
CMake/ctkMacroAddCtkLibraryOptions.cmake

@@ -0,0 +1,36 @@
+
+#
+#
+#
+  
+MACRO(ctkMacroAddCtkLibraryOptions lib)
+
+  SET(filepath ${CMAKE_CURRENT_SOURCE_DIR}/Libs/${lib}/ctk_library_options.cmake)
+
+  # Add options only if "ctk_library_option.cmake" file exists
+  IF(EXISTS ${filepath})
+  
+    # Make sure the variable is cleared 
+    SET(ctk_library_options )
+
+    INCLUDE(${filepath})
+
+    FOREACH(option ${ctk_library_options})
+
+      # Make sure option is correctly formated
+      IF(NOT "${option}" MATCHES "^[A-Za-z0-9]+:(ON|OFF)")
+        MESSAGE(FATAL_ERROR "In ${filepath}, option ${option} is incorrect. Options should be specified using the following format OPT1:[ON|OFF]. For example OPT1:OFF or OPT2:ON")
+      ENDIF()
+      
+      # Extract option name and option default value
+      STRING(REPLACE ":" "\\;" option ${option})
+      SET(optionlist ${option})
+      LIST(GET optionlist 0 option_name)
+      LIST(GET optionlist 1 option_value)
+
+      OPTION(CTK_LIB_${lib}_${option_name} "Enable ${lib} Library ${option_name} option." ${option_value})
+    ENDFOREACH()
+    
+  ENDIF()
+  
+ENDMACRO()