Hi Maik, Thanks for the Christmas present ;-) I tried your code with gcc. The following issues/suggestions came to my mind:
1) It seems to me (and it worked for me) that you don't need to have CMAKE_CURRENT_BINARY_DIR in the include path if you change the target cflags determination into set(${_cflags} "-include ${CMAKE_CURRENT_BINARY_DIR}/${_header_name} -Winvalid-pch" ) which means the -include flag sees the complete path. 2) the include directory options seem to be missing in _PCH_GET_COMPILE_FLAGS would you not need something like GET_DIRECTORY_PROPERTY(DIRINC INCLUDE_DIRECTORIES ) FOREACH(item ${DIRINC}) LIST(APPEND ${_out_compile_flags} "${_PCH_include_prefix}${item}") ENDFOREACH(item) furthermore I suppose you should replace all _compile_FLAGS variables in this function by ${_out_compile_flags}. It works as you do it but having a macro argument and not using it makes things really confusing. 3) What happens if an dependency of the precompiled include file changes? YOu could run a compiler command to determine the dependencies on configure time, but this seems not completely fool proof. I suggest to add the following target in ADD_PRECOMPILED_HEADER GET_TARGET_PROPERTY(_targetType ${_PCH_current_target} TYPE) SET(PHC_MASTER_INCLUDE_FILE ${_input}) CONFIGURE_FILE(${PROJECT_SOURCE_DIR}/cmModules/PCHCheckDependencies.cxx.in ${CMAKE_CURRENT_BINARY_DIR}/${_targetName}_gchdep.cxx) IF(${_targetType} STREQUAL SHARED_LIBRARY) ADD_LIBRARY(${_targetName}_gchdep SHARED ${CMAKE_CURRENT_BINARY_DIR}/${_targetName}_gchdep.cxx) ELSE(${_targetType} STREQUAL SHARED_LIBRARY) ADD_LIBRARY(${_targetName}_gchdep STATIC ${CMAKE_CURRENT_BINARY_DIR}/${_targetName}_gchdep.cxx) ENDIF(${_targetType} STREQUAL SHARED_LIBRARY) and add ${_targetName}_gchdep as dependency to ADD_CUSTOM_COMMAND( OUTPUT ${_output} COMMAND ${_command} DEPENDS ${_input} ${_outdir} ${CMAKE_CURRENT_BINARY_DIR}/${_name} ${_targetName}_gchdep ) PCHCheckDependencies.cxx.in contains just #include "${PHC_MASTER_INCLUDE_FILE}" int PHC_MASTER_INCLUDE_FILE_testfunction() { return 0; } it does not take much time to compile ( for my project much less then the generation of the precompiled headers) and as far as I can see it is the most simple way to automatically handle the dependencies. 4) your test for pch support seems a bit sloppy - anything besides GXX is msvc ?? Anyway a big thank you for this macro Cheers, Axel On Saturday 23 December 2006 11:26, Maik Beckmann wrote: > Am Mittwoch, den 20.12.2006, 17:53 +0100 schrieb frederic heem: > > Hi, > > Is there a nice way to find out if a target is using -fPIC ? > > Indeed, this information is needed for generating compiled header. > > At the moment, a kludge is to use the following code: > > > > #If the target is a shared library, add -fPIC to compile > > GET_TARGET_PROPERTY(_targetType ${_targetName} TYPE) > > IF(${_targetType} STREQUAL SHARED_LIBRARY) > > SET(_compile_FLAGS "${_compile_FLAGS} -fPIC") > > ENDIF(${_targetType} STREQUAL SHARED_LIBRARY) > > > > This works but is not a proper solution, one shall not know in which > > case -fPIC is used or not. > > Thanks, > > Frederic Heem > > I ran into this problem and your solutions works like a charm. > > I also worked on msvc support(see attached file), but it only work if > CMAKE_BUILD_TYPE equals "Release", since /Fd wants to add debugging > informations and fails due to inconsitent pdb files. If someone know's > more about this issue, please give me a hint. > > merry Christmas, Maik -- Axel Roebel IRCAM Analysis/Synthesis Team Phone: ++33-1-4478 4845 | Fax: ++33-1-4478 1540 _______________________________________________ CMake mailing list CMake@cmake.org http://www.cmake.org/mailman/listinfo/cmake