blob: 45cefecdc34282e6b3ba1c1a6bf31e3b5fde9f4a [file] [log] [blame]
Ed Tanous0fdddb12017-02-28 11:06:34 -08001cmake_minimum_required(VERSION 2.8.10 FATAL_ERROR)
2
Ed Tanouscfbe25d2017-05-23 16:34:35 -07003cmake_policy(SET CMP0054 NEW)
4
Ed Tanous0fdddb12017-02-28 11:06:34 -08005set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH})
6
7message("${CMAKE_MODULE_PATH}")
8
Ed Tanous93f987d2017-04-17 17:52:36 -07009SET(BUILD_SHARED_LIBRARIES OFF)
10
Ed Tanous9b65f1f2017-03-07 15:17:13 -080011#SET(HUNTER_STATUS_DEBUG ON)
Ed Tanous2d02dcd2017-05-15 12:25:30 -070012option(HUNTER_ENABLED "Enable hunter package pulling" OFF)
Ed Tanousa1e077c2017-04-25 12:42:19 -070013#SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti")
14#SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-rtti")
Ed Tanous1ccd57c2017-03-21 13:15:58 -070015include("cmake/HunterGate.cmake")
Ed Tanous0fdddb12017-02-28 11:06:34 -080016HunterGate(
Ed Tanouscfbe25d2017-05-23 16:34:35 -070017 URL "https://github.com/ruslo/hunter/archive/v0.18.64.tar.gz"
18 SHA1 "baf9c8cc4f65306f0e442b5419967b4c4c04589a"
Ed Tanous0fdddb12017-02-28 11:06:34 -080019)
20
Ed Tanous0fdddb12017-02-28 11:06:34 -080021project(bmc-webserver CXX C)
22
Ed Tanousf3d847c2017-06-12 16:01:42 -070023include( CTest )
24
Ed Tanous0fdddb12017-02-28 11:06:34 -080025set(CMAKE_CXX_STANDARD 14)
26set(CMAKE_CXX_STANDARD_REQUIRED ON)
27
28set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
29
Ed Tanouseb1b8622017-04-25 14:11:46 -070030if (MSAN)
31 if(NOT CMAKE_CXX_COMPILER_ID MATCHES "Clang")
32 message(FATAL_ERROR "Cannot enable MSAN unless using Clang")
33 endif()
34
35 if (ASAN)
36 message(FATAL_ERROR "ASAN and MSAN are mutually exclusive")
37 endif()
38
39 SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${MSAN_CXX_FLAGS}")
40 SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${MSAN_LINKER_EXE_FLAGS}")
41
42 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=memory -fsanitize-memory-track-origins -fno-omit-frame-pointer")
43 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=memory -fsanitize-memory-track-origins -fno-omit-frame-pointer")
44 set(OPENSSL_NO_ASM "1")
45 set(LIBC++ ON)
Ed Tanousf0226cd2017-05-16 12:35:38 -070046endif(MSAN)
Ed Tanouseb1b8622017-04-25 14:11:46 -070047
48if (ASAN)
49 if(NOT CMAKE_CXX_COMPILER_ID MATCHES "Clang")
50 message(FATAL_ERROR "Cannot enable ASAN unless using Clang")
51 endif()
52
53 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address -fsanitize-address-use-after-scope -fno-omit-frame-pointer")
54 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fsanitize-address-use-after-scope -fno-omit-frame-pointer")
55 set(OPENSSL_NO_ASM "1")
Ed Tanousf0226cd2017-05-16 12:35:38 -070056endif(ASAN)
Ed Tanouseb1b8622017-04-25 14:11:46 -070057
58if (GCOV)
59 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage")
60 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage")
Ed Tanousf0226cd2017-05-16 12:35:38 -070061endif(GCOV)
Ed Tanouseb1b8622017-04-25 14:11:46 -070062
Ed Tanous0fdddb12017-02-28 11:06:34 -080063if ( ${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR} )
64 message( FATAL_ERROR "In-source builds not allowed. Please make a new directory (usually called build) and run CMake from there. You may need to remove CMakeCache.txt." )
65endif()
66
Ed Tanouseb1b8622017-04-25 14:11:46 -070067if(LIBC++)
68 SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
69 SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lc++abi")
70 if (MSAN)
71 SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -I/home/ed/libcxx_msan/include -I/home/ed/libcxx_msan/include/c++/v1")
72 SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -L/home/ed/libcxx_msan/lib -Wl,-rpath,I/home/ed/libcxx_msan/lib")
73 endif(MSAN)
74endif(LIBC++)
75
Ed Tanous0d485ef2017-05-23 09:23:53 -070076#SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror -Wall")
77
Ed Tanous3dac7492017-08-02 13:46:20 -070078SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti")
79SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-rtti")
80
Ed Tanous0fdddb12017-02-28 11:06:34 -080081# general
Ed Tanous38bdb982017-03-03 14:19:33 -080082option(BUILD_SHARED_LIBS "Build as shared library" OFF)
Ed Tanous93f987d2017-04-17 17:52:36 -070083option(BUILD_UT "Enable Unit test" ON)
Ed Tanous0fdddb12017-02-28 11:06:34 -080084
Ed Tanous8041f312017-04-03 09:47:01 -070085# This needs to be before the crow and other module includes so headers get overriden correctly
86include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
87
Ed Tanous1ccd57c2017-03-21 13:15:58 -070088# security flags
89#SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fstack-protector-strong -fPIE -fPIC -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security" )
90#SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -z noexecstack -z relro -z now")
91
Ed Tanous0fdddb12017-02-28 11:06:34 -080092# Boost
Ed Tanousa1e077c2017-04-25 12:42:19 -070093#add_definitions(-DBOOST_NO_RTTI -DBOOST_NO_TYPEID)
94
Ed Tanous3dac7492017-08-02 13:46:20 -070095# TinyXML2
96#add_subdirectory(tinyxml2)
97#include_directories(tinyxml2)
98
Ed Tanous1ccd57c2017-03-21 13:15:58 -070099#add_definitions(-DBOOST_ASIO_ENABLE_HANDLER_TRACKING)
Ed Tanous01250f22017-04-18 17:49:51 -0700100add_definitions(-DBOOST_ERROR_CODE_HEADER_ONLY)
101add_definitions(-DBOOST_SYSTEM_NO_DEPRECATED)
Ed Tanous0fdddb12017-02-28 11:06:34 -0800102add_definitions(-DBOOST_ALL_NO_LIB)
Ed Tanous3dac7492017-08-02 13:46:20 -0700103add_definitions(-DBOOST_NO_RTTI)
104add_definitions(-DBOOST_NO_TYPEID)
Ed Tanous0d485ef2017-05-23 09:23:53 -0700105#set(Boost_USE_STATIC_LIBS ON)
Ed Tanouseb1b8622017-04-25 14:11:46 -0700106hunter_add_package(Boost)
Ed Tanous2d02dcd2017-05-15 12:25:30 -0700107find_package(Boost REQUIRED)
Ed Tanouse2fc45a2017-04-26 09:19:10 -0700108include_directories(${Boost_INCLUDE_DIRS})
Ed Tanous0fdddb12017-02-28 11:06:34 -0800109
110#Openssl
Ed Tanous2d02dcd2017-05-15 12:25:30 -0700111hunter_add_package(OpenSSL)
Ed Tanous0fdddb12017-02-28 11:06:34 -0800112find_package(OpenSSL REQUIRED)
Ed Tanousf0226cd2017-05-16 12:35:38 -0700113include_directories(${OPENSSL_INCLUDE_DIR})
Ed Tanous0d485ef2017-05-23 09:23:53 -0700114message("OPENSSL_INCLUDE_DIR ${OPENSSL_INCLUDE_DIR}")
Ed Tanous0fdddb12017-02-28 11:06:34 -0800115
Ed Tanous93f987d2017-04-17 17:52:36 -0700116#lib jpeg
117set(BUILD_STATIC ON)
118#include_directories(libjpeg)
119#include_directories(${CMAKE_CURRENT_BINARY_DIR}/libjpeg)
120#add_subdirectory(libjpeg)
121
Ed Tanous8041f312017-04-03 09:47:01 -0700122
Ed Tanouscc5a37f2017-05-11 10:27:23 -0700123# dbus
Ed Tanous2d02dcd2017-05-15 12:25:30 -0700124hunter_add_package(dbus)
Ed Tanouscc5a37f2017-05-11 10:27:23 -0700125find_package(dbus REQUIRED) # Include functions provided by PkgConfig module.
Ed Tanouse4e67cc2017-05-12 16:10:59 -0700126include_directories(${DBUS_INCLUDE_DIRS})
Ed Tanouscc5a37f2017-05-11 10:27:23 -0700127
Ed Tanous8041f312017-04-03 09:47:01 -0700128# Crow
Ed Tanous4c3cbc62017-05-16 09:17:42 -0700129#add_definitions(-DCROW_DISABLE_LOGGING)
Ed Tanous8041f312017-04-03 09:47:01 -0700130add_definitions(-DCROW_ENABLE_SSL)
131include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/crow/include)
Ed Tanous0fdddb12017-02-28 11:06:34 -0800132
Ed Tanous9b65f1f2017-03-07 15:17:13 -0800133#Zlib
Ed Tanous7d3dba42017-04-05 13:04:39 -0700134hunter_add_package(ZLIB)
135find_package(ZLIB REQUIRED)
Ed Tanousf0226cd2017-05-16 12:35:38 -0700136include_directories(${ZLIB_INCLUDE_DIRS})
Ed Tanousf9273472017-02-28 16:05:13 -0800137
Ed Tanous4758d5b2017-06-06 15:28:13 -0700138
139# PAM
140find_package(PAM REQUIRED)
141
Ed Tanousc9b55212017-06-12 13:25:51 -0700142# Boost-dbus
Ed Tanousc5799492017-06-13 14:06:43 -0700143if(${BUILD_UT})
144 add_subdirectory(boost-dbus)
145endif()
Ed Tanousc9b55212017-06-12 13:25:51 -0700146include_directories(boost-dbus/include)
147
Ed Tanousf9273472017-02-28 16:05:13 -0800148set(WEBSERVER_MAIN src/webserver_main.cpp)
Ed Tanous5f34a9c2017-02-28 12:35:13 -0800149
Ed Tanous904063f2017-03-02 16:48:24 -0800150set(HDR_FILES
Ed Tanous5f34a9c2017-02-28 12:35:13 -0800151 include/ssl_key_handler.hpp
Ed Tanous904063f2017-03-02 16:48:24 -0800152)
153
154set(GENERATED_SRC_FILES
155 ${CMAKE_BINARY_DIR}/generated/webassets.cpp
Ed Tanousb4a7bfa2017-04-04 17:23:00 -0700156 ${CMAKE_BINARY_DIR}/generated/webassets.hpp
Ed Tanous904063f2017-03-02 16:48:24 -0800157)
158
Ed Tanousb4a7bfa2017-04-04 17:23:00 -0700159include_directories(${CMAKE_BINARY_DIR}/generated)
160
Ed Tanous9b65f1f2017-03-07 15:17:13 -0800161set_source_files_properties(${GENERATED_SRC_FILES} PROPERTIES GENERATED TRUE)
Ed Tanous904063f2017-03-02 16:48:24 -0800162
Ed Tanous12a002d2017-05-15 11:59:16 -0700163# the webassets file has a non-ideal beahvior, where it loads binary data into a std::string
164# due to the way crow is constructed. This causes GCC warnings. Filter them out.
Ed Tanousb4d29f42017-03-24 16:39:25 -0700165if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
Ed Tanous12a002d2017-05-15 11:59:16 -0700166 if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.9)
Ed Tanousb4d29f42017-03-24 16:39:25 -0700167 set_source_files_properties(${CMAKE_BINARY_DIR}/generated/webassets.cpp PROPERTIES COMPILE_FLAGS -Wno-narrowing)
Ed Tanous12a002d2017-05-15 11:59:16 -0700168 endif(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.9)
Ed Tanousb4d29f42017-03-24 16:39:25 -0700169endif()
170
171
Ed Tanous904063f2017-03-02 16:48:24 -0800172set(SRC_FILES
Ed Tanousf9273472017-02-28 16:05:13 -0800173 src/base64.cpp
Ed Tanous904063f2017-03-02 16:48:24 -0800174 ${GENERATED_SRC_FILES}
Ed Tanous5f34a9c2017-02-28 12:35:13 -0800175)
176
Ed Tanousf9273472017-02-28 16:05:13 -0800177set(UT_FILES
Ed Tanous9140a672017-04-24 17:01:32 -0700178 src/crow_test.cpp
Ed Tanousf9273472017-02-28 16:05:13 -0800179 src/gtest_main.cpp
180 src/base64_test.cpp
181 src/token_authorization_middleware_test.cpp
Ed Tanousb4a7bfa2017-04-04 17:23:00 -0700182 src/security_headers_middleware_test.cpp
183 src/webassets_test.cpp
184 src/crow_getroutes_test.cpp
Ed Tanous93f987d2017-04-17 17:52:36 -0700185 src/ast_jpeg_decoder_test.cpp
Ed Tanous9140a672017-04-24 17:01:32 -0700186 src/kvm_websocket_test.cpp
187 src/test_utils.cpp
Ed Tanous01250f22017-04-18 17:49:51 -0700188 src/msan_test.cpp
Ed Tanous9140a672017-04-24 17:01:32 -0700189 src/ci_map_tests.cpp
Ed Tanouse2fc45a2017-04-26 09:19:10 -0700190 src/ast_video_puller_test.cpp
Ed Tanousf9273472017-02-28 16:05:13 -0800191 ${CMAKE_BINARY_DIR}/generated/blns.hpp
192)
Ed Tanous5f34a9c2017-02-28 12:35:13 -0800193
Ed Tanous93f987d2017-04-17 17:52:36 -0700194
Ed Tanous9b65f1f2017-03-07 15:17:13 -0800195file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/generated")
196
Ed Tanous93f987d2017-04-17 17:52:36 -0700197file(COPY src/test_resources DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
198
Ed Tanous38bdb982017-03-03 14:19:33 -0800199# Unit Tests
200if(${BUILD_UT})
Ed Tanous9b65f1f2017-03-07 15:17:13 -0800201 # big list of naughty strings
202 add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/generated/blns.hpp
Ed Tanouscc5a37f2017-05-11 10:27:23 -0700203 COMMAND xxd -i ${CMAKE_CURRENT_SOURCE_DIR}/src/test_resources/blns ${CMAKE_BINARY_DIR}/generated/blns.hpp)
Ed Tanous9b65f1f2017-03-07 15:17:13 -0800204
Ed Tanous38bdb982017-03-03 14:19:33 -0800205 # googletest
206 enable_testing()
Ed Tanous4c3cbc62017-05-16 09:17:42 -0700207
Ed Tanous01250f22017-04-18 17:49:51 -0700208 #hunter_add_package(GTest)
209 add_subdirectory(googletest)
210 #find_package(GMock CONFIG REQUIRED)
Ed Tanous38bdb982017-03-03 14:19:33 -0800211
Ed Tanousc9b55212017-06-12 13:25:51 -0700212 add_executable(webtest ${HDR_FILES} ${SRC_FILES} ${UT_FILES})
213 target_link_libraries(webtest gmock gtest)
214 target_link_libraries(webtest pthread)
Ed Tanousf0226cd2017-05-16 12:35:38 -0700215
Ed Tanousc9b55212017-06-12 13:25:51 -0700216 target_link_libraries(webtest ${OPENSSL_LIBRARIES})
217 target_link_libraries(webtest ${ZLIB_LIBRARIES})
218 target_link_libraries(webtest pam)
219 add_dependencies(webtest packagestaticcpp)
220 add_test(webtest webtest "--gtest_output=xml:webtest.xml")
221
Ed Tanous38bdb982017-03-03 14:19:33 -0800222endif(${BUILD_UT})
Ed Tanous904063f2017-03-02 16:48:24 -0800223
224# web static assets
225add_subdirectory(static)
Ed Tanousf9273472017-02-28 16:05:13 -0800226
Ed Tanousc9b55212017-06-12 13:25:51 -0700227
Ed Tanousf9273472017-02-28 16:05:13 -0800228# bmcweb
Ed Tanous904063f2017-03-02 16:48:24 -0800229add_executable(bmcweb ${WEBSERVER_MAIN} ${HDR_FILES} ${SRC_FILES})
Ed Tanous01250f22017-04-18 17:49:51 -0700230target_link_libraries(bmcweb pthread)
Ed Tanousf0226cd2017-05-16 12:35:38 -0700231target_link_libraries(bmcweb ${OPENSSL_LIBRARIES})
Ed Tanous9b65f1f2017-03-07 15:17:13 -0800232target_link_libraries(bmcweb ${ZLIB_LIBRARIES})
Ed Tanousdc7b6792017-05-12 15:55:51 -0700233target_link_libraries(bmcweb ${DBUS_LIBRARIES})
Ed Tanous4758d5b2017-06-06 15:28:13 -0700234target_link_libraries(bmcweb pam)
Ed Tanousf0226cd2017-05-16 12:35:38 -0700235add_dependencies(bmcweb packagestaticcpp)
Ed Tanous12a002d2017-05-15 11:59:16 -0700236install (TARGETS bmcweb DESTINATION bin)
Ed Tanouscc5a37f2017-05-11 10:27:23 -0700237
Ed Tanous1ccd57c2017-03-21 13:15:58 -0700238add_executable(getvideo src/getvideo_main.cpp)
Ed Tanous01250f22017-04-18 17:49:51 -0700239target_link_libraries(getvideo pthread)
Ed Tanous1ccd57c2017-03-21 13:15:58 -0700240
Ed Tanous38bdb982017-03-03 14:19:33 -0800241# Visual Studio Code helper
Ed Tanous5f34a9c2017-02-28 12:35:13 -0800242# this needs to be at the end to make sure all includes are handled correctly
Ed Tanous93f987d2017-04-17 17:52:36 -0700243
Ed Tanous5f34a9c2017-02-28 12:35:13 -0800244get_property(C_INCLUDE_DIRS DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY INCLUDE_DIRECTORIES)
Ed Tanouscfbe25d2017-05-23 16:34:35 -0700245execute_process(COMMAND python3 ${CMAKE_CURRENT_SOURCE_DIR}/scripts/prime_vscode_compile_db.py ${C_INCLUDE_DIRS})