1# Copyright(c) 2017 Intel Corporation 2 3# Permission is hereby granted, free of charge, to any person obtaining a 4# copy of this software and associated documentation files(the "Software"), 5# to deal in the Software without restriction, including without limitation 6# the rights to use, copy, modify, merge, publish, distribute, sublicense, 7# and / or sell copies of the Software, and to permit persons to whom the 8# Software is furnished to do so, subject to the following conditions: 9 10# The above copyright notice and this permission notice shall be included 11# in all copies or substantial portions of the Software. 12 13# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 14# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 16# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 17# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 18# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 19# OTHER DEALINGS IN THE SOFTWARE. 20 21 22if(NOT DEFINED _bs_include_base_utils) 23 set(_bs_include_base_utils TRUE) 24 25 # bs_set_if_undefined - If not defined, assign value from env or arg 26 macro(bs_set_if_undefined VAR_NAME VAR_VALUE) 27 if(DEFINED ${VAR_NAME} AND NOT ${VAR_NAME} STREQUAL "") 28 # Already defined 29 elseif(DEFINED ENV{VAR_NAME} AND NOT "$ENV{VAR_NAME}" STREQUAL "") 30 set(${VAR_NAME} "$ENV{VAR_NAME}") 31 else() 32 set(${VAR_NAME} "${VAR_VALUE}") 33 endif() 34 endmacro() 35 36 macro(bs_compare_build_type _bs_compare_var) 37 if ("${_bs_compare_var}" STREQUAL "Release" OR "${_bs_compare_var}" STREQUAL "release") 38 set(T_CMAKE_BUILD_TYPE "Release") 39 set(BUILD_TYPE "release") 40 elseif ("${_bs_compare_var}" STREQUAL "ReleaseInternal" OR "${_bs_compare_var}" STREQUAL "release-internal" OR 41 "${_bs_compare_var}" STREQUAL "Release-Internal") 42 set(T_CMAKE_BUILD_TYPE "ReleaseInternal") 43 set(BUILD_TYPE "release-internal") 44 elseif ("${_bs_compare_var}" STREQUAL "Debug" OR "${_bs_compare_var}" STREQUAL "debug") 45 set(T_CMAKE_BUILD_TYPE "Debug") 46 set(BUILD_TYPE "debug") 47 elseif ("${_bs_compare_var}" STREQUAL "RelWithDebInfo" OR "${_bs_compare_var}" STREQUAL "RELWITHDEBINFO" OR 48 "${_bs_compare_var}" STREQUAL "relwithdebinfo") 49 set(T_CMAKE_BUILD_TYPE "RelWithDebInfo") 50 set(BUILD_TYPE "RelWithDebInfo") 51 elseif ("${_bs_compare_var}" STREQUAL "MinSizeRel" OR "${_bs_compare_var}" STREQUAL "MINSIZEREL" OR 52 "${_bs_compare_var}" STREQUAL "minsizerel") 53 set(T_CMAKE_BUILD_TYPE "MinSizeRel") 54 set(BUILD_TYPE "MinSizeRel") 55 else() 56 #Pass the flag as received from user, Could be a custom flag setting 57 message("Build Type: ${_bs_compare_var} is a custom build type") 58 set(T_CMAKE_BUILD_TYPE "${_bs_compare_var}") 59 set(BUILD_TYPE "${_bs_compare_var}") 60 endif() 61 endmacro() 62 63 set(_bs_check_build_type_done 0) 64 65 # function bs_check_build_type 66 # Deal with the ambiguity of the three different variables for BUILD_TYPE: 67 # Give them priority in this order: 68 # UFO_BUILD_TYPE 69 # BUILD_TYPE 70 # Note: Despite the similarity of name, CMAKE_BUILD_TYPE is not analogous 71 # to UFO_BUILD_TYPE and BUILD_TYPE. 72 function(bs_check_build_type) 73 74 if(DEFINED CMAKE_BUILD_TYPE AND NOT "${CMAKE_BUILD_TYPE}" STREQUAL "" 75 AND NOT "${CMAKE_BUILD_TYPE}" STREQUAL "None") 76 77 set(_bs_check_build_type_done 1 PARENT_SCOPE) 78 79 bs_compare_build_type("${CMAKE_BUILD_TYPE}") 80 set(CMAKE_BUILD_TYPE "${T_CMAKE_BUILD_TYPE}" PARENT_SCOPE) #set in parent scope 81 set(CMAKE_BUILD_TYPE "${T_CMAKE_BUILD_TYPE}") #set in current scope 82 83 set(BUILD_TYPE "${BUILD_TYPE}" PARENT_SCOPE) 84 85 message(STATUS "Single-configuration generator. Build type : ${CMAKE_BUILD_TYPE}") 86 87 elseif(DEFINED BUILD_TYPE AND NOT "${BUILD_TYPE}" STREQUAL "") 88 89 set(_bs_check_build_type_done 1 PARENT_SCOPE) 90 91 bs_compare_build_type("${BUILD_TYPE}") 92 set(CMAKE_BUILD_TYPE "${T_CMAKE_BUILD_TYPE}" PARENT_SCOPE) #set in parent scope 93 set(CMAKE_BUILD_TYPE "${T_CMAKE_BUILD_TYPE}") #set in current scope 94 set(BUILD_TYPE "${BUILD_TYPE}" PARENT_SCOPE) 95 96 message(STATUS "Single-configuration generator. Build type : ${CMAKE_BUILD_TYPE}") 97 98 else() 99 # If Build Type is not passed, Set as release builds as default 100 if(NOT ${_bs_check_build_type_done}) 101 set(_bs_check_build_type_done 1 PARENT_SCOPE) 102 set(_bs_bt_var_names UFO_BUILD_TYPE BUILD_TYPE) 103 foreach(_bs_bt_var_a ${_bs_bt_var_names}) 104 foreach(_bs_bt_var_b ${_bs_bt_var_names}) 105 if(NOT _bs_bt_var_a STREQUAL _bs_bt_var_b) 106 if(DEFINED ${_bs_bt_var_a} AND DEFINED ${_bs_bt_var_b} AND NOT ${_bs_bt_var_a} STREQUAL ${_bs_bt_var_b}) 107 message(FATAL_ERROR "Conflict: ${_bs_bt_var_a}=${${_bs_bt_var_a}} vs ${_bs_bt_var_b=${${_bs_bt_var_b}}}") 108 endif() 109 endif() 110 endforeach() 111 endforeach() 112 set(_bs_bt_value "") 113 foreach(_bs_bt_var_a ${_bs_bt_var_names}) 114 if(DEFINED ${_bs_bt_var_a}) 115 set(_bs_bt_value ${${_bs_bt_var_a}}) 116 break() 117 endif() 118 endforeach() 119 120 if(_bs_bt_value STREQUAL "") 121 message("*BUILD_TYPE not defined, default to: release") 122 set(_bs_bt_value "release") 123 endif() 124 125 foreach(_bs_bt_var_a ${_bs_bt_var_names}) 126 if(NOT DEFINED ${_bs_bt_var_a}) 127 set(${_bs_bt_var_a} "${_bs_bt_value}" PARENT_SCOPE) 128 endif() 129 endforeach() 130 endif() 131 132 endif() 133 134 endfunction(bs_check_build_type) 135endif(NOT DEFINED _bs_include_base_utils) 136