xref: /openbmc/s2600wf-misc/callback-manager/CMakeLists.txt (revision 01a3964a9eef7508dce6edcc3dd2c4400f2b5029)
1cmake_minimum_required (VERSION 3.1 FATAL_ERROR)
2set (BUILD_SHARED_LIBRARIES OFF)
3include (ExternalProject)
4set (CMAKE_CXX_STANDARD 20)
5set (CMAKE_CXX_STANDARD_REQUIRED ON)
6set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti")
7set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-rtti")
8
9option (YOCTO "Enable Building in Yocto" OFF)
10
11if (NOT YOCTO)
12    externalproject_add (
13        Boost URL
14        https://dl.bintray.com/boostorg/release/1.71.0/source/boost_1_71_0.tar.gz
15        URL_MD5 5f521b41b79bf8616582c4a8a2c10177 SOURCE_DIR
16        "${CMAKE_BINARY_DIR}/boost-src" BINARY_DIR
17        "${CMAKE_BINARY_DIR}/boost-build" CONFIGURE_COMMAND "" BUILD_COMMAND ""
18        INSTALL_COMMAND mkdir -p "${CMAKE_BINARY_DIR}/prefix/include/" && cp -R
19        ${CMAKE_BINARY_DIR}/boost-src/boost ${CMAKE_BINARY_DIR}/prefix/include
20    ) # requires apt install autoconf-archive and autoconf
21    externalproject_add (sdbusplus-project PREFIX
22                         ${CMAKE_BINARY_DIR}/sdbusplus-project GIT_REPOSITORY
23                         https://github.com/openbmc/sdbusplus.git GIT_TAG
24                         8a97100b806225df40c490eb748c9a4e1b3c11b3 SOURCE_DIR
25                         ${CMAKE_BINARY_DIR}/sdbusplus-src BINARY_DIR
26                         ${CMAKE_BINARY_DIR}/sdbusplus-build CONFIGURE_COMMAND
27                         "" BUILD_COMMAND cd ${CMAKE_BINARY_DIR}/sdbusplus-src
28                         && meson build -Ddefault_library=static && ninja -C
29                         build libsdbusplus.a INSTALL_COMMAND ""
30                         LOG_DOWNLOAD ON)
31
32    include_directories (${CMAKE_BINARY_DIR}/sdbusplus-src)
33    include_directories (${CMAKE_BINARY_DIR}/nlohmann/include)
34    include_directories (${CMAKE_BINARY_DIR}/nlohmann/include/nlohmann)
35    include_directories (${CMAKE_BINARY_DIR}/phosphor-dbus-interfaces/include)
36    link_directories (${CMAKE_BINARY_DIR}/sdbusplus-src/build)
37
38    include_directories (${CMAKE_BINARY_DIR}/boost-src)
39    set (CMAKE_PREFIX_PATH ${CMAKE_BINARY_DIR}/boost-src ${CMAKE_PREFIX_PATH})
40endif ()
41
42add_definitions (-DBOOST_ERROR_CODE_HEADER_ONLY)
43add_definitions (-DBOOST_SYSTEM_NO_DEPRECATED)
44add_definitions (-DBOOST_ALL_NO_LIB)
45add_definitions (-DBOOST_NO_RTTI)
46add_definitions (-DBOOST_NO_TYPEID)
47add_definitions (-DBOOST_ASIO_DISABLE_THREADS)
48
49include_directories (${CMAKE_CURRENT_SOURCE_DIR}/include)
50include_directories (${Boost_INCLUDE_DIRS})
51include_directories (${CMAKE_CURRENT_SOURCE_DIR}/include)
52
53add_executable (callback-manager src/callback_manager.cpp)
54
55target_link_libraries (callback-manager -lsystemd)
56target_link_libraries (callback-manager stdc++fs)
57target_link_libraries (callback-manager ${Boost_LIBRARIES})
58target_link_libraries (callback-manager sdbusplus)
59
60if (NOT YOCTO)
61    add_dependencies (callback-manager sdbusplus-project)
62endif ()
63
64set (SERVICE_FILES ${PROJECT_SOURCE_DIR}/service_files/callback-manager.service)
65
66find_package (PkgConfig REQUIRED)
67pkg_get_variable(SYSTEMD_SYSTEM_UNIT_DIR systemd systemdsystemunitdir)
68
69install (TARGETS callback-manager DESTINATION sbin)
70install (FILES ${SERVICE_FILES} DESTINATION "${SYSTEMD_SYSTEM_UNIT_DIR}")
71