Warning, /graphics/kst-plot/cmake/modules/KstPchSupport.cmake is written in an unsupported language. File is not indexed.
0001 # *************************************************************************** 0002 # * * 0003 # * Copyright : (C) 2010 The University of Toronto * 0004 # * email : netterfield@astro.utoronto.ca * 0005 # * * 0006 # * Copyright : (C) 2010 Peter Kümmel * 0007 # * email : syntheticpp@gmx.net * 0008 # * * 0009 # * This program is free software; you can redistribute it and/or modify * 0010 # * it under the terms of the GNU General Public License as published by * 0011 # * the Free Software Foundation; either version 2 of the License, or * 0012 # * (at your option) any later version. * 0013 # * * 0014 # *************************************************************************** 0015 0016 0017 # Not supported officially my cmake 0018 # but there is a cmake ticket with examples 0019 # http://www.vtk.org/Bug/view.php?id=1260 0020 0021 0022 0023 # use this macro before <add_library> 0024 # 0025 # _header : header to make a .gch 0026 # _sources: the variable name (do not use ${..}) which contains a 0027 # a list of sources (a.cpp b.cpp c.cpp ...) 0028 # This macro will append a header file to it, then this 0029 # src_list can be used in <add_library> 0030 # 0031 # Now a .gch file should be generated and gcc should use it. 0032 # (add -Winvalid-pch to the cpp flags to verify) 0033 # 0034 # make clean should delete the pch file 0035 # 0036 # example : kst_add_pch_rule(pch.h source_list_name SHARED) 0037 0038 macro(kst_add_pch_rule _header _sources _lib_type) 0039 0040 if(CMAKE_COMPILER_IS_GNUCC) 0041 # first we have to find all compiler arguments 0042 get_directory_property(_definitions COMPILE_DEFINITIONS) 0043 foreach(_it ${_definitions}) 0044 if(CMAKE_MAJOR_VERSION LESS 3) 0045 list(APPEND _args "-D${_it}") 0046 else() 0047 list(APPEND _args "$<$<BOOL:${_it}>:-D${_it}>") 0048 endif() 0049 endforeach() 0050 0051 list(APPEND _args ${CMAKE_CXX_FLAGS}) 0052 if(CMAKE_BUILD_TYPE MATCHES Release) 0053 list(APPEND _args ${CMAKE_CXX_FLAGS_RELEASE}) 0054 get_directory_property(_definitions_type COMPILE_DEFINITIONS_RELEASE) 0055 else() 0056 list(APPEND _args ${CMAKE_CXX_FLAGS_DEBUG}) 0057 get_directory_property(_definitions_type COMPILE_DEFINITIONS_DEBUG) 0058 endif() 0059 if(${_lib_type} MATCHES SHARED) 0060 list(APPEND _args ${CMAKE_SHARED_LIBRARY_CXX_FLAGS}) 0061 endif() 0062 if(_definitions_type) 0063 if(CMAKE_MAJOR_VERSION LESS 3) 0064 list(APPEND _args "-D${_definitions_type}") 0065 else() 0066 list(APPEND _args "$<$<BOOL:${_definitions_type}>:-D${_definitions_type}>") 0067 endif() 0068 endif() 0069 #message(STATUS "pch: ${_args}") 0070 0071 get_directory_property(DIRINC INCLUDE_DIRECTORIES) 0072 foreach (_inc ${DIRINC}) 0073 LIST(APPEND _args "-I" ${_inc}) 0074 endforeach() 0075 0076 set(_gch_filename "${_header}.gch") 0077 list(APPEND ${_sources} ${_gch_filename}) 0078 list(APPEND _args -c ${_header} -o ${_gch_filename}) 0079 0080 separate_arguments(_args) 0081 0082 # now build the pch with the compiler arguments 0083 add_custom_command(OUTPUT ${_gch_filename} 0084 COMMAND ${CMAKE_COMMAND} -E remove ${_gch_filename} 0085 COMMAND ${CMAKE_CXX_COMPILER} ${CMAKE_CXX_COMPILER_ARG1} ${_args} 0086 DEPENDS ${_header}) 0087 0088 # all other files should use the pch 0089 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Winvalid-pch -include ${_header}") 0090 0091 else() 0092 0093 file(WRITE ${_header}.tmp "#include \"${_header}\"\n") 0094 execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different ${_header}.tmp ${_header}.cpp) 0095 0096 if(MSVC_IDE) 0097 set(pch_file "${_header}.\$(ConfigurationName).pch") 0098 else() 0099 set(pch_file ${_header}.pch) 0100 endif() 0101 0102 set_source_files_properties(${_header}.cpp PROPERTIES COMPILE_FLAGS "/Yc\"${_header}\" /Fp${pch_file}" 0103 OBJECT_OUTPUTS ${pch_file}) 0104 0105 # Bug in cmake: next line also compile .c files with pchs 0106 #set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /FI${_header} /Yu${_header} /Fp${pch_file}") 0107 foreach(it ${${_sources}}) 0108 get_filename_component(ext ${it} EXT) 0109 if(ext STREQUAL .c) 0110 else() 0111 set_source_files_properties(${it} PROPERTIES COMPILE_FLAGS "/FI${_header} /Yu${_header} /Fp${pch_file}" 0112 OBJECT_DEPENDS ${pch_file}) 0113 endif() 0114 endforeach() 0115 0116 list(APPEND ${_sources} ${_header} ${_header}.cpp) 0117 endif() 0118 0119 endmacro() 0120 0121