I recently saw the use of PUBLIC / PRIVATE in the CMake dependency. For what I have learned ,if I want to build a shared library which use another library then:
- use PUBLIC- for including that library in both my cpp and header files.
- use PRIVATE - for including that library only in my cpp files.
- use INTERFACE - for including that library only in my header file.
What is the main idea ? How can I improve my CMake file with that feature? can it be used in both static library and dynamic one?
Here is my CMake file:
cmake_minimum_required (VERSION 2.8)
set (CMAKE_CXX_FLAGS "-Weverything -std=c++11 -Wall -Wextra -g")
set (CMAKE_CXX_STANDARD 11)
set (CMAKE_BUILD_TYPE Debug)
project (internal)
set (internal VERSION 0.2)
file (GLOB internal_src
"utils.cpp"
"inspection.cpp"
"ct_proxy_if.cpp"
"stats.cpp")
file (GLOB main_SRC
${internal_src}
"mainW.cpp")
add_library(${PROJECT_NAME} STATIC ${internal_src})
target_link_libraries(internal infrastructures pthread jsoncpp ssl crypto)
I am using static library named infrastructures ( a library which my colleague developed)
I read this post CMake target_link_libraries Interface Dependencies