如何创建继承自版本

时间:2017-05-02 20:38:39

标签: c++ c cmake

This answer介绍了如何从头开始创建自定义配置类型。如何创建与内置Release完全匹配的配置类型,只添加一些标记?我现在正在使用它:

set(CMAKE_CONFIGURATION_TYPES "Debug;Release;ReleaseWithAssertions" CACHE STRING
    "Available build-types: Debug, Release and ReleaseWithAssertions")

set(CMAKE_CXX_FLAGS_RELEASEWITHASSERTIONS "${CMAKE_CXX_FLAGS_RELEASE} 
    -DENABLE_ASSERTIONS=1")

这似乎做了我想要的,但我只是复制了CMAKE_CXX_FLAGS_RELEASE的价值,所以我想知道用户可能会发现我有什么遗漏?

3 个答案:

答案 0 :(得分:4)

不,不是添加与内置Release"完全匹配的自定义"配置类型。这更像是feature request for CMake

修改:刚看到实际上有"Creating new configurations for MSVC" feature request您可以给予支持。

以下是一些可能的背景信息以及不可能的信息:

  1. 可能存在许多配置特定变量。你可以用脚本复制那些:

    get_directory_property(_vars VARIABLES)
    foreach(_var IN LISTS _vars)
        if (_var MATCHES "_RELEASE$")
            string(REPLACE "_RELEASE" "_RELEASEWITHASSERTIONS" _var_new "${_var}")
            set(${_var_new} "${${_var}}")
        endif()
    endforeach()
    
  2. 您需要将导入的目标映射到新配置,并设置CMAKE_MAP_IMPORTED_CONFIG_<CONFIG>

    list(APPEND CMAKE_MAP_IMPORTED_CONFIG_RELEASEWITHASSERTIONS "Release" "")
    
  3. 您无法对$<CONFIG:cfg>类型generator expressions检查特定配置名称执行任何操作

  4. 您必须在properties

  5. 中检查目录/目标/来源文件和配置特定的更改

    <强>参考

答案 1 :(得分:1)

如果你正在编译任何import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; import android.os.Bundle; import android.support.v4.app.Fragment; import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.Button; import android.widget.EditText; import android.widget.Toast; import com.android.volley.AuthFailureError; import com.android.volley.Request; import com.android.volley.RequestQueue; import com.android.volley.Response; import com.android.volley.VolleyError; import com.android.volley.toolbox.StringRequest; import com.android.volley.toolbox.Volley; import java.util.HashMap; import java.util.Map; public class TwoFragment extends Fragment{ View view; Button reg; //Defining views private EditText editTextEmail; private EditText editTextPassword; private Button buttonLogin; //boolean variable to check user is logged in or not //initially it is false private boolean loggedIn = false; public TwoFragment() { // Required empty public constructor } @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment view = inflater.inflate(R.layout.fragment_two, container, false); reg = (Button) view.findViewById(R.id.button); buttonLogin = (Button) view.findViewById(R.id.btnsignin); buttonLogin.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { login(); } }); editTextEmail = (EditText) view.findViewById(R.id.txtemail); editTextPassword = (EditText) view.findViewById(R.id.editText); reg.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent i = new Intent(getActivity(), managerreg.class); startActivity(i); } }); return view; } @Override public void onResume() { super.onResume(); //In onresume fetching value from sharedpreference SharedPreferences sharedPreferences = getContext().getSharedPreferences(Config.SHARED_PREF_NAME, Context.MODE_PRIVATE); //Fetching the boolean value form sharedpreferences loggedIn = sharedPreferences.getBoolean(Config.LOGGEDIN_SHARED_PREF, false); //If we will get true if(loggedIn){ //We will start the Profile Activity Intent intent = new Intent(getActivity(), MainActivity.class); startActivity(intent); } } private void login(){ //Getting values from edit texts final String username = editTextEmail.getText().toString().trim(); final String password = editTextPassword.getText().toString().trim(); //Creating a string request StringRequest stringRequest = new StringRequest(Request.Method.POST, Config.LOGIN_URL, new Response.Listener<String>() { @Override public void onResponse(String response) { //If we are getting success from server if(response.equalsIgnoreCase(Config.LOGIN_SUCCESS)){ //Creating a shared preference SharedPreferences sharedPreferences = getActivity().getSharedPreferences(Config.SHARED_PREF_NAME, Context.MODE_PRIVATE); //Creating editor to store values to shared preferences SharedPreferences.Editor editor = sharedPreferences.edit(); //Adding values to editor editor.putBoolean(Config.LOGGEDIN_SHARED_PREF, true); editor.putString(Config.USERNAME_SHARED_PREF,username ); //Saving values to editor editor.commit(); //Starting profile activity Intent intent = new Intent(getActivity(), MainActivity.class); startActivity(intent); }else{ //If the server response is not success //Displaying an error message on toast Toast.makeText(getActivity(), "Invalid username or password", Toast.LENGTH_LONG).show(); } } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { //You can handle error here if you want } }){ @Override protected Map<String, String> getParams() throws AuthFailureError { Map<String,String> params = new HashMap<>(); //Adding parameters to request params.put(Config.KEY_USERNAME, username); params.put(Config.KEY_PASSWORD, password); //returning parameter return params; } }; //Adding the string request to the queue RequestQueue requestQueue = Volley.newRequestQueue(getActivity().getApplicationContext()); requestQueue.add(stringRequest); } } 个文件,那么你可能想要的另一个就是CMAKE_C_FLAGS_RELEASE。

请参阅cmake&#39; documentation

<?php

    if($_SERVER['REQUEST_METHOD']=='POST'){
        $username = $_POST['username'];
        $password = $_POST['password'];




        require_once('dbConnect.php');

    $sql = "SELECT * FROM managerreg WHERE username = '$username' AND password = BINARY '".md5($_POST['password'])." ";

        $result = mysqli_query($con,$sql);

        $check = mysqli_fetch_array($result);

        if(isset($check)){
            echo 'success';
        }else{
            echo 'failure';
        }
    }

答案 2 :(得分:0)

来自https://gitlab.kitware.com/cmake/community/-/wikis/FAQ#how-can-i-extend-the-build-modes-with-a-custom-made-one-

似乎您希望对所有这些都做同样的事情。

CMAKE_CXX_FLAGS_RELEASEWITHASSERTIONS
CMAKE_C_FLAGS_RELEASEWITHASSERTIONS
CMAKE_EXE_LINKER_FLAGS_RELEASEWITHASSERTIONS
CMAKE_SHARED_LINKER_FLAGS_RELEASEWITHASSERTIONS