File: CMakeLists.txt

package info (click to toggle)
cmake 2.8.11.1-1~bpo70+1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy-backports
  • size: 37,056 kB
  • sloc: cpp: 157,219; ansic: 137,155; yacc: 3,254; sh: 2,745; xml: 2,483; lex: 1,028; lisp: 215; python: 199; objc: 134; f90: 105; perl: 99; fortran: 93; makefile: 65; tcl: 55; asm: 28; php: 25; ruby: 22; java: 20
file content (59 lines) | stat: -rw-r--r-- 2,249 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
cmake_minimum_required (VERSION 2.6)
project(PrecompiledHeader C)

# Make sure the proper compiler is in use.
if(NOT MSVC AND NOT "${CMAKE_C_COMPILER_ID}" MATCHES "^(Intel)$")
  message(FATAL_ERROR "The PrecompiledHeader test works only with MSVC or Intel")
endif()

# Compute a custom name for the precompiled header.
if(CMAKE_CONFIGURATION_TYPES)
  set(PCH_DIR "${CMAKE_CURRENT_BINARY_DIR}/PCH/${CMAKE_CFG_INTDIR}")
  foreach(cfg ${CMAKE_CONFIGURATION_TYPES})
    file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/PCH/${cfg})
  endforeach()
else()
  set(PCH_DIR "${CMAKE_CURRENT_BINARY_DIR}/PCH")
  file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/PCH)
endif()

# The VS6 IDE does not support renaming .pch files with /Fp.
if("${CMAKE_GENERATOR}" MATCHES "Visual Studio 6")
  set(PCH_USE_INCLUDE_DIR 1)
  set(PCH_FILE)
else()
  set(PCH_USE_INCLUDE_DIR 0)
  set(PCH_FILE "\"/Fp${PCH_DIR}/foo_precompiled.pch\"")
endif()

# Choose between an explicit include path and using /I during
# precompilation.  The /I form is used to test that the PCH is
# actually used.  In practice the include path form would be used.
if(PCH_USE_INCLUDE_DIR)
  include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
else()
  set(PCH_INCLUDE_DIR "\"/I${CMAKE_CURRENT_SOURCE_DIR}/include\"")
endif()

# Create a target that will use a precompiled header.
set(foo_SRCS foo1.c foo2.c)
add_executable(foo foo_precompile.c ${foo_SRCS})

# Setup flags on the target to create and use the precompiled header.
set_target_properties(foo PROPERTIES
  COMPILE_FLAGS "/Yufoo_precompiled.h /FIfoo_precompiled.h ${PCH_FILE}")
set_source_files_properties(foo_precompile.c PROPERTIES
  COMPILE_FLAGS "/Ycfoo_precompiled.h ${PCH_INCLUDE_DIR}")

# Setup dependencies for precompiled header creation and use.  The VS
# IDE takes care of this automatically.
if("${CMAKE_GENERATOR}" MATCHES "Makefile" OR
   "${CMAKE_GENERATOR}" MATCHES "Ninja")
  # This source file creates the precompiled header as a side-effect.
  set_source_files_properties(foo_precompile.c PROPERTIES
    OBJECT_OUTPUTS "${PCH_DIR}/foo_precompiled.pch")

  # These source files use the precompiled header.
  set_source_files_properties(${foo_SRCS} PROPERTIES
    OBJECT_DEPENDS "${PCH_DIR}/foo_precompiled.pch")
endif()