Author Topic: CMake Monorepo cbp Almost works but cant find Headers in include/ directories  (Read 214 times)

Offline stberryhill

  • Single posting newcomer
  • *
  • Posts: 1
Hi, I used the codeblocks cmake generator to generate a cbp for my cmake monorepo. It almost works flawlessly! However there are 2 issues.

1. Headers in the subprojects include/ directories are not listed under "Headers" in the codeblocks UI.
2. Some CMake tasks such as copying a resources folder do not pass successfully because presumably the directories get messed up by the codeblocks generator.

Is there anything I should be doing specifically so the project just works? I am generating the cbp in MY_PROJECT_ROOT/build-codeblocks/myproject.cbp. I would like to still have the CMake setup since it seems more portable than CodeBlocks own build system. Honestly, surprised it doesn't support CMake projects out of the box or have a good plugin for this.

Out of curiousity, is there any standard approach for having a cross platform IDE-independent build system that works out of the box with CodeBlocks?

Here's my root CMakeLists:
Code
cmake_minimum_required(VERSION 3.19)
project(myproj)

set(CMAKE_C_STANDARD 90)
set(CMAKE_C_STANDARD_REQUIRED ON)

# Add debug information
set(CMAKE_BUILD_TYPE Debug)
set(CMAKE_C_FLAGS_DEBUG "-g -O0")

if(DEFINED ENV{VCPKG_ROOT})
    set(CMAKE_TOOLCHAIN_FILE "$ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake" CACHE STRING "")
endif()

add_subdirectory(libraries/libfoo)
add_subdirectory(apps/myapp)



And here is the libfoo CMakeLists
Code
cmake_minimum_required(VERSION 3.19)

project(libfoo)

# Define implementation-specific options for libfoo
option(USE_VULKAN "Use Vulkan implementation in libfoo" OFF)
option(USE_OPENGL "Use OpenGL implementation in libfoo" ON)

# Ensure only one implementation is selected
if(USE_VULKAN AND USE_OPENGL)
    message(FATAL_ERROR "Cannot use both Vulkan and OpenGL implementations in libfoo at the same time.")
endif()

add_library(libfoo STATIC
    src/libfoo.c
)

# Include the platform-specific source folder
if(WIN32)
    target_sources(libfoo PRIVATE src/win/libfoo_win.c)
elseif(APPLE)
    target_sources(libfoo PRIVATE src/mac/libfoo_mac.c)
elseif(UNIX)
    target_sources(libfoo PRIVATE src/linux/libfoo_linux.c)
endif()



# Include the implementation-specific source folder
if(USE_VULKAN)
    message(STATUS "Including Vulkan source files in libfoo")
    target_sources(libfoo PRIVATE src/vulkan/libfoo_vulkan.c)
elseif(USE_OPENGL)
    message(STATUS "Including OpenGL source files in libfoo")
    target_sources(libfoo PRIVATE src/opengl/libfoo_opengl.c)
else()
    message(FATAL_ERROR "Neither USE_VULKAN nor USE_OPENGL is defined in libfoo!")
endif()

# Include the public headers
target_include_directories(libfoo PUBLIC
    ${CMAKE_CURRENT_SOURCE_DIR}/include
)

# Define LIBFOO_EXPORTS for the libfoo target
target_compile_definitions(libfoo PRIVATE LIBFOO_EXPORTS)

find_package(glfw3 CONFIG REQUIRED)
target_link_libraries(libfoo PRIVATE glfw)

# Setup tests
enable_testing()

# Find all .c files in tests/
file(GLOB TEST_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/tests/*.c")

foreach(test_src ${TEST_SOURCES})
    get_filename_component(test_name ${test_src} NAME_WE)
    add_executable(${test_name} ${test_src})
#    target_link_libraries(${test_name} PRIVATE libfoo libbar)
    add_test(NAME ${test_name} COMMAND ${test_name})
endforeach()



folder structure:
MY_PROJECT_ROOT/libraries/libfoo
2 folders inside - src & include
« Last Edit: Today at 04:51:29 am by stberryhill »

Offline christo

  • Developer
  • Multiple posting newcomer
  • *****
  • Posts: 72
For point 1, could you please try adding the header files also to target_sources?

Out of curiousity, is there any standard approach for having a cross platform IDE-independent build system that works out of the box with CodeBlocks?

C::B supports external makefile projects. Please see wiki

As per manual, ProjectsImporter plugin imports foreign projects and workspaces from Dev-C++, MSVC6, MSVC7, and MSVC8 for use as a Code::Blocks project. It does not support CMake yet.