Reputation:
I have two cmake files:
CMakeLists.txt:
cmake_minimum_required(VERSION 3.13)
project(as_math_engine)
set(CMAKE_CXX_STANDARD 14)
include_directories(include/as_math_engine)
add_library(as_math_engine evaluable.h)
add_subdirectory(tests)
tests/CMakeLists.txt:
include_directories(libs)
add_executable(as_math_engine_tests src/main.cpp)
And I have this include/as_math_engine/evaluable.h
file but, CMake tells me:
Cannot find source file: evaluable.h
Why is it? And how can I solve this problem?
Upvotes: 0
Views: 2021
Reputation: 3554
include_directories()
is best used to set include paths for multiple targets within a project, target_include_directories()
is usually preferred.
There are probably better ways of setting up as_math_engine
if it is going to be a header-only library.
You also need to use add_library(as_math_engine include/as_math_engine/evaluable.h)
because the add_library()
doesn't search for files.
Header Only Library shows how to set this up and use it to avoid these kinds of problems.
Alternatively delete both include_directories()
and use target_include_directories(as_math_engine_tests PRIVATE "${CMAKE_SOURCE_DIR}/include/as_math_engine" libs)
so that the as_math_engine_tests
uses the proper include path.
Upvotes: 1