Contents in outer CMakeList.txt:
cmake_minimum_required(VERSION 3.16)
PROJECT(HELLO)
ADD_SUBDIRECTORY(lib bin)
Contents of CMakeLists.txt in lib:
SET(LIBHELLO_SRC hello.cpp)
ADD_LIBRARY(hello SHARED ${
LIBHELLO_SRC})
hello.h:
hello.cpp:
ADD_LIBRARY
ADD_LIBRARY(hello SHARED ${LIBHELLO_SRC})
- hello: is the library name, the generated name will be preceded by lib, and the final generated file is libhello.so
- SHARED: dynamic library STATIC, static library
- $(LIBHELLO_SRC): source file