Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the really-simple-ssl domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /home3/c2planpf/public_html/wp-includes/functions.php on line 6114

Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the wordpress-seo domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /home3/c2planpf/public_html/wp-includes/functions.php on line 6114

Warning: Cannot modify header information - headers already sent by (output started at /home3/c2planpf/public_html/wp-includes/functions.php:6114) in /home3/c2planpf/public_html/wp-includes/rest-api/class-wp-rest-server.php on line 1893

Warning: Cannot modify header information - headers already sent by (output started at /home3/c2planpf/public_html/wp-includes/functions.php:6114) in /home3/c2planpf/public_html/wp-includes/rest-api/class-wp-rest-server.php on line 1893

Warning: Cannot modify header information - headers already sent by (output started at /home3/c2planpf/public_html/wp-includes/functions.php:6114) in /home3/c2planpf/public_html/wp-includes/rest-api/class-wp-rest-server.php on line 1893

Warning: Cannot modify header information - headers already sent by (output started at /home3/c2planpf/public_html/wp-includes/functions.php:6114) in /home3/c2planpf/public_html/wp-includes/rest-api/class-wp-rest-server.php on line 1893

Warning: Cannot modify header information - headers already sent by (output started at /home3/c2planpf/public_html/wp-includes/functions.php:6114) in /home3/c2planpf/public_html/wp-includes/rest-api/class-wp-rest-server.php on line 1893

Warning: Cannot modify header information - headers already sent by (output started at /home3/c2planpf/public_html/wp-includes/functions.php:6114) in /home3/c2planpf/public_html/wp-includes/rest-api/class-wp-rest-server.php on line 1893

Warning: Cannot modify header information - headers already sent by (output started at /home3/c2planpf/public_html/wp-includes/functions.php:6114) in /home3/c2planpf/public_html/wp-includes/rest-api/class-wp-rest-server.php on line 1893

