Home >Backend Development >C++ >How to Add -fexceptions and Other Linker/Compiler Flags in CMake?
How to Incorporate Linker and Compile Flags in a CMake File
When compiling with the arm-linux-androideabi-g compiler, adding exception handling requires the inclusion of the -fexceptions flag. While it works using the command line, the issue arises when attempting to compile using a CMake file.
To add the -fexceptions flag in CMake, follow these steps:
SET(CMAKE_EXCEPTIONS_FLAG "-fexceptions")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_EXCEPTIONS_FLAG}") SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${CMAKE_EXCEPTIONS_FLAG}")
get_target_property(TEMP ${THE_TARGET} COMPILE_FLAGS) if(TEMP STREQUAL "TEMP-NOTFOUND") SET(TEMP "") else() SET(TEMP "${TEMP} ") endif() SET(TEMP "${TEMP}${CMAKE_EXCEPTIONS_FLAG}") set_target_properties(${THE_TARGET} PROPERTIES COMPILE_FLAGS ${TEMP})
By implementing these steps, you can incorporate the necessary flags into your CMake file and successfully compile your code with the desired exception handling functionality.
The above is the detailed content of How to Add -fexceptions and Other Linker/Compiler Flags in CMake?. For more information, please follow other related articles on the PHP Chinese website!