include_guard() include(JPPNameTarget) include(JPPGitInfo) # # jpp_add_executable(basename SOURCES ...) add an executable with the given # sources. # # * SOURCES gives the list of source files to compile into the # executable. If not provided, assume there's a single source to # be compiled and that it's named basename.cc # * LINK_LIBRARIES (needed in most cases) indicates the list of targets # this executable (privately) depends on. # * COMPILE_DEFINITIONS (not needed in most cases) specifies compile # definitions required to compile the sources # # The installed executable will be named `basename` # # Note that the _target_ corresponding to the executable will be named # JPPexe-basename and can be retrieved with the # TARGETVARNAME parameter if needed. # # For instance after a call to: # # jpp_add_executable(toto SOURCES ... TARGETVARNAME titi) # # ${titi} will contain something like `JPPexe-toto` (for the exact naming # see the jpp_name_target function) and an executable named `toto` will be # created upon build) function(jpp_add_executable baseTargetName) cmake_parse_arguments(PARSE_ARGV 1 A "NO_INSTALL" "TARGETVARNAME" "SOURCES;LINK_LIBRARIES;COMPILE_DEFINITIONS") if(A_UNPARSED_ARGUMENTS) message(FATAL_ERROR "Got trailing arguments ${A_UNPARSED_ARGUMENTS}") endif() jpp_get_dir_info(IS_EXAMPLE is_example IS_TEST is_test PACKAGE package BASE base) set(exeName ${baseTargetName}) # get the target name set(type IS_EXE) jpp_name_target(${baseTargetName} NAME targetName ${type} ) set(target ${targetName}) if(A_TARGETVARNAME) set(${A_TARGETVARNAME} ${target} PARENT_SCOPE) endif() set(sources ${A_SOURCES}) if(NOT A_SOURCES) # if sources not provided, assume there's a source file named like the # requested executable set(sources ${exeName}.cc) endif() # add the executable with its sources add_executable(${target} ${sources}) # initialize the various KM3NET_JPP_XXX custom properties jpp_init_custom_properties(${target}) # # FIXME: is the SOURCE compile def used for anything else than documentation ? # # (in which case it could be removed as far as the cmake build is concerned) set(src $) set(source_file $) target_compile_definitions(${target} PRIVATE "SOURCE=\"${source_file}\"") # set the executable output name set_property(TARGET ${target} PROPERTY RUNTIME_OUTPUT_NAME ${exeName}) if(is_example OR is_test) # examples go into examples/package/xxx # tests go into tests/package/xxx # while regular executables go to bin/ set_property(TARGET ${target} PROPERTY RUNTIME_OUTPUT_DIRECTORY ${KM3NET_JPP_STAGE_DIR}/${base}) endif() if(A_COMPILE_DEFINITIONS) target_compile_definitions(${target} PRIVATE "${A_COMPILE_DEFINITIONS}") endif() # set (private) link dependencies foreach(lib IN LISTS A_LINK_LIBRARIES) string(FIND ${lib} "::" NS) if(${NS} EQUAL -1) message(FATAL_ERROR "Trying to use a non-namespaced target ${lib}") endif() target_link_libraries(${target} PRIVATE ${lib}) endforeach() # unless we explicitely asked not to, we do install the executable if(NOT A_NO_INSTALL) install(TARGETS ${target} RUNTIME DESTINATION ${base}) endif() endfunction()