Re: [CMake] compile header file for precompiled gcc headers

2006-12-20 Thread frederic heem
On Monday 18 December 2006 1:47 pm, Maik Beckmann wrote:
 Am Montag, den 18.12.2006, 13:33 +0100 schrieb Maik Beckmann:


 Even more intelligent ;)

 Maik
Hi,

The new macro generates an error:
CMake Error: Error in cmake code at
/home/heefre/svn/trunk/voxgratia/OpalTester/cmake/modules/FindXSD.cmake:55:
IF had incorrect arguments: ${item} STREQUAL ${_path} AND NOT 
_CMAKE_CURRENT_BINARY_DIR_included_before_path (Unknown arguments specified).
Current CMake 
stack: /home/heefre/svn/trunk/voxgratia/OpalTester/src/CMakeLists.txt
CMake Error: This is the ADD_PRECOMPILED_HEADER macro. CMAKE_CURREN_BINARY_DIR 
has to mentioned at INCLUDE_DIRECTORIES's argument list before , where 
PreCompiled.h is located


Note that cmake has a bug in which it reports the error at FindXSD.cmake:55, 
whereas the mistake is in PCHSupport.cmake. 
Then the marco tries to copy the precompiled header to the build directory but 
fails because the source file doesn't contain the full path, here is the 
modification:
ADD_CUSTOM_COMMAND(
OUTPUT  ${CMAKE_CURRENT_BINARY_DIR}/${_name} 
COMMAND ${CMAKE_COMMAND} -E copy  
${CMAKE_CURRENT_SOURCE_DIR}/${_input} 
${CMAKE_CURRENT_BINARY_DIR}/${_name} # ensure same directory! Required by gcc
)

The cmake version  is  cmake version 2.5-20061218
By the way, precompiled header on linux/gcc3.4 has decreased compiled time by 
30 % on one library. Precompiled header is worth it ! 
Thanks
Frederic



___
CMake mailing list
CMake@cmake.org
http://www.cmake.org/mailman/listinfo/cmake


Re: [CMake] compile header file for precompiled gcc headers

2006-12-18 Thread Maik Beckmann
Am Sonntag, den 17.12.2006, 21:55 +0100 schrieb klaas.holwerda:
 Hi,
 
 I want to get gcc to use precompiled headers.
  From http://gcc.gnu.org/onlinedocs/gcc/Precompiled-Headers.html
 i read that i need to compile a header file ( containing #includes to 
 all others for instance ).
 
 I have this haeder file, how to compile it with Cmake?
 
 I tried CHECK_CXX_SOURCE_COMPILES( wxart2d.h DONNO )
 
 But that does not produce a wxart2d.gch file.
 
 Understand that i do not need to get an executable nor library.
 
 Does somebody know how to do it?
 
 Has someone already succeeded in using precompiled headers with gcc on 
 Linux, any tips?
 
 Thanks,
 
 Klaas


Hello

