Problem 1227 - UseGeant4.cmake making mistake with compiler flags in some cases
Summary: UseGeant4.cmake making mistake with compiler flags in some cases
Status: CLOSED FIXED
Alias: None
Product: Geant4
Classification: Unclassified
Component: cmake (show other problems)
Version: other
Hardware: All All
: P5 trivial
Assignee: Ben Morgan
URL:
Depends on:
Blocks:
 
Reported: 2011-07-06 08:55 CEST by Yngve Inntjore Levinsen
Modified: 2011-07-28 20:11 CEST (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this problem.
Description Yngve Inntjore Levinsen 2011-07-06 08:55:33 CEST
If a compiler flag variable like e.g. CXX_CMAKE_COMPILE_FLAGS is non-empty before UseGeant4.cmake is called, there is a ; added to the variable. The example below will produce the error:

project(foo)
set(CMAKE_CXX_FLAGS "-W -Wa")
find_package(Geant4 REQUIRED)
include(${Geant4_USE_FILE})
message("PROBLEMATIC FLAGS: ${CMAKE_CXX_FLAGS}")
add_executable(foo foo.cc)

A solution is to add "" around when you set the variables, like this:
set(_tmp_CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Geant4_CXX_FLAGS}")
Comment 1 Yngve Inntjore Levinsen 2011-07-06 08:56:12 CEST
Edit: by CXX_CMAKE_COMPILE_FLAGS of course I mean CMAKE_CXX_FLAGS.
Comment 2 Ben Morgan 2011-07-06 13:27:27 CEST
Confirmed - this is due to a syntax error in mixing strings versus lists as described here

http://www.cmake.org/Wiki/CMake_FAQ#How_to_convert_a_semicolon_separated_list_to_a_whitespace_separated_string.3F

I hadn't seen the issue because it will work when the initial flags aren't set, or the Geant4 specific flags are the same as the initial set supplied by CMake.

I'll work on a proper patch - the underlying idea in UseGeant4 being to force the use of the 'standard' Geant4 flags, but allow users to append to these (might need to rethink that..).

For now, your suggested fix to UseGeant4.cmake will work, although might result in duplicate flags being used (that probably isn't severe).

If you don't want to (or can't) edit UseGeant4.cmake, one can do

find_package(Geant4 REQUIRED)
include(${Geant4_USE_FILE})
set(CMAKE_CXX_FLAGS "${Geant4_CXX_FLAGS}")
set(CMAKE_CXX_FLAGS_DEBUG "${Geant4_CXX_FLAGS_DEBUG}")
set(CMAKE_CXX_FLAGS_MINSIZEREL "${Geant4_CXX_FLAGS_MINSIZEREL}")
set(CMAKE_CXX_FLAGS_RELEASE "${Geant4_CXX_FLAGS_RELEASE}")
set(CMAKE_CXX_FLAGS_RELWITHDEDINFO "${Geant4_CXX_FLAGS_RELWITHDEBINFO}")


which will force the use of the flags used to build Geant4. Whilst it's a little messy, it should cover most use cases, but does mean you can't edit the flags through the cache.
Comment 3 Ben Morgan 2011-07-28 20:10:58 CEST
Fixed in svn, with tag

cmake-V09-04-14

Current fix simply forces use of flags used to build Geant4, so need to investigate other options. Either way, will be in next release.