Warning: Cannot modify header information - headers already sent by (output started at /home3/c2planpf/public_html/wp-includes/functions.php:6114) in /home3/c2planpf/public_html/wp-includes/rest-api/class-wp-rest-server.php on line 1893
{"id":987,"date":"2021-03-14T09:06:50","date_gmt":"2021-03-14T09:06:50","guid":{"rendered":"https:\/\/c2plabs.com\/?p=987"},"modified":"2022-01-14T16:45:36","modified_gmt":"2022-01-14T16:45:36","slug":"introduction-to-cmake-build-system-and-cmakelists-file","status":"publish","type":"post","link":"https:\/\/c2plabs.com\/blog\/2021\/03\/14\/introduction-to-cmake-build-system-and-cmakelists-file\/","title":{"rendered":"Introduction to CMake build system and CMakeLists file."},"content":{"rendered":"\n

CMake is the meta build system widely used for C and C++ projects and it generates build scripts for target platform. CMake is platform independent and generates Makefile on the Linux.<\/p>\n\n\n\n

When the cmake <\/strong>command is launched it parses an instruction file called CMakeLists.txt. The name of the file is case sensitive and should be CMakeLists.txt<\/em><\/strong> for cmake to be able to parse it.<\/p>\n\n\n\n

  1. Build simple executable file from source files:<\/strong><\/li><\/ol>\n\n\n\n

    Lets create a simple CMakeLists.txt file which builds C++ program with two source files.<\/p>\n\n\n\n

    In general very first instruction used in CMakeList.txt file is specifying the minimum cmake version required for our project. When cmake is run if the version is not matched it will throw fatal error.<\/p>\n\n\n\n

    cmake_minimum_required( VERSION 3.5 )<\/code><\/pre>\n\n\n\n

    Next instruction is declaring the name of the project and programming language C or C++ etc…<\/p>\n\n\n\n

    project (cmake_c2p LANGUAGES CXX)<\/code><\/pre>\n\n\n\n

    In the above instruction CXX specifies C++ and simple C can be used for C language. CMake supports C, C++, CUDA, Fortran etc. By default C, C++ languages are supported if there is no LANGUAGE instruction is specified.<\/p>\n\n\n\n

    Next instruction is create a build target, in this case it is an executable which is generated by compiling and linking two C++ files.<\/p>\n\n\n\n

    add_executable (hello_cmake hello_1.cpp hello_2.cpp)\n<\/code><\/pre>\n\n\n\n

    <\/p>\n\n\n\n

    Now we assume that source file and CMakeLists.txt file are in the same directory. To build using cmake create build<\/strong><\/em> directory and goto that directory using the below commands. This is one more feature\/advantage of CMake which builds out side of the source directory. The advantage with this kind of build system is it will not mess up the source directory with build files.<\/p>\n\n\n\n

    The example C++ code we are using for this blog is given below.<\/p>\n\n\n\n

    \/\/Hello_1.hpp file content\nint largest(int num1, int num2);\n\n\/\/hello_1.cpp file content\n#include <iostream>\n#include \"hello_1.hpp\"\n\nusing namespace std;\nint main() {\n   cout << \"The largest number is: \" << largest(34,65) << endl;\n}\n\n\n\/\/hello_2.cpp file content\n\n#include \"hello_1.hpp\"\n\nint largest(int num1, int num2) {\n        return num1 > num2 ? num1:num2;\n}\n\n<\/code><\/pre>\n\n\n\n

    <\/p>\n\n\n\n

    mkdir build\ncd build\n\ndemo@c2plabs:~\/CMAKE_BLOG\/build$ cmake --build .\n[ 33%] Linking CXX executable hello_cmake\n[100%] Built target hello_cmake\n<\/code><\/pre>\n\n\n\n

    Above commands show the build process using cmake, when we run the cmake with build options it generates executable “hello_cmake” as specified in add_executable instruction. The list of files generated by cmake on Linux platform is as blow<\/p>\n\n\n\n

    • Makefile :<\/strong> makefile generated which contains instructions for make command<\/li><\/ul>\n\n\n\n
      • CMakeCache.txt:<\/strong> The is cache file consists of instructions used by cmake when we re-run it. <\/li><\/ul>\n\n\n\n
        • CMakeFiles:<\/strong> Directory which contains temporary files, used by CMake for detecting the operating system, compiler, and so on. <\/li><\/ul>\n\n\n\n
          • cmake_install.cmake<\/strong>: A CMake script handling install rules, which is used at install time.<\/li><\/ul>\n\n\n\n
            • And executable file as instructed in add_executable instruction.<\/li><\/ul>\n\n\n\n

              <\/p>\n\n\n\n

              <\/p>\n","protected":false},"excerpt":{"rendered":"

              CMake is the meta build system widely used for C and C++ projects and it generates build scripts for target platform. CMake is platform independent and generates Makefile on the Linux. When the cmake command is launched it parses an instruction file called CMakeLists.txt. The name of the file is case sensitive and should be […]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[1],"tags":[97,95,96],"class_list":["post-987","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-add_executable","tag-cmake","tag-cmakelists-txt"],"yoast_head":"\nIntroduction to CMake build system and CMakeLists file. - C2P Labs<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/c2plabs.com\/blog\/2021\/03\/14\/introduction-to-cmake-build-system-and-cmakelists-file\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Introduction to CMake build system and CMakeLists file. - C2P Labs\" \/>\n<meta property=\"og:description\" content=\"CMake is the meta build system widely used for C and C++ projects and it generates build scripts for target platform. CMake is platform independent and generates Makefile on the Linux. When the cmake command is launched it parses an instruction file called CMakeLists.txt. The name of the file is case sensitive and should be […]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/c2plabs.com\/blog\/2021\/03\/14\/introduction-to-cmake-build-system-and-cmakelists-file\/\" \/>\n<meta property=\"og:site_name\" content=\"C2P Labs\" \/>\n<meta property=\"article:published_time\" content=\"2021-03-14T09:06:50+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-01-14T16:45:36+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\">\n\t<meta name=\"twitter:data1\" content=\"2 minutes\">\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebSite\",\"@id\":\"https:\/\/c2plabs.com\/#website\",\"url\":\"https:\/\/c2plabs.com\/\",\"name\":\"C2P Labs\",\"description\":\"concept 2 practice\",\"publisher\":{\"@id\":\"https:\/\/c2plabs.com\/#\/schema\/person\/295244afc7d5e3a58ea80101c8101cc9\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":\"https:\/\/c2plabs.com\/?s={search_term_string}\",\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/c2plabs.com\/blog\/2021\/03\/14\/introduction-to-cmake-build-system-and-cmakelists-file\/#webpage\",\"url\":\"https:\/\/c2plabs.com\/blog\/2021\/03\/14\/introduction-to-cmake-build-system-and-cmakelists-file\/\",\"name\":\"Introduction to CMake build system and CMakeLists file. - C2P Labs\",\"isPartOf\":{\"@id\":\"https:\/\/c2plabs.com\/#website\"},\"datePublished\":\"2021-03-14T09:06:50+00:00\",\"dateModified\":\"2022-01-14T16:45:36+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/c2plabs.com\/blog\/2021\/03\/14\/introduction-to-cmake-build-system-and-cmakelists-file\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/c2plabs.com\/blog\/2021\/03\/14\/introduction-to-cmake-build-system-and-cmakelists-file\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/c2plabs.com\/blog\/2021\/03\/14\/introduction-to-cmake-build-system-and-cmakelists-file\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"item\":{\"@type\":\"WebPage\",\"@id\":\"https:\/\/c2plabs.com\/\",\"url\":\"https:\/\/c2plabs.com\/\",\"name\":\"Home\"}},{\"@type\":\"ListItem\",\"position\":2,\"item\":{\"@id\":\"https:\/\/c2plabs.com\/blog\/2021\/03\/14\/introduction-to-cmake-build-system-and-cmakelists-file\/#webpage\"}}]},{\"@type\":\"Article\",\"@id\":\"https:\/\/c2plabs.com\/blog\/2021\/03\/14\/introduction-to-cmake-build-system-and-cmakelists-file\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/c2plabs.com\/blog\/2021\/03\/14\/introduction-to-cmake-build-system-and-cmakelists-file\/#webpage\"},\"author\":{\"@id\":\"https:\/\/c2plabs.com\/#\/schema\/person\/295244afc7d5e3a58ea80101c8101cc9\"},\"headline\":\"Introduction to CMake build system and CMakeLists file.\",\"datePublished\":\"2021-03-14T09:06:50+00:00\",\"dateModified\":\"2022-01-14T16:45:36+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/c2plabs.com\/blog\/2021\/03\/14\/introduction-to-cmake-build-system-and-cmakelists-file\/#webpage\"},\"wordCount\":395,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/c2plabs.com\/#\/schema\/person\/295244afc7d5e3a58ea80101c8101cc9\"},\"keywords\":[\"add_executable\",\"cmake\",\"CMakeLists.txt\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/c2plabs.com\/blog\/2021\/03\/14\/introduction-to-cmake-build-system-and-cmakelists-file\/#respond\"]}]},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/c2plabs.com\/#\/schema\/person\/295244afc7d5e3a58ea80101c8101cc9\",\"name\":\"c2plabs_admin\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/c2plabs.com\/#personlogo\",\"inLanguage\":\"en-US\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/e8e3edf05db9da81227973a2883d9d1b?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/e8e3edf05db9da81227973a2883d9d1b?s=96&d=mm&r=g\",\"caption\":\"c2plabs_admin\"},\"logo\":{\"@id\":\"https:\/\/c2plabs.com\/#personlogo\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","post_mailing_queue_ids":[],"_links":{"self":[{"href":"https:\/\/c2plabs.com\/wp-json\/wp\/v2\/posts\/987","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/c2plabs.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/c2plabs.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/c2plabs.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/c2plabs.com\/wp-json\/wp\/v2\/comments?post=987"}],"version-history":[{"count":7,"href":"https:\/\/c2plabs.com\/wp-json\/wp\/v2\/posts\/987\/revisions"}],"predecessor-version":[{"id":1158,"href":"https:\/\/c2plabs.com\/wp-json\/wp\/v2\/posts\/987\/revisions\/1158"}],"wp:attachment":[{"href":"https:\/\/c2plabs.com\/wp-json\/wp\/v2\/media?parent=987"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/c2plabs.com\/wp-json\/wp\/v2\/categories?post=987"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/c2plabs.com\/wp-json\/wp\/v2\/tags?post=987"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}