shavera
shavera

Reputation: 843

cmake target_compile_definitions and target_link_libraries clash, maybe with Qt lines?

Linux Mint 17.2 / clang 3.4 / CMake 3.2.2

I tried to simplify the problem I'm having to some dummy program, but that hasn't worked. (ie the problem doesn't reproduce there), but here's the gist:

I have a CMakeLists.txt file that has lines to the effect of:

add_executable(${PROJECT_NAME} main.cpp)
target_link_libraries(${PROJECT_NAME) projectLib1 Qt5::Core Qt5::Widgets)
target_compile_definitions(${PROJECT_NAME) PUBLIC V_MAJOR=${CPACK_VERSION_MAJOR})

and so on.

When I run cmake, it generates a flags.make file:

CXX_DEFINES = -DV_MAJOR=3

-DQT_CORE_LIB -DQT_GUI_LIB -DQT_WIDGETS_LIB

where there's a line break between the compile definitions and the definitions generated by linking to Qt.

I've tried, in a smaller program, to reproduce this (linking to Qt, adding compile definitions), but it doesn't generate the same line break error.

Furthermore, when I go in and manually edit the flags.make, it will compile; but I know that's really not how to use the system.

Any thoughts?


Edit: Just for clarity, when I attempt to compile, I get an error:

.../flags.make:8: *** missing separator. Stop.

where 8 is the line number of the line break in that flags.make file.

Upvotes: 0

Views: 1759

Answers (1)

shavera
shavera

Reputation: 843

Found issue: I was reading in version number from a file.

CMakeLists.txt:

file(READ Version.txt VersionString)
string(REPLACE "." ";" VersionList ${VersionString})
list(LENGTH VersionList listLen)
list(GET VersionList 0 CPACK_PACKAGE_VERSION_MAJOR)
list(GET VersionList 1 CPACK_PACKAGE_VERSION_MINOR)
list(GET VersionList 2 CPACK_PACKAGE_VERSION_PATCH)

etc. The newline at the end of the string was not immediately obvious, but carried through along the 'patch' version variable. That inserted the newline into the make file and messed everything up.


Edit: adding string(STRIP ${VersionString} VersionString) fixed it.

Upvotes: 2

Related Questions