| 1 |
cmake_minimum_required(VERSION 3.10) |
| 2 |
project(kingsley LANGUAGES CXX) |
| 3 |
|
| 4 |
# Set C++14 standard |
| 5 |
set(CMAKE_CXX_STANDARD 14) |
| 6 |
set(CMAKE_CXX_STANDARD_REQUIRED ON) |
| 7 |
|
| 8 |
# Enable optimization with debugging symbols |
| 9 |
set(CMAKE_BUILD_TYPE RelWithDebInfo) |
| 10 |
# set(CMAKE_BUILD_TYPE Debug) |
| 11 |
|
| 12 |
# Generate position-independent code; required for shared libraries on many platforms |
| 13 |
set(CMAKE_POSITION_INDEPENDENT_CODE ON) |
| 14 |
|
| 15 |
# Common definitions |
| 16 |
add_definitions(-DNDEBUG -D_REENTRANT=1) |
| 17 |
|
| 18 |
# Include directories |
| 19 |
include_directories(. ../.. ../../util) |
| 20 |
|
| 21 |
include(FetchContent) |
| 22 |
FetchContent_Declare( |
| 23 |
printf |
| 24 |
GIT_REPOSITORY https://github.com/emeryberger/printf.git |
| 25 |
GIT_TAG master |
| 26 |
) |
| 27 |
FetchContent_MakeAvailable(printf) |
| 28 |
include_directories(${printf_SOURCE_DIR}) |
| 29 |
|
| 30 |
set(UNIX_SOURCES |
| 31 |
../../wrappers/gnuwrapper.cpp |
| 32 |
libkingsley.cpp |
| 33 |
${printf_SOURCE_DIR}/printf.cpp |
| 34 |
) |
| 35 |
|
| 36 |
set(MACOS_SOURCES |
| 37 |
../../wrappers/macwrapper.cpp |
| 38 |
libkingsley.cpp |
| 39 |
${printf_SOURCE_DIR}/printf.cpp |
| 40 |
) |
| 41 |
|
| 42 |
if(APPLE) |
| 43 |
set(ALL_SOURCES ${MACOS_SOURCES}) |
| 44 |
else() |
| 45 |
set(ALL_SOURCES ${UNIX_SOURCES}) |
| 46 |
endif() |
| 47 |
|
| 48 |
# Create shared library |
| 49 |
add_library(kingsley SHARED ${ALL_SOURCES}) |
| 50 |
|
| 51 |
# Let CMake handle platform-specific library settings |
| 52 |
set_target_properties(kingsley PROPERTIES |
| 53 |
VERSION 1.0.0 |
| 54 |
SOVERSION 1) |
| 55 |
|
| 56 |
# Add threading support if needed |
| 57 |
find_package(Threads) |
| 58 |
if(Threads_FOUND) |
| 59 |
target_link_libraries(kingsley Threads::Threads) |
| 60 |
endif() |