# Minimum required CMake version
cmake_minimum_required(VERSION 3.0)
# Project name
project(MyStaticLib)
# Create a static library
add_library(MyStaticLib STATIC source1.cpp source2.cpp)# Include the library directory
target_include_directories(MyProgram PRIVATE "${CMAKE_CURRENT_BINARY_DIR}")
# Create an executable
add_executable(MyProgram main.cpp)
# Link the executable with the static library
target_link_libraries(MyProgram PRIVATE MyStaticLib)# Create a shared library
add_library(MySharedLib SHARED source1.cpp source2.cpp)# Find an external library (replace with the actual library)
find_package(Threads REQUIRED)
# Include the library directory
target_include_directories(MyProgram PRIVATE "${CMAKE_THREAD_INCLUDE_DIRS}")
# Link the executable with the external library
target_link_libraries(MyProgram PRIVATE Threads::Threads)if(CMAKE_C_COMPILER_ID MATCHES "GNU")
target_compile_properties(MyLib PROPERTIES CVISIBILITY_PRESET "hidden")
endif()target_link_libraries(MyProgram PRIVATE MyLib LINK_OPTIONS "-Wl,-rpath,/path/to/additional/libraries")cmake_minimum_required(VERSION 3.0)
project(MyMultithreadedApp)
# Find pthread library (replace with the actual find_package call for your target platform)
find_package(Threads REQUIRED)
# Include directories (adjust based on your header locations)
target_include_directories(MyProgram PRIVATE
"${CMAKE_CURRENT_BINARY_DIR}" # Include current directory for project headers
"${CMAKE_THREAD_INCLUDE_DIRS}" # Include directory from Threads package
)
# Source files (replace with your actual source files)
add_executable(MyProgram main.cpp worker.cpp)
# Link with pthread library
target_link_libraries(MyProgram PRIVATE Threads::Threads)
# Platform-specific flags (optional)
if(CMAKE_SYSTEM_NAME MATCHES "Linux")
target_link_libraries(MyProgram PRIVATE "-lpthread") # Link with pthread on Linux
endif()
if(CMAKE_SYSTEM_NAME MATCHES "Darwin")
target_link_libraries(MyProgram PRIVATE "-framework pthread") # Link with pthread on macOS
endif()