My project is a game engine, and it currently looks something like this:
/build
/engine
/include
/engine.h
/src
/enginepch.h
...
/vendor
/header_only
/include
/header1.h
...
/need_to_compile
...
CMakeLists.txt
/testbed
/stuffForTestingEngine
CMakeLists.txt
CMakeLists.txt
My includePath has engine/vendor/**
and engine/src/**
and I’m doing all my coding in VSCode with the C/C++ ms-vscode extension.
./engine/CMakeLists.txt
is as such:
project(engine)
# config "need_to_compile
# ...and I configured everything that needed compilation here: glm, glad, openal, libpng and glfw.
# linking
add_library(engine SHARED
src/core/application.cpp
src/core/engine.cpp
# etc. These are all my source files.
)
add_library(engine::engine ALIAS engine)
target_include_directories(engine PUBLIC
${engine_SOURCE_DIR}/include
)
target_include_directories(engine PRIVATE
${PROJECT_SOURCE_DIR}/vendor
)
target_precompile_headers(engine PRIVATE src/enginepch.h)
target_link_libraries(engine PUBLIC
glfw
png
openal
glad
glm::glm
)
This setup and pch.h file worked great with all the std stuff, such as <chrono>
and <string>
.
As soon as I tried including any header_only lib in my pch file, it broke. For example:
# This works!
#include <glm/glm.hpp>
# These didn't.
#include <spdlog/spdlog.h>
#include <entt/entt.h>
#include <stb_image/stb_image.h>
I tried many variations of the #include statement, such as “lib”, “lib.h”, “lib/lib.h”, , <lib/lib.h> and <lib.h>. None worked.
I tried including these header_only libs in CMakeLists, either by linking to an alias or adding a include_directory, but that didn’t work.
I suspect that my setup is wrong, or that I have a fatal misunderstanding of what CMake/the compiler is doing.