[Kst] branches/work/kst/portto4/kst/cmake/modules

Peter Kümmel syntheticpp at gmx.net
Mon Jan 17 12:34:31 CET 2011


SVN commit 1215039 by kuemmel:

cmake: add pch for msvc

 M  +33 -6     KstPchSupport.cmake  


--- branches/work/kst/portto4/kst/cmake/modules/KstPchSupport.cmake #1215038:1215039
@@ -5,8 +5,8 @@
 # http://www.vtk.org/Bug/view.php?id=1260
 
 
-if(CMAKE_COMPILER_IS_GNUCC)
 
+
 	# use this macro before "add_executable"
 	#
 	# _header : header to make a .gch
@@ -24,9 +24,8 @@
 	
 	macro(kst_add_pch_rule  _header _sources _lib_type)
 	
-		set(_gch_filename "${_header}.gch")
-		list(APPEND ${_sources} ${_gch_filename})
-		
+	if(CMAKE_COMPILER_IS_GNUCC)
+		# first we have to find all compiler arguments
 		get_directory_property(_definitions COMPILE_DEFINITIONS)
 		foreach (_it ${_definitions})
 			list(APPEND _args "-D${_it}")
@@ -46,19 +45,47 @@
 		list(APPEND _args -D${_definitions_type})
 		#message(STATUS "pch: ${_args}")
 		
-		list(APPEND _args -c ${_header} -o ${_gch_filename})
 		get_directory_property(DIRINC INCLUDE_DIRECTORIES)
 		foreach (_inc ${DIRINC})
 			LIST(APPEND _args "-I" ${_inc})
 		endforeach(_inc ${DIRINC})
 		
+		set(_gch_filename "${_header}.gch")
+		list(APPEND ${_sources} ${_gch_filename})
+		list(APPEND _args -c ${_header} -o ${_gch_filename})
+		
 		separate_arguments(_args)
+		
+		# now build the pch with the compiler arguments 
 		add_custom_command(OUTPUT ${_gch_filename}
 			COMMAND rm -f ${_gch_filename}
 			COMMAND ${CMAKE_CXX_COMPILER} ${CMAKE_CXX_COMPILER_ARG1} ${_args}
 			DEPENDS ${_header})
 			
+		# all other files should use the pch
 		set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Winvalid-pch -include ${_header}")
+	
+	else()
+		
+		file(WRITE ${_header}.tmp "#include \"${_header}\"\n")
+		execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different ${_header}.tmp ${_header}.cpp)
+		
+		set(use_pch /Fp${_header}.pch)
+		set_source_files_properties(${_header}.cpp PROPERTIES COMPILE_FLAGS "/Yc\"${_header}\" ${use_pch}")
+		
+		# Bug in cmake: next line also compile .c files with pchs
+		#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /FI${_header} /Yu${_header} ${use_pch}")
+		foreach(it ${${_sources}})
+			get_filename_component(ext ${it} EXT)
+			if(ext STREQUAL .c)
+			else()
+				set_source_files_properties(${it} PROPERTIES COMPILE_FLAGS "/FI${_header} /Yu${_header} ${use_pch}")
+			endif()
+		endforeach()
+			
+		list(APPEND ${_sources} ${_header} ${_header}.cpp) 
+	endif()
+		
 	endmacro()
 
-endif()
+


More information about the Kst mailing list