{"id":18665,"date":"2025-04-30T11:52:07","date_gmt":"2025-04-30T11:52:07","guid":{"rendered":"http:\/\/www.max-sperling.bplaced.net\/?p=18665"},"modified":"2025-05-05T12:44:05","modified_gmt":"2025-05-05T12:44:05","slug":"resolve-variables-with-cmake","status":"publish","type":"post","link":"http:\/\/www.max-sperling.bplaced.net\/?p=18665","title":{"rendered":"Resolve variables with CMake"},"content":{"rendered":"<h2>Structure<\/h2>\n<pre>\r\ncmake_example\/\r\n\u251c\u2500\u2500 CMakeLists.txt\r\n\u251c\u2500\u2500 config.hpp.in\r\n\u2514\u2500\u2500 main.cpp\r\n<\/pre>\n<hr \/>\n<h2>Files<\/h2>\n<p><strong>CMakeLists.txt<\/strong><\/p>\n<pre class=\"brush: plain; gutter: false; title: ; notranslate\" title=\"\">\r\ncmake_minimum_required(VERSION 3.10)\r\nproject(cmake_example)\r\n\r\nset(MY_CUSTOM_MESSAGE &quot;Hello from CMake&quot;)\r\n\r\nconfigure_file(\r\n    ${CMAKE_CURRENT_SOURCE_DIR}\/config.hpp.in\r\n    ${CMAKE_CURRENT_BINARY_DIR}\/config.hpp)\r\n\r\nadd_executable(${PROJECT_NAME} main.cpp)\r\n\r\ntarget_include_directories(${PROJECT_NAME}\r\n    PRIVATE ${CMAKE_CURRENT_BINARY_DIR})\r\n<\/pre>\n<p><strong>config.hpp.in<\/strong><\/p>\n<pre class=\"brush: cpp; gutter: false; title: ; notranslate\" title=\"\">\r\n#pragma once\r\n\r\n#define MY_MESSAGE &quot;@MY_CUSTOM_MESSAGE@&quot;\r\n<\/pre>\n<p><strong>main.cpp<\/strong><\/p>\n<pre class=\"brush: cpp; gutter: false; title: ; notranslate\" title=\"\">\r\n#include &quot;config.hpp&quot;\r\n#include &lt;iostream&gt;\r\n\r\nint main()\r\n{\r\n    std::cout &lt;&lt; &quot;Message: &quot; &lt;&lt; MY_MESSAGE &lt;&lt; std::endl;\r\n    return 0;\r\n}\r\n<\/pre>\n<hr \/>\n<h2>Execution<\/h2>\n<pre>\r\n$ cmake -S\"src\" -B\"build\"\r\n$ cmake --build build\r\n$ .\/build\/cmake_example\r\nMessage: Hello from CMake\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Structure cmake_example\/ \u251c\u2500\u2500 CMakeLists.txt \u251c\u2500\u2500 config.hpp.in \u2514\u2500\u2500 main.cpp Files CMakeLists.txt config.hpp.in main.cpp Execution $ cmake -S&#8221;src&#8221; -B&#8221;build&#8221; $ cmake &#8211;build<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false},"categories":[85],"tags":[],"_links":{"self":[{"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=\/wp\/v2\/posts\/18665"}],"collection":[{"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=18665"}],"version-history":[{"count":34,"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=\/wp\/v2\/posts\/18665\/revisions"}],"predecessor-version":[{"id":18699,"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=\/wp\/v2\/posts\/18665\/revisions\/18699"}],"wp:attachment":[{"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=18665"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=18665"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=18665"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}