To specify your own C and C + + compiler flags, for flags that does not affect optimization, use the CMAKE_C_FLAGS
and CMAKE_CXX_FLAGS
CMake options.
When providing your own compiler the flags, you might want to specify as well CMAKE_BUILD_TYPE
.
For example, to-create a 32-bit release build on a 64-bit Linux machine, does this:
shell> mkdir bld
shell> CD bld
shell> cmake:-dcmake_c_flags=- M32 \
-dcmake_cxx_flags=-m32 \
-dcmake_build_type=relwithdebinfo
If You set the flags that affect optimization (-o number
), you must set The cmake_c_flags_ Build_type
and/or cmake_cxx_flags_ Build_type
options, where build_type
corresponds to The cmake_build_type
value. To specify a different optimization for the default build type (relwithdebinfo
) Set Thecmake_c_flags_relwithdebinfo
and cmake_cxx_flags_ Relwithdebinfo
options. For example, to compile on the Linux with -o3
and with debug symbols, Do this:
cmake .. -DCMAKE_C_FLAGS_RELWITHDEBINFO="-O3 -g" \
-DCMAKE_CXX_FLAGS_RELWITHDEBINFO="-O3 -g"
红色的部分要一致
http://blog.csdn.net/fan_hai_ping/article/details/42524205
Build Type CMake provides us with four build types: Debugreleaseminsizerelrelwithdebinfo If you use CMake to generate projects for Windows MSVC/workspaces then we will get the above4solution configuration. If you use CMake to generate Makefile, we need to do some different things. There is a variable cmake_build_type in CMake that specifies the build type, which is used only for make-based generators. We can specify a build type like this: $ CMake-dcmake_build_type=Debug. The value of the cmake_build_type here is the above4one of the building types. Compile and link flags C compile flag related variables: Cmake_c_flagscmake_c_flags_[debug| release| minsizerel|Relwithdebinfo]
C++compiler flags related variables: cmake_cxx_flags
Cmake_cxx_flags_[debug| release| minsizerel|Relwithdebinfo]
Cmake_c_flags or cmake_cxx_flags can specify a compile flag cmake_c_flags_[debug| release| minsizerel| Relwithdebinfo] or
Cmake_cxx_flags_[debug| release| minsizerel|Relwithdebinfo] Specifies the compilation flags for a particular build type, which will be added to the cmake_c_flags or cmake_cxx_flags, for example, if the build type is DEBUG, then Cmake_cxx_flags_ DEBUG will be added to the cmake_cxx_flags.
Link Flag related variables: Cmake_exe_linker_flagscmake_exe_linker_flags_[debug| release| minsizerel|Relwithdebinfo] Cmake_module_linker_flagscmake_module_linker_flags_[debug| release| minsizerel|Relwithdebinfo] Cmake_shared_linker_flagscmake_shared_linker_flags_[debug| release| minsizerel|Relwithdebinfo] They are similar to the compile flags related variables generated by debug and release versions in Visual Studio we can generate the debug version and release version of the program, using CMake we can also achieve the above effect. The debug version of the project generates executable files that require debugging information and do not need to be optimized, while the release version does not require debugging information but needs to be optimized. These features are in GCC/g++ is determined by the parameters at compile time, if the optimization level to the highest need to set the parameters-o3, the lowest is-o0 is not optimized; The parameter to add debug information is-G-Ggdb, if you do not add this parameter, the debug information will not be included in the generated binaries. There is a variable cmake_build_type in CMake that can be used for Debug, Release, Relwithdebinfo, and Minsizerel. When the value of this variable is Debug, CMake uses the string in the variable cmake_cxx_flags_debug and Cmake_c_flags_debug as the compilation option to generate the makefile, when the variable value is Release, The project generates Makefile using the variable cmake_cxx_flags_release and cmake_c_flags_release options. Example: PROJECT (Main) cmake_minimum_required (VERSION2.6) SET (Cmake_source_dir.) SET (Cmake_cxx_flags_debug"$ENV {cxxflags}-o0-wall-g-ggdb") SET (cmake_cxx_flags_release"$ENV {cxxflags}-o3-wall") Aux_source_directory (. DIR_SRCS) add_executable (main ${dir_srcs})5And6The rows are set with two variables Cmake_cxx_flags_debug and cmake_cxx_flags_release, which are the compilation options for DEBUG and RELEASE respectively. You need to execute the ccmake command to generate Makefile after editing CMakeList.txt. Enter the root directory of the project,"Ccmake."into a graphical interface. Compiling 32-bit and 64-bit programs for Windows MSVC, we can set CMake Generator to determine whether the build Win32 or Win64 the project file, for example: # used to generate Visual Studio 10win64 project Files CMake -G"Visual Studio Ten Win64"# used to generate Visual Studio 10win32 project Files CMake-G"Visual Studio Ten"we can get through CMake .--Help to view the Generator available on the current platform. CMake. -duse_32bits=1if(use_32bits) message (STATUS"Using 32bits") Set(Cmake_c_flags"${cmake_c_flags}-m32") Set(Cmake_cxx_flags"${cmake_cxx_flags}-m32")Else() endif (use_32bits) for Unix and Unix-like platforms, we can use compiler flags (options) to control +Bit is still --bit construction. GCC command line parameter 32-bit version: Plus-The m32 parameter, which generates 32-bit code. 64-bit version: Plus-The m64 parameter, which generates 64-bit code. Debug version: Plus-g parameter to generate debug information. Release version: Plus-Staticparameters, which are statically linked so that the program no longer relies on dynamic libraries. Plus the-o3 parameter for fastest speed optimization. Plusthe Dndebug parameter, which defines the NDEBUG macro, masks the assertion. When there is no-m32 OR-The m64 parameter typically generates code that is consistent with the number of operating systems, but some compilers have exceptions, such as GCC under 32-bit Linux, which is compiled to 32-bit code by default. GCC, under 64-bit Linux, is compiled to 64-bit code by default. The MinGW under the window system is always compiled into 32-bit code. Because MinGW only supports 32-bit code. MinGW under the Window System-W64 (for example, TDM-GCC is installed, select mingw-w64), which is compiled to 64-bit code by default, is included under 32-bit Windows systems. Example in the makefile file: # [args] build mode. 0 for debug mode, 1 for release mode. Makerelease=1. Ifeq ($ (RELEASE),0) CFLAGS+= -gElse#release CFLAGS+= -Static-o3-Dndebug lflags+= -Staticendif# [args] The number of program bits. 32 stands for 32-bit programs, 64 for 64-bit programs, and other default. Makebits= +. Ifeq ($ (BITS), +) CFLAGS+= -M32 lflags+= -M32Elseifeq ($ (BITS), -) CFLAGS+= -m64 lflags+= -m64ElseEndifendif
MySQL source coding Yi Modify the FLAGS, debug MySQL