I've been trying to understand CMake, and recently I've stumbled upon the CLion ide. So far, it's helped out a bit. In trying to get google test integrated with CLion, I cloned this github repo.
However, I don't understand how the .cpp files that hold the test method can "see" the header files for the library, when they are at the wrong relative path!
Calendar_check.cpp:
//
// Created by AK on 13/10/15.
//
#include "gtest/gtest.h"
#include "GregorianCalendar.h"
#include "JulianCalendar.h"
///Code that runs tests, not important for this question
However, the directory structure is set up like so:
Seeing how the project is set up, shouldn't the calendar_check.cpp
file's #include
statement read
#include "../../calendars/GregorianCalendar.h"
#include "../../calendars/JulianCalendar.h"
instead?
I know static libraries don't have header files with them, so I don't understand how the calendar_test.cpp
file can know where those headers are using the path they use.
Here are the CMakeLists.txt files:
Root:
cmake_minimum_required(VERSION 3.1)
project(Calendar)
#add_definitions(-std=c++11 --target=x86_64-linux-gnu)
#set(CMAKE_CXX_STANDARD 11)
set(SOURCE_FILES main.cpp)
add_executable(calendar_run ${SOURCE_FILES})
include_directories(calendars)
add_subdirectory(calendars)
add_subdirectory(calendars_tests)
target_link_libraries(calendar_run calendars)
root/calendars:
project(calendars)
set(HEADER_FILES
calendar_defs.h
General.h
GregorianCalendar.h
JulianCalendar.h
IslamicCalendar.h
HebrewCalendar.h
)
set(SOURCE_FILES
calendar_defs.cpp
Calendar.cpp
General.cpp
GregorianCalendar.cpp
JulianCalendar.cpp
IslamicCalendar.cpp
HebrewCalendar.cpp
)
add_library(calendars STATIC ${SOURCE_FILES} ${HEADER_FILES})
root/calendar_tests:
project(calendars_tests)
add_subdirectory(lib/gtest-1.7.0)
add_subdirectory(basic_tests)
root/calendar_tests/basic_tests:
include_directories(${gtest_SOURCE_DIR}/include ${gtest_SOURCE_DIR})
add_executable(runBasicCalendarTests
basic_check.cpp
calendar_check.cpp)
target_link_libraries(runBasicCalendarTests gtest gtest_main)
target_link_libraries(runBasicCalendarTests calendars)