Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

target_compile_definitions with several flags

I'm trying to change the flatbuffers library CMakeLists.txt to make PUBLIC some flags. Then, I've rewritten these lines:

Original code

elseif(CMAKE_COMPILER_IS_GNUCXX OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x -Wall -pedantic -Werror -Wextra") 
endif()

New code

elseif(CMAKE_COMPILER_IS_GNUCXX OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
    target_compile_definitions(flatbuffers PUBLIC "-std=c++0x -Wall -pedantic -Werror -Wextra")
endif()

The target name is flatc and, when I start to build the project, I receive this:

Scanning dependencies of target flatc
[  7%] Building CXX object CMakeFiles/flatc.dir/src/idl_parser.cpp.obj
<command-line>:0:1: error: macro names must be identifiers

Is it wrong the conversion of "set(CMAKE_CXX_FLAGS )" to "target_compile_definitions()" with these flags?

like image 493
fenix688 Avatar asked Sep 15 '14 09:09

fenix688


1 Answers

The difference is that the old variable CMAKE_CXX_FLAGS is a single space-separated string with all problems (escaping, manipulation etc.) that this brings.

The newer properties (like those set by target_compile_definitions()) work on CMake lists instead, one option per list element. So just remove the quotes and you're set. And, since you're not actually passing definitions (macros), but options, use target_compile_options() instead:

elseif(CMAKE_COMPILER_IS_GNUCXX OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
    target_compile_options(flatbuffers PUBLIC -std=c++0x -Wall -pedantic -Werror -Wextra)
endif()
like image 59
Angew is no longer proud of SO Avatar answered Oct 15 '22 16:10

Angew is no longer proud of SO