0

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:

  1. use PUBLIC- for including that library in both my cpp and header files.
  2. use PRIVATE - for including that library only in my cpp files.
  3. 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

  • You seem not to be asking any specific programming question. A broad question "what is the main idea" is too broad for stackoverflow and you seem to be not facing any specific problem. Please read [how-to-ask](https://stackoverflow.com/help/how-to-ask) and [on-topic](https://stackoverflow.com/help/on-topic). `What is the main idea?` You just laid out the main idea in 3 points above. `How can I improve my CMake file with that feature?` Use it. `can it be used in both static library and dynamic one?` Yes. – KamilCuk Jul 09 '20 at 11:00
  • Welcome to Stack Overflow! You might consider reading the CMake [documentation](https://cmake.org/cmake/help/latest/manual/cmake-buildsystem.7.html#build-specification-and-usage-requirements) for Usage Requirements to better understand how these scoping arguments can be used. However, I also agree that your post needs a more focused question. – Kevin Jul 09 '20 at 12:58

0 Answers0