Reputation: 3
I have C++ source code in following hierarchy
main.cxx
CMakeLists.txt
someDirectory/myClass.cxx
someDirectory/myClass.h
My CMakeLists.txt is as follows
cmake_minimum_required(VERSION 2.8)
project(cmakePjt)
include_directories(someDirectory)
add_executable(cmakePjt main.cxx)
My main.cxx includes myClass as follows
#include "myClass.h"
And the above works! But I want to include myClass in my main.cxx as follows and how should I change my CMakeLists.txt for that?
#include "myLibName/myClass.h"
Upvotes: 0
Views: 187
Reputation: 141000
There is nothing CMakeLists can do. You have to actually create an existing actual directory with the name myLibName
, move the .h file to that directory, and add the containing directory of that directory to include the search path.
Your project may look for example like this:
main.cxx
CMakeLists.txt
myLibName/src/myClass.cxx
myLibName/include/myLibName/myClass.h
myLibName/CMakeLists.txt
Where:
# myLibName/CMakeLists.txt
add_library(myLibName src/myClass.cxx)
target_include_directories(myLibName PUBLIC ./include)
# CMakeLists.txt
add_subdirectory(myLibName)
add_executable(cmakePjt mina.cxx)
target_link_libraries(cmakePjt PRIVATE myLibName)
Upvotes: 1