Rosegarden (http://www.rosegardenmusic.com/) uses experimental PCH
support
http://rosegarden.svn.sourceforge.net/viewvc/rosegarden/trunk/rosegarden/cmake_admin/FindPCHSupport.cmake?revision=7699view=markup

This macro works per directory. It adds a target for precompileing the
header and every C++ source is compiled using it.  

I tweaked this version for applying PCH's per target (see attachment)

My version should be used like this:
CMakeLists.txt
add_executable(test test.cpp)
add_precompiled_header( test std_includes.h) 
/CMakeLists.txt

It's very experimental, but now my sources using boost.fusion compile
about 6-8 times faster than without PCH.

MfG Maik

 

# - Try to find precompiled headers support for GCC 3.4 and 4.x
# Once done this will define:
#
# Variable:
#   PCHSupport_FOUND
#
# Macro:
#   ADD_PRECOMPILED_HEADER

IF(CMAKE_COMPILER_IS_GNUCXX)
EXEC_PROGRAM(
${CMAKE_CXX_COMPILER} 
ARGS--version 
OUTPUT_VARIABLE _compiler_output)
STRING(REGEX REPLACE .* ([0-9]\\.[0-9]\\.[0-9]) .* \\1 
   gcc_compiler_version ${_compiler_output})
#MESSAGE(GCC Version: ${gcc_compiler_version})
IF(gcc_compiler_version MATCHES 4\\.[0-9]\\.[0-9])
SET(PCHSupport_FOUND TRUE)
ELSE(gcc_compiler_version MATCHES 4\\.[0-9]\\.[0-9])
IF(gcc_compiler_version MATCHES 3\\.4\\.[0-9])
SET(PCHSupport_FOUND TRUE)
ENDIF(gcc_compiler_version MATCHES 3\\.4\\.[0-9])
ENDIF(gcc_compiler_version MATCHES 4\\.[0-9]\\.[0-9])
ENDIF(CMAKE_COMPILER_IS_GNUCXX)

MACRO(ADD_PRECOMPILED_HEADER _targetName _input )

GET_FILENAME_COMPONENT(_name ${_input} NAME)
SET(_source ${CMAKE_CURRENT_SOURCE_DIR}/${_input})
SET(_outdir ${CMAKE_CURRENT_BINARY_DIR}/${_name}.gch)
MAKE_DIRECTORY(${_outdir})
SET(_output ${_outdir}/${CMAKE_BUILD_TYPE}.c++)
STRING(TOUPPER CMAKE_CXX_FLAGS_${CMAKE_BUILD_TYPE} _flags_var_name)
SET(_compiler_FLAGS ${${_flags_var_name}})

GET_DIRECTORY_PROPERTY(_directory_flags INCLUDE_DIRECTORIES)
FOREACH(item ${_directory_flags})
LIST(APPEND _compiler_FLAGS -I${item})
ENDFOREACH(item)

GET_DIRECTORY_PROPERTY(_directory_flags DEFINITIONS)
LIST(APPEND _compiler_FLAGS ${_directory_flags})

SEPARATE_ARGUMENTS(_compiler_FLAGS)
#MESSAGE(_compiler_FLAGS: ${_compiler_FLAGS})
message(${CMAKE_CXX_COMPILER} ${_compiler_FLAGS} -x c++-header -o 
${_output} ${_source})
ADD_CUSTOM_COMMAND(
OUTPUT ${_output}
COMMAND ${CMAKE_CXX_COMPILER}
${_compiler_FLAGS}
-x c++-header
-o ${_output} ${_source}
DEPENDS ${_source} )
ADD_CUSTOM_TARGET(${_targetName}_gch DEPENDS ${_output})
ADD_DEPENDENCIES(${_targetName} ${_targetName}_gch)
#SET(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} -include ${_name} -Winvalid-pch 
-H)
#SET(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} -include ${_name} -Winvalid-pch)
SET_TARGET_PROPERTIES(${_targetName} PROPERTIES
COMPILE_FLAGS -include ${_name} -Winvalid-pch
)

ENDMACRO(ADD_PRECOMPILED_HEADER)

___
CMake mailing list
CMake@cmake.org
http://www.cmake.org/mailman/listinfo/cmake

Re: [CMake] compile header file for precompiled gcc headers

2006-12-18 Thread frederic heem
Hi,
Which version of cmake are you using for precompiled header ?
Here is the ouptut of gcc when compiling headers:
/usr/bin/c++ 
-I/home/heefre/svn/trunk/voxgratia/opal/include;-I/home/heefre/svn/trunk/voxgratia/ptlib_unix/include;-I/usr/include/xsd;-I/usr/include;-I/home/heefre/svn/trunk/FsmCompiler/language/cpp/include;-I/home/heefre/svn/trunk/voxgratia/OpalTester/include;-I/home/heefre/svn/trunk/voxgratia/OpalTester/src;-I/home/heefre/svn/trunk/voxgratia/OpalTester/build/src;-I/usr/local/Trolltech/Qt-4.2.0/include;-I/usr/local/Trolltech/Qt-4.2.0/include/QtGui;-I/usr/local/Trolltech/Qt-4.2.0/include/QtCore;-I/usr/local/Trolltech/Qt-4.2.0/include/QtDBus;;;-DP_USE_PRAGMA;-D_REENTRANT;-DPTRACING;-Wall;-Werror;-DQT_GUI_LIB;-DQT_CORE_LIB
 -x 
c++-header -o 
/home/heefre/svn/trunk/voxgratia/OpalTester/build/src/std_includes.h.gch/.c++ 
/home/heefre/svn/trunk/voxgratia/OpalTester/src/std_includes.h
Every argument is separated by a colon, hence the compilation fails
Frederic Heem

