{"id":1015,"date":"2022-08-30T15:10:58","date_gmt":"2022-08-30T15:10:58","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/09\/cmake-setting-up-release-and-debug-version-and-flags-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:10:58","modified_gmt":"2022-08-30T15:10:58","slug":"cmake-setting-up-release-and-debug-version-and-flags-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/cmake-setting-up-release-and-debug-version-and-flags-collection-of-common-programming-errors\/","title":{"rendered":"CMake Setting up Release and Debug version and Flags-Collection of common programming errors"},"content":{"rendered":"<p>I am new to CMake and I am trying to get my project compiling. The project creates a few static libraries and a few executables.<\/p>\n<p>Below is the example of the file structure that I have.<\/p>\n<p>PROJECT<\/p>\n<ul>\n<li>\n<p>build\/linux<\/p>\n<ol>\n<li>CMakeLists.txt (Main CMakelist file)<\/li>\n<\/ol>\n<\/li>\n<li>\n<p>build\/linux\/Release (Should contain the release libraries and files)<\/p>\n<\/li>\n<li>\n<p>build\/linux\/Debug (Should contain the debug version of the files)<\/p>\n<\/li>\n<li>\n<p>SRC<\/p>\n<ol>\n<li>subProject_1<br \/>\n.cpp (all source files) and CMakeLists.txt 1 for this folder (creating a static library)<\/li>\n<li>subproject_2<br \/>\n.cpp (all source files) and CMakeLists.txt 2 for this folder (creating a static library)<\/li>\n<li>subproject_3<br \/>\n.cpp (all source files) and CMakeLists.txt 3 for this folder (creating the executable)<\/li>\n<\/ol>\n<\/li>\n<li>\n<p>Include<\/p>\n<ol>\n<li>subProject_1<br \/>\n.h (all the header files)<\/li>\n<li>subProject_2<br \/>\n.h (all the header files)<\/li>\n<li>subProject_3<br \/>\n.h (all the header files)<\/li>\n<\/ol>\n<\/li>\n<\/ul>\n<p>Main CMakeLists.txt<\/p>\n<pre><code>cmake_minimum_required(VERSION 2.6)\nSET(CMAKE_CXX_COMPILER \"g++\")\nProject(ort)\n\n#set the source and header directories location\nset(ORT_HEADER_DIRECTORY \"..\/..\/include\") #include folder structure explained above\nset(ORT_SOURCE_DIRECTORY \"..\/..\/src\")\nset(ORT_BINARY_DIRECTORY \"..\/..\/lib\")  # lib folder to contain all the libraries\n\nset (CMAKE_CURRENT_BINARY_DIR \".\")\n\n#Include the library packages\ninclude_directories(\"\/usr\/include\/wx-2.8\")\ninclude_directories(\"\/usr\/local\/cuda\/include\") and so on\n\n\n#set the names of all the projects (for creating the libraries)\nSET(PROJECT_NAMES \"log\" \"data\" \"cc\")\n\nforeach(PROJECT_NAME ${PROJECT_NAMES})\n     # Create the cmake related files in the out folder so that the libraries can be\n     # copied to the lib folder\n     add_subdirectory( \"{ORT_SOURCE_DIRECTORY}\/${PROJECT_NAME}\" \"${CMAKE_CURRENT_BINARY_DIR}\/out\/${PROJECT_NAME}\"\n\nendforeach(PROJECT_NAME ${PROJECT_NAMES})\n\n#set the names of all the projects (for creating the libraries)\nSET(EXECUATALE_PROJECTS \"metadata\" )\n\nforeach(EXECUATALE_PROJECT ${EXECUATALE_PROJECTS})\n     # Create the cmake related files in the out folder so that the libraries can be\n     # copied to the lib folder\n     add_subdirectory( \"{ORT_SOURCE_DIRECTORY}\/${EXECUATALE_PROJECT}\" \"${CMAKE_CURRENT_BINARY_DIR}\/out\/${EXECUATALE_PROJECT}\"\n\nendforeach(EXECUATALE_PROJECT ${EXECUATALE_PROJECTS})\n<\/code><\/pre>\n<p>CMakeLists.txt file for log directory (the same logic I have used for cc and data projects)<\/p>\n<pre><code>SET (CMAKE_CXX_FLAGS \" -g -Wall -pThread\")\ninclude_directories(${ORT_HEADER_DIRECTORY})\nSET(LOG_SOURCE a.cpp b.cpp c.cpp)\nADD_LIBRARY(log_d ${LOG_SOURCE})\ntarget_link)libraries(log_d cc_d data_d)\n<\/code><\/pre>\n<p>metadata CMakeLists.txt file (creating the executable project)<\/p>\n<pre><code>SET (CMAKE_CXX_FLAGS \" -g -Wall -pThread\")\nFIND_PACKAGE(wxWidgets)\nIF(wxWidgets_FOUND)\n        INCLUDE(${wxWidgets_USE_FILE})\nENDIF(wxWidgets_FOUND)\n\nInclude_Directories(${wxWidgets_INCLUDE_DIRS})\ninclude_directories(${ORT_HEADER_DIRECTORY})\ninclude_directories(\"\/usr\/ort\/lib\/unixODBC\/include\")\n\nSET(META_SOURCE meta.cpp data.cpp)\n\nADD_EXECUTABLE(meta_d ${META_SOURCE })\nTARGET_LINK_LIBRARIES(meta_d log_d data_d)\n<\/code><\/pre>\n<p>Currently with this piece I can successfully generate the required libraries in the build\/linux\/out folder. I did create the release and debug folder and did try to build the same. The files are created and build in the respective RElease or Debug folder. cd Release<\/p>\n<p>cmake -DCMAKE_BUILD_TYPE=Release ..<\/p>\n<p>make<\/p>\n<p>Question: 1) Since, the project can be build both at the build\/linux level as well as build\/linux\/Release build\/linux\/Debug level, Is there a way by which the project can be compiled only at the build\/linux level based on the release or debug option provided(In addition, the files are to placed in the debug or release folder based on a the option specified).<\/p>\n<p>i.e. I would like to do cmake -DCMAKE_BUILD=Release . on the build\/linux level and not the release debug level.<\/p>\n<p>I did try to run with the below option at the build\/linux level<\/p>\n<p>cmake -DCMAKE_BUILD_TYPE=Debug<\/p>\n<p>but I got an error message Unknown argument specified. Can you please let me know how can I set up this configuration so that later on I can integrate the same to Eclipse<\/p>\n<p>2) I would like to set the compilation flags for each project based on the debug and version specified, how can I do so ?<\/p>\n<p id=\"rop\"><small>Originally posted 2013-11-09 23:13:59. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>I am new to CMake and I am trying to get my project compiling. The project creates a few static libraries and a few executables. Below is the example of the file structure that I have. PROJECT build\/linux CMakeLists.txt (Main CMakelist file) build\/linux\/Release (Should contain the release libraries and files) build\/linux\/Debug (Should contain the debug [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1015","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1015","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=1015"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1015\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=1015"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=1015"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=1015"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}