Thread: CMake Help (losing my mind :(()

  1. #1
    Registered User
    Join Date
    Jul 2019
    Posts
    11

    CMake Help (losing my mind :(()

    Hello AllVery basic question that I spent many hours. I am using codeblock IDE and cmake. I have a file layout as "documents/exp/asrc.cpp" and "documents/exp/aheader.h". Source and header files in the same folder. The problem is no matter what I tried in CMakeLists, Cmake-gui did not see the header files.I tried almot everything like
    Code:
     cmake_minimum_required(VERSION 2.4)
    project(aproject)
    include_directories(${PROJECT_SOURCE_DIR})
    include_directories(${CMAKE_SOURCE_DIR})
    target_include_directories(atarget ${CMAKE_SOURCE_DIR})
    add_executable(app asrc.cpp)
    To be honest I did not understand anything about cmake as there is not much resource and completely angry as it is a very basic step . It only got .cpp (printed to json-output) . Something is missing ??
    Last edited by scorp08; 09-25-2019 at 07:35 AM.

  2. #2
    Informer -Adrian's Avatar
    Join Date
    Jan 2013
    Posts
    817
    First of all, let me assure you that your anger is warranted. CMake documentation is an utter mess (the entire world agrees), and CMake itself doesn't have a good approach/syntax either – it's just that it's the best choice right now due to inertia.

    Now regarding Codeblocks, is it even intended that you manually edit your CMakeLists.txt? Doesn't the IDE take care of that, interfering with your manual edits?

    Regarding your example, try:
    Code:
    cmake_minimum_required(VERSION 3.0)
    
    project(foo)
    
    add_executable(app
        "documents/exp/aheader.h"
        "documents/exp/asrc.cpp"
    )
    If you want your header files recognized as dependencies, you need to add them to your target. This is not necessary for successful compilation though (the .cpp implementation suffices)

    Here are two resources that might help in the future regarding CMake:

    Last edited by -Adrian; 09-25-2019 at 08:29 AM.

  3. #3
    Registered User
    Join Date
    Jul 2019
    Posts
    11
    Thanks but did not worked. I tried other stuff but none worked like :
    Code:
    cmake_minimum_required(VERSION 3.1)
    project(my_project)
    set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
    add_library(calclib STATIC mystruct.h struct_cagir.cpp)
    add_executable(my_exe struct_cagir.cpp)
    target_link_libraries(my_exe PUBLIC calclib)
    Quote Originally Posted by -Adrian View Post
    First of all, let me assure you that your anger is warranted. CMake documentation is an utter mess (the entire world agrees), and CMake itself doesn't have a good approach/syntax either – it's just that it's the best choice right now due to inertia.Now regarding Codeblocks, is it even intended that you manually edit your CMakeLists.txt? Doesn't the IDE take care of that, interfering with your manual edits?Regarding your example, try:
    Code:
    cmake_minimum_required(VERSION 3.0)
    project(foo)
    add_executable(app    "documents/exp/aheader.h"    "documents/exp/asrc.cpp")
    If you want your header files recognized as dependencies, you need to add them to your target. This is not necessary for successful compilation though (the .cpp implementation suffices)Here are two resources that might help in the future regarding CMake:
    Last edited by scorp08; 09-28-2019 at 05:25 AM.

  4. #4
    Informer -Adrian's Avatar
    Join Date
    Jan 2013
    Posts
    817
    Did you pass the paths relative to your CMakeLists.txt as I showed in my example? Also, what do you do to invoke CMake? Looks like one needs to create the Codeblocks project through the CLI first, Codeblocks cannot itself invoke CMake.

    Also, why don't you just use Codeblocks without touching CMake?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Segmentation fault: I am losing my mind :(
    By Median in forum C Programming
    Replies: 31
    Last Post: 11-06-2012, 01:29 PM
  2. Pipelines - please help, 6 hours and I am losing my mind.
    By Johnny_010 in forum C Programming
    Replies: 4
    Last Post: 04-04-2012, 02:06 PM
  3. Replies: 6
    Last Post: 03-18-2012, 10:11 PM
  4. Don't know if I'm losing my mind...
    By Invincible in forum C++ Programming
    Replies: 19
    Last Post: 05-26-2002, 11:27 PM
  5. Lost source... losing mind...
    By doubleanti in forum A Brief History of Cprogramming.com
    Replies: 6
    Last Post: 10-27-2001, 12:31 AM

Tags for this Thread