1# Conditionally build an example program. If any of its arguments is the exact 2# string "x", do nothing. Otherwise strip off the "x" prefixes on arguments 3# and link to that target. 4function(example name) 5 # Use cmake_parse_arguments first. 6 set(flags CONSOLE) 7 set(single_args) # none 8 set(accum_args DATA EXTRA_LIBS) 9 cmake_parse_arguments(MYOPTS "${flags}" "${single_args}" "${accum_args}" 10 ${ARGN}) 11 12 # Parse what remains of the argument list manually. 13 set(sources) 14 set(libs) 15 foreach(arg ${MYOPTS_UNPARSED_ARGUMENTS}) 16 if(arg STREQUAL "x") 17 message(STATUS "Not building ${name}") 18 return() 19 endif() 20 if(arg MATCHES "[.]c$") 21 list(APPEND sources ${arg}) 22 elseif(arg MATCHES "[.]cpp$") 23 list(APPEND sources ${arg}) 24 else() 25 string(REGEX REPLACE "^x" "" arg ${arg}) 26 list(APPEND libs ${arg}) 27 endif() 28 endforeach() 29 30 # If no sources are listed assume a single C source file. 31 if(NOT sources) 32 set(sources "${name}.c") 33 endif() 34 35 # Prepend the base libraries. 36 if(ANDROID) 37 set(libs ${ALLEGRO_LINK_WITH} ${libs}) 38 else() 39 set(libs ${ALLEGRO_LINK_WITH} ${ALLEGRO_MAIN_LINK_WITH} ${libs}) 40 endif() 41 42 # Popup error messages. 43 if(WANT_POPUP_EXAMPLES AND SUPPORT_NATIVE_DIALOG) 44 list(APPEND libs ${NATIVE_DIALOG_LINK_WITH}) 45 endif() 46 47 # Monolith contains all other libraries which were enabled. 48 if(WANT_MONOLITH) 49 set(libs ${ALLEGRO_MONOLITH_LINK_WITH}) 50 endif() 51 52 # Append the extra, non-Allegro libraries. 53 foreach(lib ${MYOPTS_EXTRA_LIBS}) 54 list(APPEND libs ${lib}) 55 endforeach() 56 57 list(REMOVE_DUPLICATES libs) 58 59 if(WIN32) 60 if(MYOPTS_CONSOLE) 61 # We need stdout and stderr available from cmd.exe, 62 # so we must not use WIN32 here. 63 set(EXECUTABLE_TYPE) 64 else() 65 set(EXECUTABLE_TYPE "WIN32") 66 endif() 67 endif(WIN32) 68 69 if(IPHONE) 70 set(EXECUTABLE_TYPE MACOSX_BUNDLE) 71 endif(IPHONE) 72 73 if(ANDROID) 74 if(MYOPTS_CONSOLE) 75 message(STATUS "Not building ${name} - console program") 76 return() 77 endif() 78 add_copy_commands( 79 "${CMAKE_CURRENT_SOURCE_DIR}/data" 80 "${CMAKE_CURRENT_BINARY_DIR}/${name}.project/app/src/main/assets/data" 81 assets 82 "${MYOPTS_DATA}" 83 ) 84 add_android_app("${name}" "${sources};${assets}") 85 elseif(IPHONE) 86 add_our_executable("${name}" SRCS "${sources};${CMAKE_CURRENT_SOURCE_DIR}/data" 87 LIBS "${libs}") 88 set_source_files_properties("${CMAKE_CURRENT_SOURCE_DIR}/data" PROPERTIES 89 MACOSX_PACKAGE_LOCATION "Resources") 90 else() 91 add_our_executable("${name}" SRCS "${sources}" LIBS "${libs}") 92 endif() 93endfunction(example) 94 95#-----------------------------------------------------------------------------# 96# vim: set ts=8 sts=4 sw=4 et: 97