{"id":6175,"date":"2019-06-02T21:47:22","date_gmt":"2019-06-02T12:47:22","guid":{"rendered":"https:\/\/theolizer.com\/wordpress\/?p=6175"},"modified":"2019-06-03T23:02:12","modified_gmt":"2019-06-03T14:02:12","slug":"cpp-school3-9","status":"publish","type":"post","link":"https:\/\/theolizer.com\/cpp-school3\/cpp-school3-9\/","title":{"rendered":"\u7b2c9\u56de CMake\u5909\u6570\u306e\u30b9\u30b3\u30fc\u30d7"},"content":{"rendered":"<p>\u3053\u3093\u306b\u3061\u306f\u3002\u7530\u539f\u3067\u3059\u3002<\/p>\n<p>C++\u306e\u5909\u6570\u306f\u30b0\u30ed\u30fc\u30d0\u30eb\u5909\u6570\u3084\u30ed\u30fc\u30ab\u30eb\u5909\u6570\u3001\u30e1\u30f3\u30d0\u5909\u6570\u7b49\u69d8\u3005\u306a\u5909\u6570\u304c\u3042\u308a\u53b3\u5bc6\u306b\u30b9\u30b3\u30fc\u30d7\uff08\u6709\u52b9\u7bc4\u56f2\uff09\u304c\u5b9a\u7fa9\u3055\u308c\u3066\u3044\u307e\u3059\u306d\u3002CMake\u5909\u6570\u306b\u3082\u540c\u69d8\u306b\u30b9\u30b3\u30fc\u30d7\u304c\u3042\u308a\u307e\u3059\u3002CMake\u306f\u30a4\u30f3\u30bf\u30d7\u30ea\u30bf\u3068\u3044\u3046\u3053\u3068\u3082\u3042\u308a\u3001C++\u5909\u6570\u3068\u306f\u8003\u3048\u65b9\u304c\u304b\u306a\u308a\u7570\u306a\u308a\u307e\u3059\u3002\u4eca\u56de\u306f\u3053\u306eCMake\u5909\u6570\u306e\u30b9\u30b3\u30fc\u30d7\u306b\u3064\u3044\u3066\u89e3\u8aac\u3057\u307e\u3059\u3002<\/p>\n<h3>\uff11\uff0e\u30b9\u30b3\u30fc\u30d7\u306e\u7a2e\u985e<\/h3>\n<p>C++\u306e\u5909\u6570\u306e\u30b9\u30b3\u30fc\u30d7\u306f\u5bff\u547d\u3068\u30a2\u30af\u30bb\u30b9\u7bc4\u56f2\u306e\u7d44\u307f\u5408\u308f\u305b\u304c\u3042\u308b\u306e\u3067\u5b9f\u306b\u591a\u7a2e\u985e\u3042\u308a\u307e\u3059\u3002<br \/>\n\uff5b \u9759\u7684\u5909\u6570\u3001\u30b9\u30bf\u30c3\u30af\u4e0a\u306e\u5909\u6570\u3001\u30d2\u30fc\u30d7\u4e0a\u306e\u5909\u6570 \uff5d \u00d7 \uff5b \u30d7\u30ed\u30b0\u30e9\u30e0\u5168\u4f53\u3001\u540c\u3058\u30bd\u30fc\u30b9\u30d5\u30a1\u30a4\u30eb\u5185\u3001\uff11\u3064\u306e\u30af\u30e9\u30b9\u5185\u3001\uff11\u3064\u306e\u95a2\u6570\u5185 \uff5d\u3001\u66f4\u306b\u30b9\u30ec\u30c3\u30c9\u30fb\u30b9\u30b3\u30fc\u30d7\u3082\u3042\u308a\u307e\u3059\u3002\u5358\u7d14\u306a\u7d44\u307f\u5408\u308f\u305b\u3067\u306f\u306a\u304f\u3001\u306a\u304b\u306a\u304b\u8907\u96d1\u3067\u3059\u3002<\/p>\n<p>\u305d\u308c\u306b\u6bd4\u3079\u308b\u3068CMake\u306f\u7c21\u5358\u3067\u3059\u3002<\/p>\n<ol>\n<li>CMake\u306f\u30a4\u30f3\u30bf\u30d7\u30ea\u30bf\u3067\u3059\u306e\u3067\u3001\u57fa\u672c\u306f\u8a2d\u5b9a\u30b3\u30de\u30f3\u30c9\u304c\u5b9f\u884c\u3055\u308c\u305f\u6642\u70b9\u3067\u30e1\u30e2\u30ea\u9818\u57df\u304c\u78ba\u4fdd\u3055\u308c\u307e\u3059\u3002<\/li>\n<li>\u3057\u304b\u3057\u3001\u4e00\u5b9a\u306e\u30b1\u30fc\u30b9\u3067\u306f\u547c\u3073\u51fa\u3057\u5143\u3067\u78ba\u4fdd\u3055\u308c\u305f\u30e1\u30e2\u30ea\u9818\u57df\u3068\u306f\u7570\u306a\u308b\u9818\u57df\u304c\u78ba\u4fdd\u3055\u308c\u307e\u3059\u3002<\/li>\n<li>\u66f4\u306b\u3001\u305d\u306e\u5185\u306e\u4e00\u90e8\u306e\u30b1\u30fc\u30b9\u3067\u547c\u3073\u51fa\u3057\u5143\u306e\u30e1\u30e2\u30ea\u9818\u57df\u3078\u8a2d\u5b9a\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/li>\n<\/ol>\n<h3>\uff12\uff0e\u57fa\u672c<\/h3>\n<h5>\u5148\u306b\u8ff0\u3079\u305f\u3088\u3046\u306b\u57fa\u672c\u306f\u8a2d\u5b9a\u3057\u305f\u6642\u70b9\u4ee5\u964d\u3067CMake\u5909\u6570\u306f\u6709\u52b9\u306b\u306a\u308a\u307e\u3059\u3002<\/h5>\n<p>\u307e\u305f\u3001\u672a\u8a2d\u5b9a\u306e\u6642\u306f <strong>\u7a7a\u6587\u5b57\u5217<\/strong> \u306b\u5c55\u958b\u3055\u308c\u307e\u3059\u3002<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nmessage(STATUS &quot;NORMAL_VAR=${NORMAL_VAR}&quot;)\r\nset(NORMAL_VAR &quot;parent&quot;)\r\nmessage(STATUS &quot;NORMAL_VAR=${NORMAL_VAR}&quot;)\r\nset(NORMAL_VAR &quot;normal&quot;)\r\nmessage(STATUS &quot;NORMAL_VAR=${NORMAL_VAR}&quot;)\r\n<\/pre>\n<div class=\"su-spoiler su-spoiler-style-fancy su-spoiler-icon-plus su-spoiler-closed\" data-scroll-offset=\"0\" data-anchor-in-url=\"no\"><div class=\"su-spoiler-title\" tabindex=\"0\" role=\"button\"><span class=\"su-spoiler-icon\"><\/span>\u5b9f\u884c\u7d50\u679c<\/div><div class=\"su-spoiler-content su-u-clearfix su-u-trim\">\n[text]\n&#8212; NORMAL_VAR=<br \/>\n&#8212; NORMAL_VAR=parent<br \/>\n&#8212; NORMAL_VAR=normal<br \/>\n[\/text]\n<\/div><\/div>\n<h5>\u30de\u30af\u30ed\u306e\u5185\u90e8\u3067set\u3057\u305f\u5834\u5408\u3001\u30de\u30af\u30ed\u3092\u547c\u3073\u51fa\u3057\u305f\u6642\u306b\u8a2d\u5b9a\u3055\u308c\u307e\u3059\u3002<\/h5>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nmacro(macro_sample)\r\n    message(STATUS &quot;MACRO_VAR=${MACRO_VAR}&quot;)\r\n    set(MACRO_VAR &quot;macro&quot;)\r\nendmacro()\r\n\r\nmessage(STATUS &quot;MACRO_VAR=${MACRO_VAR}&quot;)\r\nset(MACRO_VAR &quot;parent&quot;)\r\nmessage(STATUS &quot;MACRO_VAR=${MACRO_VAR}&quot;)\r\nmacro_sample()\r\nmessage(STATUS &quot;MACRO_VAR=${MACRO_VAR}&quot;)\r\n<\/pre>\n<div class=\"su-spoiler su-spoiler-style-fancy su-spoiler-icon-plus su-spoiler-closed\" data-scroll-offset=\"0\" data-anchor-in-url=\"no\"><div class=\"su-spoiler-title\" tabindex=\"0\" role=\"button\"><span class=\"su-spoiler-icon\"><\/span>\u5b9f\u884c\u7d50\u679c<\/div><div class=\"su-spoiler-content su-u-clearfix su-u-trim\">\n[text]\n&#8212; MACRO_VAR=<br \/>\n&#8212; MACRO_VAR=parent<br \/>\n&#8212; MACRO_VAR=parent<br \/>\n&#8212; MACRO_VAR=macro<br \/>\n[\/text]\n<\/div><\/div>\n<h5>include \u306e\u4f8b\u3067\u3059\u3002<\/h5>\n<p>include \u306fC\/C++\u306e#include\u3068\u540c\u3058\u3088\u3046\u306b\u632f\u308b\u821e\u3044\u307e\u3059\u306e\u3067\u30b9\u30b3\u30fc\u30d7\u306f\u5f62\u6210\u3057\u307e\u305b\u3093\u3002<br \/>\n\u5fae\u5999\u306badd_subdirectory\u3068\u6df7\u4e71\u3059\u308b\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u306e\u3067\u3001\u5ff5\u306e\u70ba\u30b5\u30f3\u30d7\u30eb\u3092\u8f09\u305b\u3066\u304a\u304d\u307e\u3059\u3002<\/p>\n<pre class=\"brush: plain; title: included.cmake; notranslate\" title=\"included.cmake\">\r\nmessage(STATUS &quot;INCLUDED_VAR=${INCLUDED_VAR}&quot;)\r\nset(INCLUDED_VAR &quot;included&quot;)\r\n<\/pre>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nmessage(STATUS &quot;INCLUDED_VAR=${INCLUDED_VAR}&quot;)\r\nset(INCLUDED_VAR &quot;parent&quot;)\r\nmessage(STATUS &quot;INCLUDED_VAR=${INCLUDED_VAR}&quot;)\r\ninclude(included.cmake)\r\nmessage(STATUS &quot;INCLUDED_VAR=${INCLUDED_VAR}&quot;)\r\n<\/pre>\n<div class=\"su-spoiler su-spoiler-style-fancy su-spoiler-icon-plus su-spoiler-closed\" data-scroll-offset=\"0\" data-anchor-in-url=\"no\"><div class=\"su-spoiler-title\" tabindex=\"0\" role=\"button\"><span class=\"su-spoiler-icon\"><\/span>\u5b9f\u884c\u7d50\u679c<\/div><div class=\"su-spoiler-content su-u-clearfix su-u-trim\">\n[text]\n&#8212; INCLUDED_VAR=<br \/>\n&#8212; INCLUDED_VAR=parent<br \/>\n&#8212; INCLUDED_VAR=parent<br \/>\n&#8212; INCLUDED_VAR=included<br \/>\n[\/text]\n<\/div><\/div>\n<h3>\uff13\uff0e\u30b9\u30b3\u30fc\u30d7\u304c\u5f62\u6210\u3055\u308c\u308b\uff08\u547c\u3073\u51fa\u3057\u5148\u3067\u5225\u30e1\u30e2\u30ea\u9818\u57df\u304c\u78ba\u4fdd\u3055\u308c\u308b\uff09\u30b1\u30fc\u30b9<\/h3>\n<p>\u5192\u982d\u306b\u66f8\u3044\u305f\u3088\u3046\u306b\u300c\u57fa\u672c\u300d\u306f\u7279\u5b9a\u306e\u30b1\u30fc\u30b9\u3067\u7121\u52b9\u306b\u306a\u308a\u307e\u3059\u3002<br \/>\nfunction()\uff5eendfunction()\u306e\u9593\u3001add_subdirectory()\u3067\u8aad\u307f\u8fbc\u3093\u3060CMakeLists.txt\u306e\u4e2d\u3001foreach()\uff5eendforeach()\u306e\u30eb\u30fc\u30d7\u5909\u6570\u3067\u3059\u3002<br \/>\n\u3053\u308c\u3089\u306e\u30b9\u30b3\u30fc\u30d7\u306b\u5165\u308b\u524d\u306b\u5b9a\u7fa9\u3055\u308c\u305f\u5909\u6570\u306e\u5024\u3092\u898b\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u304c\u3001\u8a2d\u5b9a\u3057\u3066\u3082\u547c\u3073\u51fa\u3057\u5143\u306b\u306f\u53cd\u6620\u3055\u308c\u307e\u305b\u3093\u3002\u547c\u3073\u51fa\u3057\u5148\u306e\u5909\u6570\u7528\u306e\u9818\u57df\u304c\u5225\u9014\u78ba\u4fdd\u3055\u308c\u3001\u547c\u3073\u51fa\u3057\u5143\u306e\u5024\u304c\u300c\u30b3\u30d4\u30fc\u300d\u3055\u308c\u3066\u3044\u308b\u3088\u3046\u3067\u3059\u3002<\/p>\n<h5>\u307e\u305a\u306f\u3001function()\u306e\u4f8b\u3067\u3059\u3002<\/h5>\n<p>\uff08\u4ee5\u964d\u3001\u672a\u8a2d\u5b9a\u72b6\u614b\u306e\u5909\u6570\u78ba\u8a8d\u306f\u7701\u7565\u3057\u3066\u3044\u307e\u3059\u3002\uff09<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nfunction(function_sample)\r\n    message(STATUS &quot;FUNCTION_VAR=${FUNCTION_VAR}&quot;)\r\n    set(FUNCTION_VAR &quot;function&quot;)\r\n    message(STATUS &quot;FUNCTION_VAR=${FUNCTION_VAR}&quot;)\r\nendfunction()\r\n\r\nset(FUNCTION_VAR &quot;parent&quot;)\r\nfunction_sample()\r\nmessage(STATUS &quot;FUNCTION_VAR=${FUNCTION_VAR}&quot;)\r\n<\/pre>\n<div class=\"su-spoiler su-spoiler-style-fancy su-spoiler-icon-plus su-spoiler-closed\" data-scroll-offset=\"0\" data-anchor-in-url=\"no\"><div class=\"su-spoiler-title\" tabindex=\"0\" role=\"button\"><span class=\"su-spoiler-icon\"><\/span>\u5b9f\u884c\u7d50\u679c<\/div><div class=\"su-spoiler-content su-u-clearfix su-u-trim\">\n[text]\n&#8212; FUNCTION_VAR=parent<br \/>\n&#8212; FUNCTION_VAR=function<br \/>\n&#8212; FUNCTION_VAR=parent<br \/>\n[\/text]\n<\/div><\/div>\n<h5>\u6b21\u306b\u3001add_subdirectory()\u306e\u4f8b\u3067\u3059\u3002<\/h5>\n<pre class=\"brush: plain; title: exe\/CMakeLists.txt; notranslate\" title=\"exe\/CMakeLists.txt\">\r\nadd_executable(cpp_exe cpp_exe.cpp)\r\n\r\nmessage(STATUS &quot;SUBDIR_VAR=${SUBDIR_VAR}&quot;)\r\nset(SUBDIR_VAR &quot;subdir&quot;)\r\nmessage(STATUS &quot;SUBDIR_VAR=${SUBDIR_VAR}&quot;)\r\n<\/pre>\n<div class=\"su-spoiler su-spoiler-style-fancy su-spoiler-icon-plus su-spoiler-closed\" data-scroll-offset=\"0\" data-anchor-in-url=\"no\"><div class=\"su-spoiler-title\" tabindex=\"0\" role=\"button\"><span class=\"su-spoiler-icon\"><\/span>exe\/cpp_exe.cpp<\/div><div class=\"su-spoiler-content su-u-clearfix su-u-trim\">\n[cpp]\n#include &lt;iostream&gt;<\/p>\n<p>int main()<br \/>\n{<br \/>\n    std::cout &lt;&lt; &quot;Hello, world!!\\n&quot;;<br \/>\n}<br \/>\n[\/cpp]\n<\/div><\/div>\n<pre class=\"brush: plain; title: CMakeLists.txt; notranslate\" title=\"CMakeLists.txt\">\r\ncmake_minimum_required(VERSION 3.13.4)\r\nproject(sample)\r\n\r\nset(SUBDIR_VAR &quot;parent&quot;)\r\nadd_subdirectory(exe)\r\nmessage(STATUS &quot;SUBDIR_VAR=${SUBDIR_VAR}&quot;)\r\n<\/pre>\n<div class=\"su-spoiler su-spoiler-style-fancy su-spoiler-icon-plus su-spoiler-closed\" data-scroll-offset=\"0\" data-anchor-in-url=\"no\"><div class=\"su-spoiler-title\" tabindex=\"0\" role=\"button\"><span class=\"su-spoiler-icon\"><\/span>\u5b9f\u884c\u7d50\u679c\uff08\u4e0d\u8981\u90e8\u5206\u306f\u7701\u7565\uff09<\/div><div class=\"su-spoiler-content su-u-clearfix su-u-trim\">\n[text]\n&#8212; SUBDIR_VAR=parent<br \/>\n&#8212; SUBDIR_VAR=subdir<br \/>\n&#8212; SUBDIR_VAR=parent<br \/>\n[\/text]\n<\/div><\/div>\n<h5>\u6700\u5f8c\u306b\u3001foreach()\u306e\u4f8b\u3067\u3059\u3002<\/h5>\n<p>foreach()\u306e\u30eb\u30fc\u30d7\u5909\u6570\u3060\u3051\u306f\u3001\u547c\u3073\u51fa\u3057\u5148\u7528\u306b\u9818\u57df\u304c\u8a2d\u3051\u3089\u308c\u307e\u3059\u304c\u3001\u305d\u308c\u4ee5\u5916\u306eforeach()\u5185\u90e8\u3067\u8a2d\u5b9a\u3057\u305f\u5909\u6570\u306f\u300c\u57fa\u672c\u300d\u3068\u540c\u3058\u632f\u308b\u821e\u3044\u3092\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nset(FOREACH_VAR0 &quot;parent&quot;)\r\nset(FOREACH_VAR1 &quot;parent&quot;)\r\nforeach(FOREACH_VAR0 RANGE 0 2)\r\n    message(STATUS &quot;FOREACH_VAR0=${FOREACH_VAR0}&quot;)\r\n    message(STATUS &quot;FOREACH_VAR1=${FOREACH_VAR1}&quot;)\r\n    set(FOREACH_VAR0 &quot;foreach&quot;)\r\n    set(FOREACH_VAR1 &quot;foreach&quot;)\r\nendforeach()\r\nmessage(STATUS &quot;FOREACH_VAR0=${FOREACH_VAR0}&quot;)\r\nmessage(STATUS &quot;FOREACH_VAR1=${FOREACH_VAR1}&quot;)\r\n<\/pre>\n<div class=\"su-spoiler su-spoiler-style-fancy su-spoiler-icon-plus su-spoiler-closed\" data-scroll-offset=\"0\" data-anchor-in-url=\"no\"><div class=\"su-spoiler-title\" tabindex=\"0\" role=\"button\"><span class=\"su-spoiler-icon\"><\/span>\u5b9f\u884c\u7d50\u679c<\/div><div class=\"su-spoiler-content su-u-clearfix su-u-trim\">\n[text]\n&#8212; FOREACH_VAR0=0<br \/>\n&#8212; FOREACH_VAR1=parent<br \/>\n&#8212; FOREACH_VAR0=1<br \/>\n&#8212; FOREACH_VAR1=foreach<br \/>\n&#8212; FOREACH_VAR0=2<br \/>\n&#8212; FOREACH_VAR1=foreach<br \/>\n&#8212; FOREACH_VAR0=parent<br \/>\n&#8212; FOREACH_VAR1=foreach<br \/>\n[\/text]\n<\/div><\/div>\n<h3>\uff14\uff0e\u305d\u3057\u3066\u3001\u7b2c\u4e8c\u306e\u4f8b\u5916\uff08PARENT_SCOPE\uff09<\/h3>\n<p>\u66f4\u306b\u3001\u547c\u3073\u51fa\u3055\u308c\u3066\u65b9\u3067\u306e\u307f\u6709\u52b9\u306a\u5909\u6570\u306b\u5bfe\u3057\u3066\u3001PARENT_SCOPE\u6307\u5b9a\u3057\u3066set\u3059\u308b\u3053\u3068\u3067\u547c\u3073\u51fa\u3057\u5143\u3078\u53cd\u6620\u3067\u304d\u308b\u3082\u306e\u304c\u3042\u308a\u307e\u3059\u3002<br \/>\n\u305d\u308c\u306f\u3001function()\uff5eendfunction()\u3068add_subdirectory()\u3067\u8aad\u307f\u8fbc\u3093\u3060CMakeLists.txt\u306e\u4e2d\u3067\u3059\u3002<\/p>\n<p>\u632f\u308b\u821e\u3044\u3068\u3057\u3066\u306f\u3001\u547c\u3073\u51fa\u3057\u5143\u306e\u5909\u6570\u304c\u547c\u3073\u51fa\u3057\u5148\u3078\u30b3\u30d4\u30fc\u3055\u308c\u3001PARENT_SCOPE\u3092\u6307\u5b9a\u3057\u306a\u3044\u6642\u306f\u30b3\u30d4\u30fc\u3055\u308c\u305f\u5909\u6570\u3078\u8a2d\u5b9a\u3055\u308c\u3001PARENT_SCOPE\u3092\u6307\u5b9a\u3059\u308b\u3068\u30b3\u30d4\u30fc\u5143\uff08\u547c\u3073\u51fa\u3057\u5143\uff09\u306e\u5909\u6570\u304c\u8a2d\u5b9a\u3055\u308c\u308b\u3088\u3046\u3067\u3059\u3002<\/p>\n<h5>\u307e\u305a\u306f\u3001function()\u306e\u4f8b\u3067\u3059\u3002<\/h5>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nfunction(function_sample)\r\n    message(STATUS &quot;FUNCTION_VAR0=${FUNCTION_VAR0}&quot;) # \u547c\u3073\u51fa\u3057\u5148\uff08\u547c\u3073\u51fa\u3057\u5143\u306e\u30b3\u30d4\u30fc\uff09\r\n    set(FUNCTION_VAR0 &quot;function&quot; PARENT_SCOPE)       # \u547c\u3073\u51fa\u3057\u5143\u3078\u8a2d\u5b9a\r\n    message(STATUS &quot;FUNCTION_VAR0=${FUNCTION_VAR0}&quot;) # \u547c\u3073\u51fa\u3057\u5148\r\n    set(FUNCTION_VAR0 &quot;function XXX&quot;)                # \u547c\u3073\u51fa\u3057\u5148\u3078\u8a2d\u5b9a\r\n    message(STATUS &quot;FUNCTION_VAR0=${FUNCTION_VAR0}&quot;) # \u547c\u3073\u51fa\u3057\u5148\r\n\r\n    message(STATUS &quot;FUNCTION_VAR1=${FUNCTION_VAR1}&quot;)\r\n    set(FUNCTION_VAR1 &quot;function&quot;)\r\nendfunction()\r\n\r\nset(FUNCTION_VAR0 &quot;parent&quot;)\r\nset(FUNCTION_VAR1 &quot;parent&quot;)\r\nfunction_sample()\r\nmessage(STATUS &quot;FUNCTION_VAR0=${FUNCTION_VAR0}&quot;)\r\nmessage(STATUS &quot;FUNCTION_VAR1=${FUNCTION_VAR1}&quot;)\r\n<\/pre>\n<div class=\"su-spoiler su-spoiler-style-fancy su-spoiler-icon-plus su-spoiler-closed\" data-scroll-offset=\"0\" data-anchor-in-url=\"no\"><div class=\"su-spoiler-title\" tabindex=\"0\" role=\"button\"><span class=\"su-spoiler-icon\"><\/span>\u5b9f\u884c\u7d50\u679c<\/div><div class=\"su-spoiler-content su-u-clearfix su-u-trim\">\n[text]\n&#8212; FUNCTION_VAR0=parent<br \/>\n&#8212; FUNCTION_VAR0=parent<br \/>\n&#8212; FUNCTION_VAR0=function XXX<br \/>\n&#8212; FUNCTION_VAR1=parent<br \/>\n&#8212; FUNCTION_VAR0=function<br \/>\n&#8212; FUNCTION_VAR1=parent<br \/>\n[\/text]\n<\/div><\/div>\n<h5>\u6b21\u306b\u3001add_subdirectory()\u306e\u4f8b\u3067\u3059\u3002<\/h5>\n<pre class=\"brush: plain; title: exe\/CMakeLists.txt; notranslate\" title=\"exe\/CMakeLists.txt\">\r\nadd_executable(cpp_exe cpp_exe.cpp)\r\n\r\nmessage(STATUS &quot;SUBDIR_VAR0=${SUBDIR_VAR0}&quot;)\r\nset(SUBDIR_VAR0 &quot;subdir&quot; PARENT_SCOPE)\r\nmessage(STATUS &quot;SUBDIR_VAR0=${SUBDIR_VAR0}&quot;)\r\nset(SUBDIR_VAR0 &quot;subdir XXX&quot;)\r\nmessage(STATUS &quot;SUBDIR_VAR0=${SUBDIR_VAR0}&quot;)\r\n\r\nmessage(STATUS &quot;SUBDIR_VAR1=${SUBDIR_VAR1}&quot;)\r\nset(SUBDIR_VAR1 &quot;subdir&quot;)\r\n<\/pre>\n<div class=\"su-spoiler su-spoiler-style-fancy su-spoiler-icon-plus su-spoiler-closed\" data-scroll-offset=\"0\" data-anchor-in-url=\"no\"><div class=\"su-spoiler-title\" tabindex=\"0\" role=\"button\"><span class=\"su-spoiler-icon\"><\/span>exe\/cpp_exe.cpp<\/div><div class=\"su-spoiler-content su-u-clearfix su-u-trim\">\n[cpp]\n#include &lt;iostream&gt;<\/p>\n<p>int main()<br \/>\n{<br \/>\n    std::cout &lt;&lt; &quot;Hello, world!!\\n&quot;;<br \/>\n}<br \/>\n[\/cpp]\n<\/div><\/div>\n<pre class=\"brush: plain; title: CMakeLists.txt; notranslate\" title=\"CMakeLists.txt\">\r\ncmake_minimum_required(VERSION 3.13.4)\r\nproject(sample)\r\n\r\nset(SUBDIR_VAR0 &quot;parent&quot;)\r\nset(SUBDIR_VAR1 &quot;parent&quot;)\r\nadd_subdirectory(exe)\r\nmessage(STATUS &quot;SUBDIR_VAR0=${SUBDIR_VAR0}&quot;)\r\nmessage(STATUS &quot;SUBDIR_VAR1=${SUBDIR_VAR1}&quot;)\r\n<\/pre>\n<div class=\"su-spoiler su-spoiler-style-fancy su-spoiler-icon-plus su-spoiler-closed\" data-scroll-offset=\"0\" data-anchor-in-url=\"no\"><div class=\"su-spoiler-title\" tabindex=\"0\" role=\"button\"><span class=\"su-spoiler-icon\"><\/span>\u5b9f\u884c\u7d50\u679c\uff08\u4e0d\u8981\u90e8\u5206\u306f\u7701\u7565\uff09<\/div><div class=\"su-spoiler-content su-u-clearfix su-u-trim\">\n[text]\n&#8212; SUBDIR_VAR0=parent<br \/>\n&#8212; SUBDIR_VAR0=parent<br \/>\n&#8212; SUBDIR_VAR0=subdir XXX<br \/>\n&#8212; SUBDIR_VAR1=parent<br \/>\n&#8212; SUBDIR_VAR0=subdir<br \/>\n&#8212; SUBDIR_VAR1=parent<br \/>\n[\/text]\n<\/div><\/div>\n<h5>\u6700\u5f8c\u306b\u3001foreach()\u306e\u30eb\u30fc\u30d7\u5909\u6570\u306b\u3064\u3044\u3066\u88dc\u8db3\uff08PARENT_SCOPE\u975e\u5bfe\u5fdc\u3067\u3059\uff09<\/h5>\n<p>\u3068\u3053\u308d\u3067\u3001foreach()\u306f\u5c11\u306a\u304f\u3082CMake 3.13.4\u3067\u306fPARENT_SCOPE\u3092\u6307\u5b9a\u3059\u308b\u3068\u30a8\u30e9\u30fc\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<pre class=\"brush: plain; title: sample.cmake; notranslate\" title=\"sample.cmake\">\r\nset(FOREACH_VAR0 &quot;parent&quot;)\r\nset(FOREACH_VAR1 &quot;parent&quot;)\r\nforeach(FOREACH_VAR0 RANGE 0 2)\r\n    message(STATUS &quot;FOREACH_VAR0=${FOREACH_VAR0}&quot;)\r\n    message(STATUS &quot;FOREACH_VAR1=${FOREACH_VAR1}&quot;)\r\n    set(FOREACH_VAR0 &quot;foreach&quot; PARENT_SCOPE)\r\n    set(FOREACH_VAR1 &quot;foreach&quot;)\r\nendforeach()\r\nmessage(STATUS &quot;FOREACH_VAR0=${FOREACH_VAR0}&quot;)\r\nmessage(STATUS &quot;FOREACH_VAR1=${FOREACH_VAR1}&quot;)\r\n<\/pre>\n<div class=\"su-spoiler su-spoiler-style-fancy su-spoiler-icon-plus su-spoiler-closed\" data-scroll-offset=\"0\" data-anchor-in-url=\"no\"><div class=\"su-spoiler-title\" tabindex=\"0\" role=\"button\"><span class=\"su-spoiler-icon\"><\/span>\u5b9f\u884c\u7d50\u679c<\/div><div class=\"su-spoiler-content su-u-clearfix su-u-trim\">\n[text]\n&#8212; FOREACH_VAR0=0<br \/>\n&#8212; FOREACH_VAR1=parent<br \/>\nCMake Warning (dev) at sample.cmake:6 (set):<br \/>\n  Cannot set &quot;FOREACH_VAR0&quot;: current scope has no parent.<br \/>\nThis warning is for project developers.  Use -Wno-dev to suppress it.<\/p>\n<p>&#8212; FOREACH_VAR0=1<br \/>\n&#8212; FOREACH_VAR1=foreach<br \/>\nCMake Warning (dev) at sample.cmake:6 (set):<br \/>\n  Cannot set &quot;FOREACH_VAR0&quot;: current scope has no parent.<br \/>\nThis warning is for project developers.  Use -Wno-dev to suppress it.<\/p>\n<p>&#8212; FOREACH_VAR0=2<br \/>\n&#8212; FOREACH_VAR1=foreach<br \/>\nCMake Warning (dev) at sample.cmake:6 (set):<br \/>\n  Cannot set &quot;FOREACH_VAR0&quot;: current scope has no parent.<br \/>\nThis warning is for project developers.  Use -Wno-dev to suppress it.<\/p>\n<p>&#8212; FOREACH_VAR0=parent<br \/>\n&#8212; FOREACH_VAR1=foreach<br \/>\n[\/text]\n<\/div><\/div>\n<h3>\uff15\uff0e\u307e\u3068\u3081<\/h3>\n<p>CMake\u3067\u8907\u96d1\u306a\u5909\u6570\u64cd\u4f5c\u3092\u884c\u3046\u3053\u3068\u306f\u6bd4\u8f03\u7684\u5c11\u306a\u3044\u3068\u306f\u601d\u3044\u307e\u3059\u3002<br \/>\n\u5b9f\u969b\u3001\u547c\u3073\u51fa\u3057\u5143\u306b\u5909\u6570\u306e\u5024\u3092\u53cd\u6620\u3057\u305f\u3044\u6642\u3001\u79c1\u306f\u3064\u3044\u3064\u3044macro\u3092\u4f7f\u3063\u3066\u3044\u307e\u3057\u305f\u3002\u5f53\u6642\u306f\u4eca\u56de\u306e\u3088\u3046\u306a\u6df1\u3044\u8abf\u67fb\u3092\u3057\u306a\u3044\u307e\u307eCMake\u3092\u4f7f\u3063\u3066\u3044\u305f\u306e\u3067\u624b\u629c\u304d\u3067\u3059\u306d\u3002<br \/>\n\u3057\u304b\u3057\u3001CMake\u306f\u30b9\u30af\u30ea\u30d7\u30c8\uff08\u7c21\u6613\u8a00\u8a9e\uff09\u3068\u306f\u3044\u3048\u3001\u306a\u308b\u3079\u304ffunction\u3092\u4f7f\u3063\u305f\u307b\u3046\u304c\u601d\u308f\u306c\u843d\u3068\u3057\u7a74\u306b\u30cf\u30de\u308a\u306b\u304f\u3044\u306e\u3067function\u3092\u4f7f\u3063\u305f\u65b9\u304c\u826f\u3055\u305d\u3046\u3067\u3059\u3002<\/p>\n<p>\u5e74\u3092\u3068\u308b\u306b\u3064\u308c\u6700\u8fd1\u306f\u3069\u3046\u3082\u96c6\u4e2d\u3067\u304d\u306a\u304f\u3066\u3044\u3051\u307e\u305b\u3093\u3002\u3053\u308c\u306f\u304d\u3063\u3068\u6905\u5b50\u306e\u305b\u3044\u3060\uff01\uff01\u3068\uff08\u6905\u5b50\u306e\u305b\u3044\u306b\u3057\u3066\uff09\u3001\u5927\u585a\u5bb6\u5177\u3067\u30cf\u30fc\u30de\u30f3\u30df\u30e9\u30fc\u306e<a href=\"https:\/\/www.hermanmiller.com\/ja_jp\/products\/seating\/office-chairs\/embody-chairs\/\" rel=\"noopener noreferrer\" target=\"_blank\">\u30a8\u30f3\u30dc\u30c7\u30a3\u30fb\u30c1\u30a7\u30a2<\/a>\u3092\u8cb7\u3044\u307e\u3057\u305f\u3002\u6709\u540d\u306a<a href=\"https:\/\/www.hermanmiller.com\/ja_jp\/products\/seating\/office-chairs\/aeron-chairs\/\" rel=\"noopener noreferrer\" target=\"_blank\">\u30a2\u30fc\u30ed\u30f3\u30c1\u30a7\u30a2<\/a>\u3068\u8ff7\u3063\u305f\u306e\u3060\u3051\u3069\u3001\u9577\uff5e\u3044\u6642\u9593\u80cc\u3082\u305f\u308c\u306b\u983c\u308b\u79c1\u306b\u306f\u3053\u3061\u3089\u306e\u65b9\u304c\u826f\u3055\u305d\u3046\u3067\u3057\u305f\u3002\u5ea7\u9762\u3082\u3086\u3063\u305f\u308a\u3057\u3066\u3044\u308b\u304b\u3089\u75b2\u308c\u306a\u3055\u305d\u3046\u3002\u5c4a\u304f\u306e\u304c\u697d\u3057\u307f\u3067\u3059\u3002<\/p>\n<p>\u305d\u308c\u3067\u306f\u4eca\u56de\u306f\u3053\u306e\u3078\u3093\u3067\u3002\u304a\u75b2\u308c\u69d8\u3067\u3057\u305f\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"\u3053\u3093\u306b\u3061\u306f\u3002\u7530\u539f\u3067\u3059\u3002 C++\u306e\u5909\u6570\u306f\u30b0\u30ed\u30fc\u30d0\u30eb\u5909\u6570\u3084\u30ed\u30fc\u30ab\u30eb\u5909\u6570\u3001\u30e1\u30f3\u30d0\u5909\u6570\u7b49\u69d8\u3005\u306a\u5909\u6570\u304c\u3042\u308a\u53b3\u5bc6\u306b\u30b9\u30b3\u30fc\u30d7\uff08\u6709\u52b9\u7bc4\u56f2\uff09\u304c\u5b9a\u7fa9\u3055\u308c\u3066\u3044\u307e\u3059\u306d\u3002CMake\u5909\u6570\u306b\u3082\u540c\u69d8\u306b\u30b9\u30b3\u30fc\u30d7\u304c\u3042\u308a\u307e\u3059\u3002CMake\u306f\u30a4\u30f3\u30bf\u30d7\u30ea\u30bf\u3068\u3044\u3046\u3053 &#8230;","protected":false},"author":5,"featured_media":6177,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[23],"tags":[],"class_list":["post-6175","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-cpp-school3"],"aioseo_notices":[],"jetpack_featured_media_url":"https:\/\/theolizer.com\/wordpress\/wp-content\/uploads\/2019\/05\/school3-9.jpg","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/theolizer.com\/wp-json\/wp\/v2\/posts\/6175","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/theolizer.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/theolizer.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/theolizer.com\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/theolizer.com\/wp-json\/wp\/v2\/comments?post=6175"}],"version-history":[{"count":0,"href":"https:\/\/theolizer.com\/wp-json\/wp\/v2\/posts\/6175\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/theolizer.com\/wp-json\/wp\/v2\/media\/6177"}],"wp:attachment":[{"href":"https:\/\/theolizer.com\/wp-json\/wp\/v2\/media?parent=6175"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/theolizer.com\/wp-json\/wp\/v2\/categories?post=6175"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/theolizer.com\/wp-json\/wp\/v2\/tags?post=6175"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}