On Monday 18 December 2006 9:25 am, Maik Beckmann wrote
 Am Sonntag, den 17.12.2006, 21:55 +0100 schrieb klaas.holwerda:
  Hi,
 
  I want to get gcc to use precompiled headers.
   From http://gcc.gnu.org/onlinedocs/gcc/Precompiled-Headers.html
  i read that i need to compile a header file ( containing #includes to
  all others for instance ).
 
  I have this haeder file, how to compile it with Cmake?
 
  I tried CHECK_CXX_SOURCE_COMPILES( wxart2d.h DONNO )
 
  But that does not produce a wxart2d.gch file.
 
  Understand that i do not need to get an executable nor library.
 
  Does somebody know how to do it?
 
  Has someone already succeeded in using precompiled headers with gcc on
  Linux, any tips?
 
  Thanks,
 
  Klaas

 Hello

 Rosegarden (http://www.rosegardenmusic.com/) uses experimental PCH
 support
 http://rosegarden.svn.sourceforge.net/viewvc/rosegarden/trunk/rosegarden/cm
ake_admin/FindPCHSupport.cmake?revision=7699view=markup

 This macro works per directory. It adds a target for precompileing the
 header and every C++ source is compiled using it.

 I tweaked this version for applying PCH's per target (see attachment)

 My version should be used like this:
 CMakeLists.txt
 add_executable(test test.cpp)
 add_precompiled_header( test std_includes.h)
 /CMakeLists.txt

 It's very experimental, but now my sources using boost.fusion compile
 about 6-8 times faster than without PCH.

 MfG Maik
___
CMake mailing list
CMake@cmake.org
http://www.cmake.org/mailman/listinfo/cmake


Re: [CMake] compile header file for precompiled gcc headers

2006-12-18 Thread Maik Beckmann
Am Montag, den 18.12.2006, 10:46 +0100 schrieb frederic heem:


Oops, forgot to mention two important things:

First:
At line
 c++-header -o gch/.c++ 
see
.c++
so you didn't set CMAKE_BUILD_TYPE. If you run i.e.
cmake -DCMAKE_BUILD_TYPE=Debug ../
the line above should change to
   c++-header -o ...gch/Debug.c++

Second:
You must add {CMAKE_CURRENT_BINARY_DIR} and ${CMAKE_CURRENT_SOURCE_DIR}
to the include dirs:
include_directories( 
#... others
${CMAKE_CURRENT_BINARY_DIR}  
${CMAKE_CURRENT_SOURCE_DIR}
#... others 
)


I'm using version 2.4.5, but the module doesn't use any recent cmake
features, AFAIK them.

I will work on this script soon to make it less error prone. 

Regards,
Maik

___
CMake mailing list
CMake@cmake.org
http://www.cmake.org/mailman/listinfo/cmake


Re: [CMake] compile header file for precompiled gcc headers

2006-12-18 Thread Maik Beckmann
Am Montag, den 18.12.2006, 11:42 +0100 schrieb Maik Beckmann:
 Am Montag, den 18.12.2006, 10:46 +0100 schrieb frederic heem:
 

Ok, try the new version attached and use it as follows:

a CMakeLists.txt file

include(dir/of/PCHSupport.cmake/PCHSupport.cmake)

include_directories(
${CMAKE_CURRENT_BINARY_DIR}
/dir/of/do_precompile.h
)

add_executable( a_target 
a_source_file.cpp
)

add_precompiled_header( a_target 
/dir/of/do_precompile.h/do_precompile.h
)  

/ a CMakeLists.txt file


Maik

# - Try to find precompiled headers support for GCC 3.4 and 4.x
# Once done this will define:
#
# Variable:
#   PCHSupport_FOUND
#
# Macro:
#   ADD_PRECOMPILED_HEADER

IF(CMAKE_COMPILER_IS_GNUCXX)
EXEC_PROGRAM(
${CMAKE_CXX_COMPILER} 
ARGS--version 
OUTPUT_VARIABLE _compiler_output)
STRING(REGEX REPLACE .* ([0-9]\\.[0-9]\\.[0-9]) .* \\1 
   gcc_compiler_version ${_compiler_output})
#MESSAGE(GCC Version: ${gcc_compiler_version})
IF(gcc_compiler_version MATCHES 4\\.[0-9]\\.[0-9])
SET(PCHSupport_FOUND TRUE)
ELSE(gcc_compiler_version MATCHES 4\\.[0-9]\\.[0-9])
IF(gcc_compiler_version MATCHES 3\\.4\\.[0-9])
SET(PCHSupport_FOUND TRUE)
ENDIF(gcc_compiler_version MATCHES 3\\.4\\.[0-9])
ENDIF(gcc_compiler_version MATCHES 4\\.[0-9]\\.[0-9])
ENDIF(CMAKE_COMPILER_IS_GNUCXX)

MACRO(ADD_PRECOMPILED_HEADER _targetName _input )

IF(NOT CMAKE_BUILD_TYPE)
MESSAGE(FATAL_ERROR 
This is the ADD_PRECOMPILED_HEADER macro.  
You must set CMAKE_BUILD_TYPE!
)
ENDIF(NOT CMAKE_BUILD_TYPE)

GET_FILENAME_COMPONENT(_name ${_input} NAME)
GET_FILENAME_COMPONENT(_path ${_input} PATH)
SET(_outdir ${CMAKE_CURRENT_BINARY_DIR}/${_name}.gch)
SET(_output ${_outdir}/${CMAKE_BUILD_TYPE}.c++)

MAKE_DIRECTORY(${_outdir})

STRING(TOUPPER CMAKE_CXX_FLAGS_${CMAKE_BUILD_TYPE} _flags_var_name)
SET(_compile_FLAGS ${${_flags_var_name}})

GET_DIRECTORY_PROPERTY(_directory_flags INCLUDE_DIRECTORIES)


SET(_CMAKE_CURRENT_BINARY_DIR_included_before_path FALSE)
FOREACH(item ${_directory_flags})
IF(${item}  STREQUAL ${_path} AND NOT 
_CMAKE_CURRENT_BINARY_DIR_included_before_path )
MESSAGE(FATAL_ERROR 
This is the ADD_PRECOMPILED_HEADER macro. 
CMAKE_CURREN_BINARY_DIR has to mentioned at 
INCLUDE_DIRECTORIES's argument list before ${_path}, where ${_name} is located
)   
ENDIF(${item}  STREQUAL ${_path} AND NOT 
_CMAKE_CURRENT_BINARY_DIR_included_before_path )

IF(${item}  STREQUAL ${CMAKE_CURRENT_BINARY_DIR})
SET(_CMAKE_CURRENT_BINARY_DIR_included_before_path TRUE)
ENDIF(${item}  STREQUAL ${CMAKE_CURRENT_BINARY_DIR})

LIST(APPEND _compile_FLAGS -I${item})
ENDFOREACH(item)

GET_DIRECTORY_PROPERTY(_directory_flags DEFINITIONS)
LIST(APPEND _compile_FLAGS ${_directory_flags})

SEPARATE_ARGUMENTS(_compile_FLAGS)
#MESSAGE(_compiler_FLAGS: ${_compiler_FLAGS})
#message(COMMAND ${CMAKE_CXX_COMPILER} ${_compile_FLAGS} -x c++-header 
-o ${_output} ${_input})   
ADD_CUSTOM_COMMAND(
OUTPUT ${_output}
COMMAND ${CMAKE_CXX_COMPILER}
${_compile_FLAGS}
-x c++-header
-o ${_output} 
${_input}
COMMAND ${CMAKE_COMMAND} -E copy  ${_input} 
${CMAKE_CURRENT_BINARY_DIR}/${_name} # ensure same directory! Required by gcc
DEPENDS ${_input}   
)
ADD_CUSTOM_TARGET(${_targetName}_gch 
DEPENDS ${_output} 
)
ADD_DEPENDENCIES(${_targetName} ${_targetName}_gch )
SET_TARGET_PROPERTIES(${_targetName} 
PROPERTIES  
COMPILE_FLAGS -include ${_name} -Winvalid-pch
)


