2019-09-07 12:03:22 +02:00
cmake_minimum_required ( VERSION 3.0.2 FATAL_ERROR )
# Generates files for MIME type <-> extension conversions
# DEPENDS ON: gperf grep bash/powershell
2019-09-19 21:15:32 +02:00
if ( NOT TDUTILS_MIME_TYPE )
return ( )
endif ( )
2019-09-07 12:03:22 +02:00
file ( MAKE_DIRECTORY auto )
set ( TDMIME_SOURCE
$ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / a u t o / m i m e _ t y p e _ t o _ e x t e n s i o n . c p p
$ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / a u t o / e x t e n s i o n _ t o _ m i m e _ t y p e . c p p
)
set ( TDMIME_AUTO
$ { T D M I M E _ S O U R C E }
P A R E N T _ S C O P E
)
add_custom_target ( tdmime_auto DEPENDS ${ TDMIME_SOURCE } )
if ( NOT CMAKE_CROSSCOMPILING )
find_program ( GPERF_EXECUTABLE gperf )
if ( NOT GPERF_EXECUTABLE )
message ( FATAL_ERROR "Could NOT find gperf. Add path to gperf executable to PATH environment variable or specify it manually using GPERF_EXECUTABLE option, i. e. 'cmake -DGPERF_EXECUTABLE:FILEPATH=\" <path to gperf executable>\ "'." )
endif ( )
set ( GPERF_FILES
$ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / a u t o / m i m e _ t y p e _ t o _ e x t e n s i o n . g p e r f
$ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / a u t o / e x t e n s i o n _ t o _ m i m e _ t y p e . g p e r f
)
set ( GPERF_GEN_SOURCE generate_mime_types_gperf.cpp )
add_executable ( generate_mime_types_gperf ${ GPERF_GEN_SOURCE } )
add_custom_command (
O U T P U T $ { G P E R F _ F I L E S }
W O R K I N G _ D I R E C T O R Y $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R }
C O M M A N D g e n e r a t e _ m i m e _ t y p e s _ g p e r f m i m e _ t y p e s . t x t $ { G P E R F _ F I L E S }
D E P E N D S g e n e r a t e _ m i m e _ t y p e s _ g p e r f m i m e _ t y p e s . t x t
)
if ( WIN32 )
set ( MIME_TYPE_TO_EXTENSION_CMD ${ GPERF_EXECUTABLE } -m100 --output-file=auto/mime_type_to_extension.cpp auto/mime_type_to_extension.gperf )
else ( )
set ( MIME_TYPE_TO_EXTENSION_CMD ${ GPERF_EXECUTABLE } -m100 auto/mime_type_to_extension.gperf | grep -v __gnu_inline__ > auto/mime_type_to_extension.cpp )
endif ( )
add_custom_command (
O U T P U T $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / a u t o / m i m e _ t y p e _ t o _ e x t e n s i o n . c p p
W O R K I N G _ D I R E C T O R Y $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R }
C O M M A N D $ { M I M E _ T Y P E _ T O _ E X T E N S I O N _ C M D }
D E P E N D S a u t o / m i m e _ t y p e _ t o _ e x t e n s i o n . g p e r f
)
if ( WIN32 )
set ( EXTENSION_TO_MIME_TYPE_CMD ${ GPERF_EXECUTABLE } -m100 --output-file=auto/extension_to_mime_type.cpp auto/extension_to_mime_type.gperf )
else ( )
set ( EXTENSION_TO_MIME_TYPE_CMD ${ GPERF_EXECUTABLE } -m100 auto/extension_to_mime_type.gperf | grep -v __gnu_inline__ > auto/extension_to_mime_type.cpp )
endif ( )
add_custom_command (
O U T P U T $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / a u t o / e x t e n s i o n _ t o _ m i m e _ t y p e . c p p
W O R K I N G _ D I R E C T O R Y $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R }
C O M M A N D $ { E X T E N S I O N _ T O _ M I M E _ T Y P E _ C M D }
D E P E N D S a u t o / e x t e n s i o n _ t o _ m i m e _ t y p e . g p e r f
)
endif ( )