comparison cmake/function/IrccdDefineExecutable.cmake @ 0:1158cffe5a5e

Initial import
author David Demelier <markand@malikania.fr>
date Mon, 08 Feb 2016 16:43:14 +0100
parents
children 98ac3c79009f
comparison
equal deleted inserted replaced
-1:000000000000 0:1158cffe5a5e
1 #
2 # IrccdDefineExecutable.cmake -- CMake build system for irccd
3 #
4 # Copyright (c) 2013-2016 David Demelier <markand@malikania.fr>
5 #
6 # Permission to use, copy, modify, and/or distribute this software for any
7 # purpose with or without fee is hereby granted, provided that the above
8 # copyright notice and this permission notice appear in all copies.
9 #
10 # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 #
18
19 #
20 # irccd_define_executable
21 # -------------------------------------------------------------------
22 #
23 # irccd_define_executable(
24 # TARGET target name
25 # SOURCES src1, src2, srcn
26 # FLAGS (Optional) C/C++ flags (without -D)
27 # LIBRARIES (Optional) libraries to link
28 # INCLUDES (Optional) includes for the target
29 # INSTALL (Optional) if set, install the executable (default: false)
30 # PRIVATE (Optional) if set, do not build it into the fake root (default: false)
31 # )
32 #
33 # Create an executable that can be installed or not.
34 #
35
36 function(irccd_define_executable)
37 set(options INSTALL PRIVATE)
38 set(oneValueArgs TARGET INSTALL)
39 set(multiValueArgs SOURCES FLAGS LIBRARIES INCLUDES)
40
41 cmake_parse_arguments(EXE "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
42
43 if (NOT EXE_TARGET)
44 message(FATAL_ERROR "Please set TARGET")
45 endif ()
46 if (NOT EXE_SOURCES)
47 message(FATAL_ERROR "Please set SOURCES")
48 endif ()
49
50 if (EXE_INSTALL AND EXE_PRIVATE)
51 message(FATAL_ERROR "INSTALL and PRIVATE are mutually exclusive")
52 endif ()
53
54 add_executable(${EXE_TARGET} ${EXE_SOURCES})
55 target_include_directories(${EXE_TARGET} PRIVATE ${EXE_INCLUDES})
56 target_compile_definitions(${EXE_TARGET} PRIVATE ${EXE_FLAGS})
57 target_link_libraries(${EXE_TARGET} ${EXE_LIBRARIES})
58
59 # use fakeroot if relocatable for public executables.
60 if (IRCCD_RELOCATABLE AND NOT EXE_PRIVATE)
61 file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/fakeroot/${WITH_BINDIR})
62
63 set_target_properties(
64 ${EXE_TARGET}
65 PROPERTIES
66 RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/fakeroot/${WITH_BINDIR}
67 RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR}/fakeroot/${WITH_BINDIR}
68 RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}/fakeroot/${WITH_BINDIR}
69 )
70 endif ()
71
72 # Install the target.
73 if (EXE_INSTALL)
74 install(
75 TARGETS ${EXE_TARGET}
76 RUNTIME DESTINATION ${WITH_BINDIR}
77 )
78 endif ()
79 endfunction()