view cmake/function/MalikaniaDefineExecutable.cmake @ 49:2804ae55c70f

CMake: big cleanup, closes #598
author David Demelier <markand@malikania.fr>
date Fri, 09 Dec 2016 13:28:45 +0100
parents
children 697bf85e8e19
line wrap: on
line source

#
# MalikaniaDefineExecutable.cmake -- CMake build system for malikania
#
# Copyright (c) 2013-2016 Malikania Authors
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#

#
# malikania_define_executable
# ---------------------------
#
# malikania_define_executable(
#    TARGET             The target name
#    SOURCES            The list of sources
#    FLAGS              (Optional) List of flags
#    INCLUDES           (Optional) List of include directories
#    LIBRARIES          (Optional) List of libraries
# )
#
# Create an executable. Be sure to quote SOURCES, if not only the first file will be passed.
# If you need flags, just pass them without -D or /D, this is automatically done for you.
#

include(CMakeParseArguments)

function(malikania_define_executable)
    set(singleArgs TARGET)
    set(multiArgs SOURCES FLAGS INCLUDES LIBRARIES)

    cmake_parse_arguments(EXE "" "${singleArgs}" "${multiArgs}" ${ARGN})

    if (NOT EXE_TARGET)
        message(FATAL_ERROR "Missing TARGET parameter")
    endif ()
    if (NOT EXE_SOURCES)
        message(FATAL_ERROR "Missing SOURCES parameter")
    endif ()

    add_executable(${EXE_TARGET} ${EXE_SOURCES})
    target_link_libraries(${EXE_TARGET} ${EXE_LIBRARIES})
    target_include_directories(${EXE_TARGET} PRIVATE ${EXE_INCLUDES})
    target_compile_definitions(${EXE_TARGET} PRIVATE ${EXE_FLAGS})
endfunction()