i am learning about Cmake and i am facing a problem , in my main project i use the Fmt library and i can include it using angle brackets but i can't use angle brackets with my own libraries in my learning project
this is my directory
-build
-(contains building results)
-include
-zero
-zero.h
-zero.c++
-CmakeLists.txt
-main.c++
-CmakeLists.txt
zero/CmakeLists.txt:
cmake_minimum_required(VERSION 3.10)
set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib)
add_library(zero STATIC zero.c++ zero.h)
CmakeLists.txt:
cmake_minimum_required(VERSION 3.10)
project(MAIN)
add_subdirectory(${PROJECT_SOURCE_DIR}/include/zero)
set(EXECUTABLE_OUTPUT_PATH bin)
add_executable(main main.c++)
target_link_libraries(main include/zero)
message(${CMAKE_CURRENT_SOURCE_DIR})
target_include_directories(zero PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
)
main.c++:
#include <iostream>
//#include <zero/zero.h> this gives an error when i compile it with mingw32-make:
// No such file or directory #include <zero/zero.h>
//#include <include/zero/zero.h> thie also gives the same error
int main() {
std::cout<<"hello world! ";
}
i am trying to learn how to make a library accessible via the <> syntax
Edite:
i fixed it by changing the CmakeLists.txt to
cmake_minimum_required(VERSION 3.10)
project(MAIN)
add_subdirectory(${PROJECT_SOURCE_DIR}/include/zero)
set(EXECUTABLE_OUTPUT_PATH bin)
add_executable(main main.c++)
target_link_libraries(main zero)
message(${CMAKE_CURRENT_SOURCE_DIR})
target_include_directories(zero PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
)
my first mistake was that target_link_libraries(main include/zero)
is wrong beacuse the second argumant should be the target name not the path
second i changed ${CMAKE_CURRENT_SOURCE_DIR}/include
to ${CMAKE_CURRENT_SOURCE_DIR}
and it worked i don't know the reason of it and this is my question know: why this worked?
Edite2:
i changed ${CMAKE_CURRENT_SOURCE_DIR}
to ${CMAKE_CURRENT_SOURCE_DIR}/include
and changed <include/zero/zero.h>
to <zero/zero.h>
this also worked but i don't know the reason of neither of them