ENDMACRO(ADD_PRECOMPILED_HEADER)

___
CMake mailing list
CMake@cmake.org
http://www.cmake.org/mailman/listinfo/cmake

Re: [CMake] compile header file for precompiled gcc headers

2006-12-18 Thread Maik Beckmann
Am Montag, den 18.12.2006, 13:33 +0100 schrieb Maik Beckmann:


Even more intelligent ;)

Maik


# - Try to find precompiled headers support for GCC 3.4 and 4.x
# Once done this will define:
#
# Variable:
#   PCHSupport_FOUND
#
# Macro:
#   ADD_PRECOMPILED_HEADER

IF(CMAKE_COMPILER_IS_GNUCXX)
EXEC_PROGRAM(
${CMAKE_CXX_COMPILER} 
ARGS--version 
OUTPUT_VARIABLE _compiler_output)
STRING(REGEX REPLACE .* ([0-9]\\.[0-9]\\.[0-9]) .* \\1 
   gcc_compiler_version ${_compiler_output})
#MESSAGE(GCC Version: ${gcc_compiler_version})
IF(gcc_compiler_version MATCHES 4\\.[0-9]\\.[0-9])
SET(PCHSupport_FOUND TRUE)
ELSE(gcc_compiler_version MATCHES 4\\.[0-9]\\.[0-9])
IF(gcc_compiler_version MATCHES 3\\.4\\.[0-9])
SET(PCHSupport_FOUND TRUE)
ENDIF(gcc_compiler_version MATCHES 3\\.4\\.[0-9])
ENDIF(gcc_compiler_version MATCHES 4\\.[0-9]\\.[0-9])
ENDIF(CMAKE_COMPILER_IS_GNUCXX)

