1484543d1Sopenharmony_ci# ------------------------------------------------------------------- 2484543d1Sopenharmony_ci# ffrt CMake 3484543d1Sopenharmony_ci# 4484543d1Sopenharmony_ci# To enable thread sanitizer: 5484543d1Sopenharmony_ci# -DCMAKE_CXX_FLAGS="-fsanitize=thread -g" 6484543d1Sopenharmony_ci# 7484543d1Sopenharmony_ci# To enable address and leak sanitizers 8484543d1Sopenharmony_ci# -DCMAKE_CXX_FLAGS="-fsanitize=address -fsanitize=leak -g" 9484543d1Sopenharmony_ci# ------------------------------------------------------------------- 10484543d1Sopenharmony_ci 11484543d1Sopenharmony_ci# CMake version 12484543d1Sopenharmony_cicmake_minimum_required (VERSION 3.10) 13484543d1Sopenharmony_ci 14484543d1Sopenharmony_ci# build options 15484543d1Sopenharmony_cioption(FFRT_BBOX_ENABLE "Enables ffrt black box" ON) 16484543d1Sopenharmony_cioption(FFRT_EXAMPLE "Enables ffrt examples compile" ON) 17484543d1Sopenharmony_cioption(FFRT_BENCHMARKS "Enables ffrt Benchmarks" OFF) 18484543d1Sopenharmony_cioption(FFRT_TEST_ENABLE "Enables ffrt test" OFF) 19484543d1Sopenharmony_cioption(FFRT_CLANG_COMPILE "use clang/clang++ for compiling" OFF) 20484543d1Sopenharmony_cioption(FFRT_SANITIZE "enable address or thread sanitizer" OFF) 21484543d1Sopenharmony_ci 22484543d1Sopenharmony_ci# set compiler clang or gcc, must before project(ffrt) 23484543d1Sopenharmony_ciif(FFRT_CLANG_COMPILE STREQUAL ON) 24484543d1Sopenharmony_ci set(CMAKE_C_COMPILER clang) 25484543d1Sopenharmony_ci set(CMAKE_CXX_COMPILER clang++) 26484543d1Sopenharmony_cielse() 27484543d1Sopenharmony_ci set(CMAKE_C_COMPILER gcc) 28484543d1Sopenharmony_ci set(CMAKE_CXX_COMPILER g++) 29484543d1Sopenharmony_ciendif() 30484543d1Sopenharmony_ci 31484543d1Sopenharmony_ci# Project name 32484543d1Sopenharmony_ciproject(ffrt) 33484543d1Sopenharmony_ci 34484543d1Sopenharmony_ci#cmake build type settings,release or debug 35484543d1Sopenharmony_ciif(CMAKE_BUILD_TYPE STREQUAL Release) 36484543d1Sopenharmony_ci set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DFFRT_RELEASE -DFFRT_LOG_LEVEL=0") 37484543d1Sopenharmony_cielse() 38484543d1Sopenharmony_ci set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DFFRT_LOG_LEVEL=3") 39484543d1Sopenharmony_ciendif() 40484543d1Sopenharmony_ci 41484543d1Sopenharmony_ci# project-specific variables 42484543d1Sopenharmony_ciset(FFRT_CODE_PATH ${PROJECT_SOURCE_DIR}/src) 43484543d1Sopenharmony_ciset(FFRT_INNER_API_PATH ${PROJECT_SOURCE_DIR}/interfaces/inner_api) 44484543d1Sopenharmony_ciset(FFRT_API_PATH ${PROJECT_SOURCE_DIR}/interfaces/kits) 45484543d1Sopenharmony_ciset(FFRT_BUILD_PATH ${PROJECT_SOURCE_DIR}/build) 46484543d1Sopenharmony_ciset(ROOT_PATH ${PROJECT_SOURCE_DIR}/../) 47484543d1Sopenharmony_ciset(SECUREC_PATH ${ROOT_PATH}/third_party/bounds_checking_function) 48484543d1Sopenharmony_ciset(TRACE_PATH ${FFRT_CODE_PATH}/dfx/trace) 49484543d1Sopenharmony_ciset(QOS_PATH ${FFRT_CODE_PATH}/sched/) 50484543d1Sopenharmony_ciset(securec_includes ${SECUREC_PATH}/include) 51484543d1Sopenharmony_ciaux_source_directory(${SECUREC_PATH}/src securec_srcs) 52484543d1Sopenharmony_ciadd_library(securec SHARED ${securec_srcs}) 53484543d1Sopenharmony_citarget_include_directories(securec PRIVATE ${securec_includes}) 54484543d1Sopenharmony_ciinclude_directories(${securec_includes}) 55484543d1Sopenharmony_ci 56484543d1Sopenharmony_ci#compiler flags 57484543d1Sopenharmony_ciif(FFRT_SANITIZE STREQUAL address) 58484543d1Sopenharmony_ci set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fsanitize-recover=address,all -fno-omit-frame-pointer") 59484543d1Sopenharmony_cielseif(FFRT_SANITIZE STREQUAL thread) 60484543d1Sopenharmony_ci set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=thread -fno-omit-frame-pointer") 61484543d1Sopenharmony_ciendif() 62484543d1Sopenharmony_ci 63484543d1Sopenharmony_ciif(FFRT_UT_ENABLE STREQUAL OFF AND FFRT_ST_ENABLE STREQUAL OFF) 64484543d1Sopenharmony_ci set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden") 65484543d1Sopenharmony_ciendif() 66484543d1Sopenharmony_ciif(CMAKE_BUILD_TYPE STREQUAL Release) 67484543d1Sopenharmony_ci set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 -g -O2 -fPIC") 68484543d1Sopenharmony_cielse() 69484543d1Sopenharmony_ci set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 -g -O0 -fPIC") 70484543d1Sopenharmony_ciendif() 71484543d1Sopenharmony_ci 72484543d1Sopenharmony_ci# add the binary tree to the search path for include files 73484543d1Sopenharmony_ciinclude_directories(${FFRT_API_PATH}) 74484543d1Sopenharmony_ciinclude_directories(${FFRT_INNER_API_PATH}) 75484543d1Sopenharmony_ciinclude_directories(${FFRT_CODE_PATH}) 76484543d1Sopenharmony_ciinclude_directories(${TRACE_PATH}) 77484543d1Sopenharmony_ciinclude_directories(${QOS_PATH}) 78484543d1Sopenharmony_ci 79484543d1Sopenharmony_cimessage(STATUS "CMAKE_BUILD_TYPE: " ${CMAKE_BUILD_TYPE}) 80484543d1Sopenharmony_cimessage(STATUS "FFRT_BBOX_ENABLE: " ${FFRT_BBOX_ENABLE}) 81484543d1Sopenharmony_cimessage(STATUS "FFRT_EXAMPLE: " ${FFRT_EXAMPLE}) 82484543d1Sopenharmony_cimessage(STATUS "FFRT_BENCHMARKS: " ${FFRT_BENCHMARKS}) 83484543d1Sopenharmony_cimessage(STATUS "FFRT_TEST_ENABLE: " ${FFRT_TEST_ENABLE}) 84484543d1Sopenharmony_cimessage(STATUS "FFRT_CLANG_COMPILE: " ${FFRT_CLANG_COMPILE}) 85484543d1Sopenharmony_cimessage(STATUS "FFRT_SANITIZE: " ${FFRT_SANITIZE}) 86484543d1Sopenharmony_ci 87484543d1Sopenharmony_ciadd_definitions("-DFFRT_PTHREAD_ENABLE") 88484543d1Sopenharmony_ci 89484543d1Sopenharmony_ci# ffrt qos 90484543d1Sopenharmony_ciadd_definitions(-DUSE_OHOS_QOS) 91484543d1Sopenharmony_ci 92484543d1Sopenharmony_ci# ffrt BBOX 93484543d1Sopenharmony_ciif(FFRT_BBOX_ENABLE STREQUAL ON) 94484543d1Sopenharmony_ci add_definitions("-DFFRT_BBOX_ENABLE") 95484543d1Sopenharmony_ciendif() 96484543d1Sopenharmony_ci 97484543d1Sopenharmony_ci# ffrt trace record level 98484543d1Sopenharmony_ciadd_definitions("-DFFRT_TRACE_RECORD_LEVEL=1") 99484543d1Sopenharmony_ci 100484543d1Sopenharmony_ci# libffrt.so 101484543d1Sopenharmony_ciadd_subdirectory(src) 102484543d1Sopenharmony_ciLINK_DIRECTORIES(${FFRT_BUILD_PATH}/src) 103484543d1Sopenharmony_ci 104484543d1Sopenharmony_ci# ffrt Examples 105484543d1Sopenharmony_ciif(FFRT_EXAMPLE STREQUAL ON) 106484543d1Sopenharmony_ci add_subdirectory(examples) 107484543d1Sopenharmony_ciendif() 108484543d1Sopenharmony_ci 109484543d1Sopenharmony_ci# ffrt Benchmarks 110484543d1Sopenharmony_ciif(FFRT_BENCHMARKS STREQUAL ON) 111484543d1Sopenharmony_ci add_subdirectory(benchmarks) 112484543d1Sopenharmony_ciendif() 113