티스토리 뷰
I'm gonna cover "how to use FUNCTION in CMake" at this post.
Function of CMake is not that different with a function of C, C++ and Java.
Function could have name and varidic arguments and It has Its own scope that means a function could refers
variable of outer scope. But Its variables are terminated as soon as the function is terminated.
By "argc" in function, You could know how many arguments are passed into function.
By "argv", You could get every argument at once(each of argument is treated as element of list then argv is list
which contains all argument of function)
EXAMPLE
cmake_minimum_required(VERSION 3.15)
project(cmaketoy)
set(CMAKE_CXX_STANDARD 11)
set (out_var "I'm not in a function")
function(hello_world)
set (scope_test "In the scope")
message("Hello world function!! hello world! = ${scope_test}")
message(${out_var})
endfunction(hello_world)
message("Is scope_test alive?! = ${scope_test}")
function(fn_with_args a b c d)
message(${ARGV}) # hello world We're args
message(${ARGC}) # Total number of arguments = 4
message(${ARGV0})
message(${ARGV1})
message(${ARGV2})
message(${ARGV3})
message("I will line all parameters by foreach")
foreach(arg ${ARGV})
message(${arg})
endforeach()
endfunction()
hello_world()
fn_with_args("hello " "world " "We're " "args")
add_executable(cmaketoy main.cpp)
RESULT
Interesting uh?
'cmake' 카테고리의 다른 글
[CMake, KOR/ENG] How to generate gRPC c++ code with CMake (0) | 2019.12.24 |
---|---|
[CMake,ENG/KOR] compile protobuf with CMake (0) | 2019.12.24 |
[CMake, KOR] get_filename_component (0) | 2019.12.23 |
[CMake, KOR] foreach - 1 (0) | 2019.12.23 |
[CMake,KOR] LIST (0) | 2019.12.23 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- CMake run protoc
- CMAke 파일이름 추출
- 14714 어플리케이션
- 14714 공부법
- 함수포인터 오버라이트
- CMake get_filename_Component
- 복습 계획어플
- CMake for
- 복습 어플
- react-native
- 14714 어플
- CMake probouf
- 14714 앱
- 14714 복습법
- buffer-over-flow
- 14714 review
- CMake get file name
- 14714 플래너
- aws 청구문의
- aws 프리티어 요금청구
- 14714 공부법 어플리케이션
- CMake 기초
- review reminder
- CMake for문
- get_filename_component
- CMake 강좌
- 토리파 공부법
- CMake run proto compiler
- function pointer overflow
- CMake 반복문
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
글 보관함