[CMake] (no subject)

John Drescher drescherjm at gmail.com
Tue Dec 15 09:08:35 EST 2009


On Tue, Dec 15, 2009 at 4:13 AM, Johan Knutzen <knutzen_johan2 at yahoo.se> wrote:
>
> Hi!
>
> What is the status of scripts enabling precompiled headers for gcc/visual studio? I've tried out PCHSupport_26 from http://www.cmake.org/Bug/view.php?id=1260 but I couldn't get it to work. Does anyone have any up to date script that works with 2.8?
>

I have not bothered in linux since I can use ccache to speed up
builds. In windows I use the following macro:

#########################################################################################

macro( SM_PCH_SUPPORT ProjectName )
if (MSVC)
	if (USE_MSVC_PCH)
	
		set_source_files_properties(${ProjectName}PCH.cxx
			PROPERTIES
			COMPILE_FLAGS "/Yc${ProjectName}PCH.h"
			)
		foreach( src_file ${${ProjectName}_SRCS} )
			set_source_files_properties(
				${src_file}
				PROPERTIES
				COMPILE_FLAGS "/Yu${ProjectName}PCH.h"
				)
		endforeach( src_file ${${ProjectName}_SRCS} )
		
		list(APPEND ${ProjectName}_SRCS ${ProjectName}PCH.cxx)
		list(APPEND ${ProjectName}_EXT_HDRS ${ProjectName}PCH.h)

	endif(USE_MSVC_PCH)
endif (MSVC)
endmacro (SM_PCH_SUPPORT)

#########################################################################################


And this requires me to have my source variable named ${ProjectName}_SRCS

And my header variable to be named ${ProjectName}_EXT_HDRS

and the following files to exist in the same folder as the CMakeLists.txt

${ProjectName}PCH.cxx ${ProjectName}PCH.h

I generally put this macro in the main project before my first
add_subdirectory so that all subprojects can use the macro as well.

Then to activate this in a project. I place the macro call after I
define the list variables.

SET( smDataManagement_SRCS
	./src/smData.cxx
	./src/smDataOperation.cxx
	./src/smCounterBalanceOperation.cxx
)

SET( smDataManagement_EXT_HDRS
	./Include/smData.h
	./Include/smDataOperation.h
	./Include/smCounterBalanceOperation.h
)

SET( smDataManagement_MOC_HDRS
	
)

# some .ui files
SET( smDataManagement_UIS
)

# and finally an resource file
SET( smDataManagement_RCS
)

SET( smDataManagement_INT_HDRS

)

#Add precompiled header support
SM_PCH_SUPPORT(smDataManagement)

This works in cmake-2.6 and above.
John


More information about the CMake mailing list