annotate CMakeLists.txt @ 7:b8a79f9fba5a

More fixes and cleanups in CMake build script.
author SokoL_SD
date Thu, 14 May 2009 08:36:04 +0000
parents 834feae7809b
children 16eec94c5b33
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
1 cmake_minimum_required(VERSION 2.6)
1
e78566595089 initial import
mandel
parents:
diff changeset
2 PROJECT(qtd CXX C)
e78566595089 initial import
mandel
parents:
diff changeset
3 FIND_PACKAGE(Qt4 REQUIRED)
e78566595089 initial import
mandel
parents:
diff changeset
4
7
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
5 ##--------------------------------------------
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
6 ## Settings.
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
7 ##--------------------------------------------
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
8
5
834feae7809b Fix include paths in CMake script.
SokoL_SD
parents: 4
diff changeset
9 include_directories(${QT_INCLUDES} include ${CMAKE_CURRENT_BINARY_DIR}/include)
1
e78566595089 initial import
mandel
parents:
diff changeset
10
7
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
11 ## Options.
4
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
12 option(BUILD_QT_OPENGL "Build QtOpenGL" "ON")
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
13 option(BUILD_EXAMPLES "Build examples" "ON")
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
14
7
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
15 ## Packages list.
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
16 set(packages_big Core Gui)
4
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
17 if(BUILD_QT_OPENGL)
7
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
18 set(packages_big ${packages_big} OpenGL)
4
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
19 endif(BUILD_QT_OPENGL)
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
20
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
21 set(packages)
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
22 foreach(package ${packages_big})
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
23 string(TOLOWER ${package} package)
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
24 set(packages ${packages} ${package})
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
25 endforeach(package ${packages_big})
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
26
7
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
27 ## Find D compiler and parsing its version.
4
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
28 find_program(DC dmd ldc)
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
29 if (DC)
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
30 exec_program(${DC} ARGS "" OUTPUT_VARIABLE d_output)
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
31 string(REGEX MATCH "Digital Mars D Compiler v[0-9]\\.[0-9]+" dmd_version "${d_output}")
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
32 if (dmd_version)
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
33 set(D_IS_MARS true)
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
34 set(D_COMPILER_NAME "Digital Mars D Compiler")
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
35 string(REGEX REPLACE "Digital Mars D Compiler v([0-9])\\.[0-9]+" "\\1" D_VERSION "${dmd_version}")
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
36 string(REGEX REPLACE "Digital Mars D Compiler v[0-9]\\.([0-9]+)" "\\1" D_FRONTEND "${dmd_version}")
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
37 else (dmd_version)
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
38 string(REGEX MATCH "LLVM-based D Compiler" is_ldc "${d_output}")
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
39 if (is_ldc)
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
40 exec_program(${DC} ARGS "--version" OUTPUT_VARIABLE d_output)
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
41 string(REGEX MATCH "based on DMD v[0-9]\\.[0-9]+ and llvm [0-9]\\.[0-9]+" ldc_version "${d_output}")
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
42 set(D_IS_LLVM true)
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
43 if(ldc_version)
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
44 set(D_IS_LLVM true)
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
45 set(D_COMPILER_NAME "LLVM-based D Compiler")
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
46 string(REGEX REPLACE "based on DMD v([0-9])\\.[0-9]+ and llvm [0-9]\\.[0-9]+" "\\1" D_VERSION "${ldc_version}")
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
47 string(REGEX REPLACE "based on DMD v[0-9]\\.([0-9]+) and llvm [0-9]\\.[0-9]+" "\\1" D_FRONTEND "${ldc_version}")
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
48 else(ldc_version)
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
49 message(FATAL_ERROR "LDC compiler was found, but the version can not be processed")
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
50 endif(ldc_version)
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
51 else (is_ldc)
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
52 message(FATAL_ERROR "D compliler not founded")
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
53 endif(is_ldc)
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
54 endif(dmd_version)
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
55 message(STATUS "D compiler founded -- ${D_COMPILER_NAME} v${D_VERSION}.${D_FRONTEND}")
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
56 else (DC)
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
57 message(FATAL_ERROR "D compliler not founded")
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
58 endif (DC)
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
59
7
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
60 if(D_IS_MARS)
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
61 option(COMBINED_OBJECT_FILE "Build all d sources to one object file" "ON")
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
62 elseif(D_IS_LLVM)
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
63 option(COMBINED_OBJECT_FILE "Build all d sources to one object file" "OFF")
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
64 endif(D_IS_MARS)
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
65
4
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
66 # Check D compiler version
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
67 if(D_VERSION EQUAL "1")
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
68 if (D_FRONTEND LESS "041")
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
69 message(STATUS "Minimum required version of D compiler is 1.041 (or compiler based on this version)")
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
70 endif(D_FRONTEND LESS "041")
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
71 set(D_TARGET d1-tango)
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
72 elseif(D_VERSION EQUAL "2")
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
73 set(D_TARGET ) ## TODO: hm... I don`t known this parameter for D2 ^(
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
74 endif(D_VERSION EQUAL "1")
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
75
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
76 # Debug and release flags.
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
77 if (${CMAKE_BUILD_TYPE} MATCHES [dD][eE][bB][uU][gG])
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
78 #set(CMAKE_BUILD_TYPE Debug)
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
79 #set( SUFFIXLIB "${SUFFIXLIB}-debug" )
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
80 #set( SUFFIXBIN "${SUFFIXBIN}-debug" )
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
81 add_definitions(-DDEBUG)
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
82 set(D_FLAGS -g -gc -debug)
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
83 else (${CMAKE_BUILD_TYPE} MATCHES [dD][eE][bB][uU][gG])
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
84 #set(CMAKE_BUILD_TYPE Release)
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
85 add_definitions(-UNO_DEBUG)
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
86 set(D_FLAGS -O -release -inline)
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
87 if(${CMAKE_SYSTEM_NAME} STREQUAL Windows)
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
88 set(D_FLAGS ${D_FLAGS} -L/subsystem:windows)
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
89 endif(${CMAKE_SYSTEM_NAME} STREQUAL Windows)
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
90 endif (${CMAKE_BUILD_TYPE} MATCHES [dD][eE][bB][uU][gG])
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
91 set(D_FLAGS ${D_FLAGS} -I${CMAKE_BINARY_DIR} -I${CMAKE_SOURCE_DIR})
7
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
92 if(NOT ${CMAKE_SYSTEM_NAME} STREQUAL Windows AND NOT D_IS_MARS)
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
93 set(D_FLAGS ${D_FLAGS} -L-L${CMAKE_BINARY_DIR}/lib)
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
94 endif(NOT ${CMAKE_SYSTEM_NAME} STREQUAL Windows AND NOT D_IS_MARS)
4
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
95
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
96
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
97 if(${CMAKE_SYSTEM_NAME} STREQUAL Windows)
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
98 set(implib implib)
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
99 find_program(IMPLIB ${implib})
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
100 if (NOT IMPLIB)
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
101 message(FATAL_ERROR "implib not found. You can donwload it from http://ftp.digitalmars.com/bup.zip")
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
102 endif (NOT IMPLIB)
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
103 set(D_OBJECT_SUFFIX .obj)
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
104 if(D_IS_MARS)
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
105 set(D_LIB_SUFFIX .lib)
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
106 set(D_LIB_PREFIX )
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
107 elseif(D_IS_LDC)
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
108 set(D_LIB_SUFFIX .a)
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
109 set(D_LIB_PREFIX lib)
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
110 endif(D_IS_MARS)
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
111 set(GEN_OPT ${GEN_OPT} --cpp_shared)
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
112 add_definitions(-DCPP_SHARED)
7
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
113 string(REGEX REPLACE ".dll([A-Za-z\\.0-9]+)" "\\1" CMAKE_IMPORT_LIBRARY_SUFFIX "${CMAKE_IMPORT_LIBRARY_SUFFIX}")
4
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
114 elseif(${CMAKE_SYSTEM_NAME} STREQUAL Linux)
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
115 set(D_LIB_SUFFIX .a)
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
116 set(D_LIB_PREFIX lib)
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
117 set(D_OBJECT_SUFFIX .o)
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
118 endif(${CMAKE_SYSTEM_NAME} STREQUAL Windows)
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
119
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
120 set(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} ./)
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
121 set(GEN_OPT ${GEN_OPT} --d-target=${D_TARGET})
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
122
7
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
123 ##--------------------------------------------
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
124 ## Macroses and functions.
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
125 ##--------------------------------------------
4
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
126
7
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
127 ## Make native path.
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
128 ## Usage:
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
129 ## set(path c:/file_path/file_name.cpp)
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
130 ## make_native_path(path)
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
131 ## message(STATUS ${path})
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
132 ## Output:
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
133 ## -- "c:\file_path\file_name.cpp"
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
134 ## Command "file(TO_NATIVE_PATH ...)" is wrong on Windows
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
135 macro(MAKE_NATIVE_PATH pathname)
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
136 if(${CMAKE_SYSTEM_NAME} STREQUAL Windows)
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
137 # An extra \\ escape is necessary to get a \ through CMake's processing.
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
138 string(REPLACE "/" "\\" ${pathname} "${${pathname}}")
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
139 # Enclose with UNESCAPED quotes. This means we need to escape our
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
140 # quotes once here, i.e. with \"
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
141 set(${pathname} \"${${pathname}}\")
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
142 endif(${CMAKE_SYSTEM_NAME} STREQUAL Windows)
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
143 endmacro(MAKE_NATIVE_PATH)
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
144
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
145 ## Remove unnecessary travel to the object file.
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
146 ## path -- path to object file.
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
147 ## Example:
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
148 ## set(path ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/target.dir/main.d.obj)
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
149 ## obj_path(path)
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
150 ## message(STATUS ${path})
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
151 ## Example output:
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
152 ## -- CMakeFiles/target.dir/main.d.obj
4
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
153 macro(OBJ_PATH path)
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
154 unset(test)
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
155 string(REGEX MATCH "${CMAKE_CURRENT_BINARY_DIR}/.*" test "${${path}}")
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
156 if(NOT ${test} EQUAL "")
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
157 string(LENGTH "${CMAKE_CURRENT_BINARY_DIR}" first)
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
158 string(LENGTH "${${path}}" last)
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
159 math(EXPR first "${first} + 1")
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
160 math(EXPR len "${last} - ${first}")
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
161 string(SUBSTRING "${${path}}" ${first} ${len} ${path})
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
162 else(NOT ${test} EQUAL "")
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
163 string(REGEX MATCH "${CMAKE_CURRENT_SOURCE_DIR}/.*" test "${${path}}")
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
164 if(NOT ${test} EQUAL "")
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
165 string(LENGTH "${CMAKE_CURRENT_SOURCE_DIR}" first)
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
166 string(LENGTH "${${path}}" last)
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
167 math(EXPR first "${first} + 1")
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
168 math(EXPR len "${last} - ${first}")
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
169 string(SUBSTRING "${${path}}" ${first} ${len} ${path})
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
170 endif(NOT ${test} EQUAL "")
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
171 endif(NOT ${test} EQUAL "")
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
172 endmacro(OBJ_PATH)
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
173
7
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
174
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
175 ## Compile d files.
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
176 ## target -- name of a new target.
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
177 ## objects_list -- created object files.
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
178 ## params -- sources files.
4
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
179 macro(compile_d_files target objects_list)
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
180 unset(${objects_list})
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
181 set(tmp_dir ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${target}.dir)
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
182 file(MAKE_DIRECTORY ${tmp_dir})
7
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
183 if(NOT COMBINED_OBJECT_FILE)
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
184 foreach (d_source_p ${ARGN})
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
185 ## TODO: why find_file command work wrong?
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
186 find_file(d_source_p ${d_source_p} PATHS ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
187 ${CMAKE_BINARY_DIR} ${CMAKE_SOURCE_DIR})
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
188 set (d_source ${d_source_p})
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
189 obj_path(d_source)
4
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
190 set(d_obj ${tmp_dir}/${d_source}${D_OBJECT_SUFFIX})
7
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
191 set(${objects_list} ${${objects_list}} ${d_obj})
4
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
192 get_filename_component(path ${d_obj} PATH)
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
193 file(MAKE_DIRECTORY ${path})
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
194 set(d_obj_out ${d_obj})
7
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
195 obj_path(d_obj_out)
4
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
196 add_custom_command(OUTPUT "${d_obj}"
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
197 COMMAND "${DC}"
7
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
198 ARGS ${D_FLAGS} -c ${d_source_p} -of${d_obj}
4
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
199 COMMENT "Building ${d_obj_out}"
7
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
200 DEPENDS ${d_source_p}
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
201 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
4
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
202 )
7
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
203 endforeach(d_source_p)
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
204 else(NOT COMBINED_OBJECT_FILE)
4
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
205 set(${objects_list} ${tmp_dir}/${target}${D_OBJECT_SUFFIX})
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
206 set(d_obj_out ${${objects_list}})
7
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
207 obj_path(d_obj_out)
4
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
208 set(parameters_list_file ${tmp_dir}/parameters)
7
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
209 set(parameters ${D_FLAGS} -c ${ARGN} -of${${objects_list}})
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
210 file(REMOVE ${parameters_list_file})
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
211 foreach(arg ${parameters})
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
212 file(APPEND ${parameters_list_file} "${arg}\n")
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
213 endforeach(arg)
4
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
214 add_custom_command(OUTPUT "${${objects_list}}"
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
215 COMMAND "${DC}"
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
216 ARGS @${parameters_list_file}
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
217 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
218 DEPENDS ${ARGN}
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
219 COMMENT ""
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
220 )
7
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
221 endif(NOT COMBINED_OBJECT_FILE)
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
222 add_custom_target(${target} DEPENDS "${${objects_list}}")
4
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
223 endmacro(compile_d_files objects_list)
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
224
7
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
225 ## Build example macro.
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
226 ## name -- example name.
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
227 ## Options:
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
228 ## PACKAGES -- list of packages to link to exaple (for example, QtCore QtGui QtOpenGL).
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
229 ## Default value is "QtCore QtGui".
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
230 ## params -- sources d files.
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
231 ## Usage:
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
232 ## build_example(ExampleName PACKAGES QtCore QtGui QtXml main.d another_d_file.d)
4
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
233 macro(build_example name)
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
234 unset(is_sources)
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
235 unset(is_libs)
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
236 set(qtd_libs ${core_lib_param} ${gui_lib_param})
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
237 foreach(param ${ARGN})
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
238 if(is_libs)
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
239 string(REGEX REPLACE "Qt([A-Za-z0-9])" "\\1" param_package "${param}")
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
240 if(${param_package} STREQUAL ${param})
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
241 unset(is_libs)
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
242 set(is_sources 1)
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
243 else(${param_package} STREQUAL ${param})
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
244 unset(is_founded)
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
245 foreach(package_big ${packages_big})
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
246 string(TOLOWER ${package_big} package)
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
247 if(${param_package} STREQUAL ${package_big})
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
248 set(qtd_libs ${qtd_libs} ${${package}_lib_param})
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
249 set(is_founded 1)
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
250 break(package_big ${packages_big})
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
251 endif(${param_package} STREQUAL ${package_big})
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
252 endforeach(package_big ${packages_big})
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
253 if(NOT is_founded)
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
254 message(STATUS "Module ${param_package} not founded for example ${name}")
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
255 return(build_example name)
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
256 endif(NOT is_founded)
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
257 endif(${param_package} STREQUAL ${param})
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
258 endif(is_libs)
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
259 if(NOT is_libs)
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
260 if(NOT is_sources)
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
261 if(${param} STREQUAL PACKAGES)
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
262 set(is_libs 1)
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
263 set(qtd_libs)
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
264 else(${param} STREQUAL PACKAGES)
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
265 set(is_sources 1)
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
266 endif(${param} STREQUAL PACKAGES)
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
267 endif(NOT is_sources)
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
268 if(is_sources)
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
269 set(sources ${sources} ${param})
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
270 endif(is_sources)
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
271 endif(NOT is_libs)
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
272 endforeach(param ${ARGN})
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
273 compile_d_files(${name}_dobjs objects ${sources} )
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
274 set(output ${CMAKE_CURRENT_BINARY_DIR}/${name}${CMAKE_EXECUTABLE_SUFFIX})
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
275 set(output_native ${output})
7
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
276 make_native_path(output_native)
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
277 ## Bug fix: Reverse libs for ldc.
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
278 if(D_IS_LLVM)
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
279 set(qtd_libs_tmp ${qtd_libs})
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
280 unset(qtd_libs)
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
281 foreach(libs ${qtd_libs_tmp})
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
282 set(qtd_libs ${libs} ${qtd_libs})
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
283 endforeach(libs ${qtd_libs_tmp})
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
284 endif(D_IS_LLVM)
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
285
4
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
286 add_custom_command(OUTPUT "${output}"
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
287 COMMAND "${DC}"
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
288 ARGS ${D_FLAGS} ${libs_path} ${qtd_libs} ${objects}
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
289 -of${output_native}
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
290 DEPENDS ${objects}
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
291 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
292 COMMENT "Building example ${name}"
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
293 )
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
294 add_custom_target(example_${name} ALL DEPENDS "${output}")
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
295 add_dependencies(example_${name} allpackages)
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
296 endmacro(build_example sources)
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
297
7
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
298 ##--------------------------------------------
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
299 ## Build library.
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
300 ##--------------------------------------------
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
301 add_subdirectory(generator)
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
302 file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
303 add_custom_target(allpackages ALL)
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
304 link_directories(${CMAKE_BINARY_DIR}/CMakeFiles)
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
305
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
306 foreach(package_big ${packages_big})
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
307 string(TOLOWER ${package_big} package)
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
308 ## Loading settings for package.
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
309 unset(d_objs)
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
310 unset(cpp_objs)
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
311 unset(d_sources)
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
312 unset(cpp_sources)
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
313 unset(lib_name)
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
314 unset(link_cpp)
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
315 unset(link_d)
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
316 unset(cpp_files)
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
317 unset(d_files)
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
318 unset(classes)
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
319 unset(d_generated_files)
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
320 unset(link_example)
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
321 include (${CMAKE_SOURCE_DIR}/build/${package}.txt)
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
322
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
323 ## Loading package sources list.
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
324 foreach(d_source ${d_files})
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
325 set(d_sources ${d_sources} ${CMAKE_SOURCE_DIR}/qt/${d_source}.d)
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
326 endforeach(d_source)
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
327 foreach(d_source ${d_generated_files})
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
328 set(d_sources ${d_sources} ${CMAKE_BINARY_DIR}/qt/${d_source}.d)
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
329 endforeach(d_source)
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
330 foreach (cpp_source ${cpp_files})
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
331 set(cpp_sources ${cpp_sources} ${CMAKE_SOURCE_DIR}/cpp/${cpp_source}.cpp)
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
332 endforeach(cpp_source)
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
333 set(classes ArrayOps ${classes})
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
334 foreach(class ${classes})
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
335 set(d_sources ${d_sources} ${CMAKE_BINARY_DIR}/qt/${package}/${class}.d)
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
336 set(cpp_sources ${cpp_sources} ${CMAKE_BINARY_DIR}/cpp/qt_${package}/${class}_shell.cpp)
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
337 endforeach(class)
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
338 add_sources_for_generating(${cpp_sources})
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
339
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
340 ## Link CPP library.
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
341 set(lib_name ${D_LIB_PREFIX}qtd${package}${D_LIB_SUFFIX})
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
342 add_library(cpp_${package} SHARED ${cpp_sources})
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
343
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
344 ## Link D library.
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
345 compile_d_files(${package}_dobjs objects ${d_sources})
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
346 set(d_objs ${d_objs} ${objects})
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
347 if(${CMAKE_SYSTEM_NAME} STREQUAL Windows)
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
348 set_property(TARGET cpp_${package} PROPERTY RUNTIME_OUTPUT_DIRECTORY lib)
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
349 set_property(TARGET cpp_${package} PROPERTY ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/CMakeFiles)
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
350 target_link_libraries(cpp_${package} ${link_cpp} )
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
351 set(cpp_lib ${CMAKE_BINARY_DIR}/lib/libcpp_${package}.dll)
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
352 set(cpp_lib_native ${cpp_lib})
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
353 make_native_path(cpp_lib_native)
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
354 set(d_implib ${CMAKE_BINARY_DIR}/CMakeFiles/${package}.dir/cpp_${package}.lib)
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
355 set(d_implib_native ${d_implib})
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
356 make_native_path(d_implib_native)
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
357 add_custom_command(
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
358 OUTPUT "${d_implib}"
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
359 COMMAND "${IMPLIB}"
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
360 ARGS /system /PAGESIZE:32 ${d_implib_native} ${cpp_lib_native}
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
361 DEPENDS "cpp_${package}"
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
362 COMMENT "Creating implib ${lib_name}"
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
363 )
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
364 add_custom_command(
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
365 OUTPUT "${lib_name}"
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
366 COMMAND "${DC}"
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
367 ARGS -lib ${d_objs} ${d_implib} -oflib/${lib_name}
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
368 DEPENDS ${d_objs} ${d_implib}
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
369 COMMENT "Linking ${lib_name}"
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
370 )
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
371 else(${CMAKE_SYSTEM_NAME} STREQUAL Linux)
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
372 set_property(TARGET cpp_${package} PROPERTY LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/CMakeFiles)
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
373 foreach(cpp_source ${cpp_sources})
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
374 set(cpp_source ${cpp_source})
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
375 obj_path(cpp_source)
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
376 set(cpp_objs ${cpp_objs} CMakeFiles/cpp_${package}.dir/${cpp_source}.o)
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
377 endforeach(cpp_source)
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
378 add_custom_command(
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
379 OUTPUT "${lib_name}"
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
380 COMMAND "${CMAKE_AR}"
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
381 ARGS rcs lib/${lib_name} ${d_objs} ${cpp_objs}
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
382 DEPENDS ${d_objs} cpp_${package}
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
383 COMMENT "Linking ${lib_name}"
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
384 )
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
385 endif(${CMAKE_SYSTEM_NAME} STREQUAL Windows)
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
386
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
387 ## Dependences.
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
388 add_dependencies(cpp_${package} dgen)
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
389 add_custom_target(${package} DEPENDS ${lib_name})
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
390 foreach(depend ${depends})
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
391 add_dependencies(cpp_${package} cpp_${depend})
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
392 add_dependencies(${package} ${depend})
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
393 endforeach(depend ${depends})
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
394 add_dependencies(allpackages ${package})
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
395 set(depends ${depends} ${package})
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
396
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
397 ## Paths for QtD libs. Needed by examples.
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
398 if(${CMAKE_SYSTEM_NAME} STREQUAL Windows AND D_IS_MARS)
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
399 set(libs_path ${CMAKE_BINARY_DIR}/lib/qtd${package}.lib)
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
400 make_native_path(libs_path)
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
401 set(${package}_lib_param -L+${libs_path})
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
402 foreach(link ${link_example})
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
403 set(link ${CMAKE_SOURCE_DIR}/lib/${link}.lib)
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
404 make_native_path(link)
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
405 set(link -L+${link})
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
406 set(${package}_lib_param ${${package}_lib_param} ${link})
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
407 endforeach(link ${link_example})
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
408 else (${CMAKE_SYSTEM_NAME} STREQUAL Windows AND D_IS_MARS)
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
409 set(${package}_lib_param -L-lqtd${package} -L-lQt${package_big})
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
410 foreach(link ${link_example})
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
411 set(${package}_lib_param ${${package}_lib_param} ${link})
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
412 endforeach(link ${link_example})
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
413 endif(${CMAKE_SYSTEM_NAME} STREQUAL Windows AND D_IS_MARS)
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
414 endforeach(package_big ${packages_big})
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
415
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
416 ##--------------------------------------------
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
417 ## Build other parts of the QtD.
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
418 ##--------------------------------------------
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
419 if(BUILD_EXAMPLES)
4
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
420 add_subdirectory(demos)
0a29ce1ae854 CMake build script.
SokoL_SD
parents: 1
diff changeset
421 add_subdirectory(examples)
7
b8a79f9fba5a More fixes and cleanups in CMake build script.
SokoL_SD
parents: 5
diff changeset
422 endif(BUILD_EXAMPLES)