ulib/CMakeLists.txt

111 lines
3.4 KiB
CMake
Raw Normal View History

2023-11-16 14:28:55 +08:00
cmake_minimum_required(VERSION 3.10)
2024-01-02 17:28:51 +08:00
project(ulib LANGUAGES CXX C VERSION 0.1.0)
2024-01-03 17:33:38 +08:00
set(CMAKE_C_STANDARD 11)
2024-01-03 16:50:48 +08:00
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_C_EXTENSIONS OFF)
set(CMAKE_CXX_STANDARD 11)
2023-11-16 14:28:55 +08:00
set(CMAKE_CXX_STANDARD_REQUIRED ON)
2023-12-05 10:06:05 +08:00
set(CMAKE_CXX_EXTENSIONS OFF)
2023-11-16 14:28:55 +08:00
option(ULIB_BUILD_TESTS "Build tests" OFF)
option(ULIB_SHARED_LIB "Build shared library" OFF)
2023-12-26 20:58:36 +08:00
option(ULIB_BUILD_EXAMPLES "Build examples" OFF)
2023-12-16 01:41:16 +08:00
2024-01-05 09:48:31 +08:00
if(NOT CMAKE_BUILD_TYPE)
2023-12-16 01:47:47 +08:00
set(CMAKE_BUILD_TYPE "Release")
# set stripped
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -s")
2023-12-16 01:41:16 +08:00
endif()
2023-12-16 01:47:47 +08:00
# add -static-libgcc and -static-libstdc++ to link flags
2023-12-16 01:41:16 +08:00
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
2024-01-05 09:48:31 +08:00
if(ULIB_SHARED_LIB)
add_library(${PROJECT_NAME} SHARED "")
else()
2023-12-28 11:45:07 +08:00
add_library(${PROJECT_NAME} STATIC ""
src/ulib/system/timer.cpp
src/ulib/system/timer.h)
2023-12-13 13:17:23 +08:00
endif()
target_sources(${PROJECT_NAME} PRIVATE
2024-01-02 17:28:51 +08:00
3party/mongoose/mongoose.c
2023-12-27 11:22:39 +08:00
src/ulib/base/location.h
src/ulib/base/location.cpp
2023-12-19 11:07:12 +08:00
src/ulib/concorrency/barrier.cpp
src/ulib/concorrency/barrier.h
src/ulib/concorrency/mutex.cpp
src/ulib/concorrency/mutex.h
src/ulib/concorrency/condition_variable.cpp
src/ulib/concorrency/condition_variable.h
2023-12-16 01:34:42 +08:00
src/ulib/concorrency/countdown_latch.cpp
src/ulib/concorrency/countdown_latch.h
src/ulib/concorrency/internal/mutex_impl.cpp
src/ulib/concorrency/internal/mutex_impl.h
src/ulib/concorrency/internal/condition_variable_impl.cpp
src/ulib/concorrency/internal/condition_variable_impl.h
src/ulib/concorrency/event.cpp
2023-12-27 11:22:39 +08:00
src/ulib/concorrency/event.h
src/ulib/system/thread.h
src/ulib/system/thread.cpp
2023-12-27 19:23:05 +08:00
src/ulib/system/thread_pool.h
src/ulib/system/thread_pool.cpp
2023-12-28 11:45:07 +08:00
src/ulib/system/timer.h
src/ulib/system/timer.cpp
2023-12-27 11:22:39 +08:00
)
2023-12-05 11:33:13 +08:00
find_package(Threads REQUIRED)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
2023-11-16 14:28:55 +08:00
2023-12-05 14:06:18 +08:00
## CMP0063
2024-01-05 09:48:31 +08:00
if(POLICY CMP0063)
2023-12-05 14:06:18 +08:00
cmake_policy(SET CMP0063 NEW)
2024-01-05 09:48:31 +08:00
endif()
if(POLICY CMP0048)
2023-12-05 14:06:18 +08:00
cmake_policy(SET CMP0048 NEW)
2024-01-05 09:48:31 +08:00
endif()
2023-12-05 14:06:18 +08:00
set(FMT_USE_CPP11 OFF CACHE BOOL "Use C++11" FORCE)
set(FMT_TEST OFF CACHE BOOL "Build tests" FORCE)
set(FMT_USE_CPP11 OFF CACHE BOOL "Use C++11" FORCE)
2023-12-05 11:33:13 +08:00
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/3party/fmt)
2024-01-06 20:29:49 +08:00
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/3party/sqlpp11)
2023-11-16 14:28:55 +08:00
2023-12-26 20:58:36 +08:00
set(JSONCPP_WITH_TESTS OFF)
set(JSONCPP_WITH_POST_BUILD_UNITTEST OFF)
set(JSONCPP_WITH_PKGCONFIG_SUPPORT OFF)
set(BUILD_SHARED_LIBS OFF)
set(BUILD_OBJECT_LIBS OFF)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/3party/jsoncpp)
2023-12-05 16:17:48 +08:00
target_sources(${PROJECT_NAME} PRIVATE
2023-12-05 11:33:13 +08:00
src/ulib/empty.cpp
src/ulib/log/logger.cpp
src/ulib/log/log.cpp
src/ulib/log/level.cpp
)
2024-01-06 20:44:29 +08:00
target_link_libraries(${PROJECT_NAME} PUBLIC fmt::fmt jsoncpp_static sqlpp11::sqlpp11)
2023-12-05 11:33:13 +08:00
target_compile_definitions(${PROJECT_NAME} PRIVATE ULIB_LIBRARY_IMPL)
2024-01-05 09:42:29 +08:00
target_include_directories(${PROJECT_NAME} PUBLIC
3party/inja
2024-01-05 09:48:31 +08:00
3party/mongoose
2024-01-05 13:47:50 +08:00
3party/nlohmann
2024-01-06 13:54:58 +08:00
3party/nonstd
2024-01-05 13:47:50 +08:00
3party/sigslot
2024-01-05 09:42:29 +08:00
src
)
2023-11-16 14:28:55 +08:00
2023-12-05 11:49:59 +08:00
install(TARGETS ${PROJECT_NAME} DESTINATION lib)
2023-12-05 15:46:14 +08:00
if(ULIB_BUILD_TESTS)
enable_testing()
2023-12-11 09:26:36 +08:00
set(GTEST_LANG_CXX11 OFF)
set(GTEST_HAS_TR1_TUPLE OFF)
set(GTEST_USE_OWN_TR1_TUPLE ON)
2023-12-05 15:46:14 +08:00
add_subdirectory(3party/googletest)
add_subdirectory(tests)
2023-12-11 09:26:36 +08:00
endif()
2023-12-26 20:58:36 +08:00
2024-01-05 09:48:31 +08:00
if(ULIB_BUILD_EXAMPLES)
2023-12-26 20:58:36 +08:00
add_subdirectory(examples)
endif()