Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e6df884

Browse files
committed
Change: Oraganize cmake config of bins
1 parent 63df9b0 commit e6df884

File tree

3 files changed

+37
-14
lines changed

3 files changed

+37
-14
lines changed

src/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ include_directories(SYSTEM third_party/toml11)
4949

5050
include(cmake/compile-options.cmake)
5151
include(cmake/cpack.cmake)
52+
include(cmake/bin.cmake)
5253

5354
add_subdirectory(lib)
5455
add_subdirectory(bin)

src/bin/CMakeLists.txt

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,8 @@
1515

1616
cmake_minimum_required(VERSION 2.7)
1717

18-
add_executable(servo_array_bin servo_array.cpp)
19-
set_target_properties(servo_array_bin PROPERTIES OUTPUT_NAME "servo_array")
20-
target_link_libraries(servo_array_bin servoarray_lib)
21-
sa_set_compile_options(servo_array_bin)
22-
install(TARGETS servo_array_bin RUNTIME DESTINATION bin)
18+
sa_add_bin(servo_array INSTALL)
2319

24-
add_executable(servo_map_bin servo_map.cpp)
25-
set_target_properties(servo_map_bin PROPERTIES OUTPUT_NAME "servo_map")
26-
target_link_libraries(servo_map_bin servoarray_lib)
27-
sa_set_compile_options(servo_map_bin)
28-
install(TARGETS servo_map_bin RUNTIME DESTINATION bin)
20+
sa_add_bin(servo_map INSTALL)
2921

30-
add_executable(bench_bin bench.cpp)
31-
set_target_properties(bench_bin PROPERTIES OUTPUT_NAME "bench")
32-
target_link_libraries(bench_bin servoarray_lib)
33-
sa_set_compile_options(bench_bin)
22+
sa_add_bin(bench)

src/cmake/bin.cmake

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# This file is part of servoarray.
2+
#
3+
# servoarray is free software: you can redistribute it and/or modify
4+
# it under the terms of the GNU General Public License as published by
5+
# the Free Software Foundation, either version 3 of the License, or
6+
# (at your option) any later version.
7+
#
8+
# servoarray is distributed in the hope that it will be useful,
9+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
# GNU General Public License for more details.
12+
#
13+
# You should have received a copy of the GNU General Public License
14+
# along with servoarray. If not, see <http://www.gnu.org/licenses/>.
15+
16+
function(sa_add_bin target)
17+
cmake_parse_arguments(ARG "INSTALL" "NAME" "" ${ARGN})
18+
19+
if(ARG_NAME)
20+
set(name ${ARG_NAME})
21+
else()
22+
set(name ${target})
23+
endif()
24+
25+
add_executable(${target}_bin ${target}.cpp)
26+
set_target_properties(${target}_bin PROPERTIES OUTPUT_NAME "${name}")
27+
target_link_libraries(${target}_bin servoarray_lib)
28+
sa_set_compile_options(${target}_bin)
29+
30+
if(${ARG_INSTALL})
31+
install(TARGETS ${target}_bin RUNTIME DESTINATION bin)
32+
endif()
33+
endfunction()

0 commit comments

Comments
 (0)