MACRO(ADD_PRECOMPILED_HEADER _targetName _input )

IF(NOT CMAKE_BUILD_TYPE)
MESSAGE(FATAL_ERROR 
This is the ADD_PRECOMPILED_HEADER macro.  
You must set CMAKE_BUILD_TYPE!
)
ENDIF(NOT CMAKE_BUILD_TYPE)

GET_FILENAME_COMPONENT(_name ${_input} NAME)
GET_FILENAME_COMPONENT(_path ${_input} PATH)
SET(_outdir ${CMAKE_CURRENT_BINARY_DIR}/${_name}.gch)
SET(_output ${_outdir}/${CMAKE_BUILD_TYPE}.c++)

ADD_CUSTOM_COMMAND(
OUTPUT ${_outdir}
COMMAND mkdir ${_outdir} # TODO: {CMAKE_COMMAND} -E ... 
)
#MAKE_DIRECTORY(${_outdir})

STRING(TOUPPER CMAKE_CXX_FLAGS_${CMAKE_BUILD_TYPE} _flags_var_name)
SET(_compile_FLAGS ${${_flags_var_name}})

GET_DIRECTORY_PROPERTY(_directory_flags INCLUDE_DIRECTORIES)


SET(_CMAKE_CURRENT_BINARY_DIR_included_before_path FALSE)
FOREACH(item ${_directory_flags})
IF(${item}  STREQUAL ${_path} AND NOT 
_CMAKE_CURRENT_BINARY_DIR_included_before_path )
MESSAGE(FATAL_ERROR 
This is the ADD_PRECOMPILED_HEADER macro. 
CMAKE_CURREN_BINARY_DIR has to mentioned at 
INCLUDE_DIRECTORIES's argument list before ${_path}, where ${_name} is located
)   
ENDIF(${item}  STREQUAL ${_path} AND NOT 
_CMAKE_CURRENT_BINARY_DIR_included_before_path )

IF(${item}  STREQUAL ${CMAKE_CURRENT_BINARY_DIR})
SET(_CMAKE_CURRENT_BINARY_DIR_included_before_path TRUE)
ENDIF(${item}  STREQUAL ${CMAKE_CURRENT_BINARY_DIR})

LIST(APPEND _compile_FLAGS -I${item})
ENDFOREACH(item)

GET_DIRECTORY_PROPERTY(_directory_flags DEFINITIONS)
LIST(APPEND _compile_FLAGS ${_directory_flags})

SEPARATE_ARGUMENTS(_compile_FLAGS)
#MESSAGE(_compiler_FLAGS: ${_compiler_FLAGS})
#message(COMMAND ${CMAKE_CXX_COMPILER} ${_compile_FLAGS} -x c++-header 
-o ${_output} ${_input})

ADD_CUSTOM_COMMAND(
OUTPUT  ${CMAKE_CURRENT_BINARY_DIR}/${_name} 
COMMAND ${CMAKE_COMMAND} -E copy  ${_input} 
${CMAKE_CURRENT_BINARY_DIR}/${_name} # ensure same directory! Required by gcc
)

ADD_CUSTOM_COMMAND(
OUTPUT ${_output}   
COMMAND ${CMAKE_CXX_COMPILER}
${_compile_FLAGS}
-x c++-header
-o ${_output} 
${_input}
DEPENDS ${_input} ${_outdir} ${CMAKE_CURRENT_BINARY_DIR}/${_name}   
)
ADD_CUSTOM_TARGET(${_targetName}_gch 
DEPENDS ${_output}  
)
ADD_DEPENDENCIES(${_targetName} ${_targetName}_gch )
SET_TARGET_PROPERTIES(${_targetName} 
PROPERTIES  
COMPILE_FLAGS -include ${_name} -Winvalid-pch
)


ENDMACRO(ADD_PRECOMPILED_HEADER)

___
CMake mailing list
CMake@cmake.org
http://www.cmake.org/mailman/listinfo/cmake