Mercurial > hg > orthanc
comparison CMakeLists.txt @ 134:bdc60d16cc98
improved cmake
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 09 Oct 2012 11:58:22 +0200 |
parents | 1969ff16457c |
children | a2dbb5024fdf |
comparison
equal
deleted
inserted
replaced
133:1969ff16457c | 134:bdc60d16cc98 |
---|---|
1 cmake_minimum_required(VERSION 2.8) | 1 cmake_minimum_required(VERSION 2.8) |
2 | 2 |
3 project(Orthanc) | 3 project(Orthanc) |
4 | |
5 # Parameters of the build | |
6 SET(STATIC_BUILD ON CACHE BOOL "Static build of the third-party libraries (necessary for Windows)") | |
7 SET(STANDALONE_BUILD OFF CACHE BOOL "Standalone build (all the resources are embedded, necessary for releases)") | |
8 SET(ENABLE_SSL ON CACHE BOOL "Include support for SSL") | |
9 SET(BUILD_UNIT_TESTS ON CACHE BOOL "Build the unit tests") | |
10 SET(DEBIAN_FORCE_HARDENING OFF CACHE BOOL "Force the injection of Debian hardening flags (unrecommended)") | |
11 SET(USE_DYNAMIC_JSONCPP OFF CACHE BOOL "Use the dynamic version of JsonCpp (only for Debian sid)") | |
12 SET(USE_DYNAMIC_GOOGLE_LOG ON CACHE BOOL "Use the dynamic version of Google Log") | |
13 SET(USE_DYNAMIC_GOOGLE_TEST ON CACHE BOOL "Use the dynamic version of Google Test (not for Debian sid)") | |
14 SET(USE_STATIC_DEBIAN_GOOGLE_TEST OFF CACHE BOOL "Use the sources of Google Test shipped with libgtest-dev (only for Debian sid)") | |
15 | |
16 # Version of the build, should always be "mainline" except in release branches | |
17 add_definitions( | |
18 -DORTHANC_VERSION="mainline" | |
19 ) | |
20 | |
21 # Some basic inclusions | |
22 include(CheckIncludeFiles) | |
23 include(CheckIncludeFileCXX) | |
4 include(${CMAKE_SOURCE_DIR}/Resources/CMake/AutoGeneratedCode.cmake) | 24 include(${CMAKE_SOURCE_DIR}/Resources/CMake/AutoGeneratedCode.cmake) |
5 include(${CMAKE_SOURCE_DIR}/Resources/CMake/DownloadPackage.cmake) | 25 include(${CMAKE_SOURCE_DIR}/Resources/CMake/DownloadPackage.cmake) |
6 include(CheckIncludeFiles) | 26 include(${CMAKE_SOURCE_DIR}/Resources/CMake/Compiler.cmake) |
7 include(CheckIncludeFileCXX) | |
8 | 27 |
9 add_definitions(-DORTHANC_VERSION="mainline") | 28 # Configuration of the standalone builds |
10 | |
11 SET(STATIC_BUILD ON CACHE BOOL "Static build of the third-party libraries (necessary for Windows)") | |
12 SET(STANDALONE_BUILD OFF CACHE BOOL "Standalone build (necessary for cross-compilation or binary releases)") | |
13 SET(ENABLE_SSL ON CACHE BOOL "Include support for SSL") | |
14 SET(BUILD_UNIT_TESTS ON CACHE BOOL "Build the unit tests") | |
15 SET(DEBIAN_HARDENING OFF CACHE BOOL "Use Debian hardening flags") | |
16 SET(USE_DYNAMIC_JSONCPP OFF CACHE BOOL "Use the dynamic version of JsonCpp, only for Debian Unstable") | |
17 SET(USE_DYNAMIC_GOOGLE_LOG ON CACHE BOOL "Use the dynamic version of Google Log") | |
18 | |
19 if (${CMAKE_CROSSCOMPILING}) | 29 if (${CMAKE_CROSSCOMPILING}) |
30 # Cross-compilation implies the standalone build | |
20 SET(STANDALONE_BUILD ON) | 31 SET(STANDALONE_BUILD ON) |
21 endif() | 32 endif() |
22 | 33 |
23 if (${CMAKE_SYSTEM_NAME} STREQUAL "Windows") | 34 if (${STANDALONE_BUILD}) |
24 CHECK_INCLUDE_FILES(rpc.h HAVE_UUID_H) | 35 # We embed all the resources in the binaries for standalone builds |
36 add_definitions(-DORTHANC_STANDALONE=1) | |
37 EmbedResources( | |
38 PREPARE_DATABASE OrthancServer/PrepareDatabase.sql | |
39 ORTHANC_EXPLORER OrthancExplorer | |
40 ) | |
25 else() | 41 else() |
26 CHECK_INCLUDE_FILES(uuid/uuid.h HAVE_UUID_H) | 42 add_definitions( |
27 endif() | 43 -DORTHANC_STANDALONE=0 |
28 | 44 -DORTHANC_PATH=\"${CMAKE_SOURCE_DIR}\" |
29 if (NOT HAVE_UUID_H) | 45 ) |
30 message(FATAL_ERROR "Please install the uuid-dev package") | 46 EmbedResources( |
47 PREPARE_DATABASE OrthancServer/PrepareDatabase.sql | |
48 ) | |
31 endif() | 49 endif() |
32 | 50 |
33 | 51 |
52 # Prepare the third-party dependencies | |
34 SET(THIRD_PARTY_SOURCES | 53 SET(THIRD_PARTY_SOURCES |
35 ${CMAKE_SOURCE_DIR}/Resources/md5/md5.c | 54 ${CMAKE_SOURCE_DIR}/Resources/md5/md5.c |
36 ${CMAKE_SOURCE_DIR}/Resources/base64/base64.cpp | 55 ${CMAKE_SOURCE_DIR}/Resources/base64/base64.cpp |
37 ) | 56 ) |
38 | 57 |
53 include(${CMAKE_SOURCE_DIR}/Resources/CMake/JsonCppConfiguration.cmake) | 72 include(${CMAKE_SOURCE_DIR}/Resources/CMake/JsonCppConfiguration.cmake) |
54 include(${CMAKE_SOURCE_DIR}/Resources/CMake/LibCurlConfiguration.cmake) | 73 include(${CMAKE_SOURCE_DIR}/Resources/CMake/LibCurlConfiguration.cmake) |
55 include(${CMAKE_SOURCE_DIR}/Resources/CMake/LibPngConfiguration.cmake) | 74 include(${CMAKE_SOURCE_DIR}/Resources/CMake/LibPngConfiguration.cmake) |
56 | 75 |
57 | 76 |
58 if (${CMAKE_COMPILER_IS_GNUCXX}) | 77 # The main instructions to build the Orthanc binaries |
59 set(CMAKE_C_FLAGS "-Wall -Wno-long-long -Wno-implicit-function-declaration") | |
60 # --std=c99 makes libcurl not to compile | |
61 # -pedantic gives a lot of warnings on OpenSSL | |
62 set(CMAKE_CXX_FLAGS "-Wall -pedantic -Wno-long-long -Wno-variadic-macros") | |
63 elseif (${MSVC}) | |
64 # http://stackoverflow.com/a/6510446 | |
65 foreach(flag_var | |
66 CMAKE_C_FLAGS_DEBUG | |
67 CMAKE_CXX_FLAGS_DEBUG | |
68 CMAKE_C_FLAGS_RELEASE | |
69 CMAKE_CXX_FLAGS_RELEASE | |
70 CMAKE_C_FLAGS_MINSIZEREL | |
71 CMAKE_CXX_FLAGS_MINSIZEREL | |
72 CMAKE_C_FLAGS_RELWITHDEBINFO | |
73 CMAKE_CXX_FLAGS_RELWITHDEBINFO) | |
74 string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}") | |
75 string(REGEX REPLACE "/MDd" "/MTd" ${flag_var} "${${flag_var}}") | |
76 endforeach(flag_var) | |
77 add_definitions( | |
78 -D_CRT_SECURE_NO_WARNINGS=1 | |
79 -D_CRT_SECURE_NO_DEPRECATE=1 | |
80 ) | |
81 include_directories(${CMAKE_SOURCE_DIR}/Resources/VisualStudio) | |
82 link_libraries(netapi32) | |
83 endif() | |
84 | |
85 | |
86 if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux") | |
87 if (DEBIAN_HARDENING) | |
88 execute_process( | |
89 COMMAND dpkg-buildflags --get CPPFLAGS | |
90 OUTPUT_VARIABLE DEBIAN_CPP_FLAGS | |
91 OUTPUT_STRIP_TRAILING_WHITESPACE) | |
92 execute_process( | |
93 COMMAND dpkg-buildflags --get CFLAGS | |
94 OUTPUT_VARIABLE DEBIAN_C_FLAGS | |
95 OUTPUT_STRIP_TRAILING_WHITESPACE) | |
96 execute_process( | |
97 COMMAND dpkg-buildflags --get CXXFLAGS | |
98 OUTPUT_VARIABLE DEBIAN_CXX_FLAGS | |
99 OUTPUT_STRIP_TRAILING_WHITESPACE) | |
100 execute_process( | |
101 COMMAND dpkg-buildflags --get LDFLAGS | |
102 OUTPUT_VARIABLE DEBIAN_LD_FLAGS | |
103 OUTPUT_STRIP_TRAILING_WHITESPACE) | |
104 | |
105 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${DEBIAN_C_FLAGS} ${DEBIAN_CPP_FLAGS}") | |
106 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${DEBIAN_CXX_FLAGS} ${DEBIAN_CPP_FLAGS}") | |
107 endif() | |
108 | |
109 add_definitions( | |
110 -D_LARGEFILE64_SOURCE=1 | |
111 -D_FILE_OFFSET_BITS=64 | |
112 ) | |
113 set(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed ${DEBIAN_LD_FLAGS}") | |
114 set(CMAKE_MODULE_LINKER_FLAGS "-Wl,--no-undefined ${DEBIAN_LD_FLAGS}") | |
115 set(CMAKE_SHARED_LINKER_FLAGS "-Wl,--no-undefined ${DEBIAN_LD_FLAGS}") | |
116 | |
117 # http://www.mail-archive.com/cmake@cmake.org/msg08837.html | |
118 set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "") | |
119 link_libraries(uuid pthread rt) | |
120 | |
121 elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Windows") | |
122 add_definitions( | |
123 -DWINVER=0x0501 | |
124 -D_CRT_SECURE_NO_WARNINGS=1 | |
125 ) | |
126 link_libraries(rpcrt4 ws2_32) | |
127 endif() | |
128 | |
129 | |
130 if (${STATIC_BUILD}) | |
131 add_definitions(-DORTHANC_STATIC=1) | |
132 else() | |
133 add_definitions(-DORTHANC_STATIC=0) | |
134 endif() | |
135 | |
136 if (${STANDALONE_BUILD}) | |
137 add_definitions( | |
138 -DORTHANC_STANDALONE=1 | |
139 ) | |
140 | |
141 EmbedResources( | |
142 PREPARE_DATABASE OrthancServer/PrepareDatabase.sql | |
143 ORTHANC_EXPLORER OrthancExplorer | |
144 ) | |
145 | |
146 else() | |
147 add_definitions( | |
148 -DORTHANC_STANDALONE=0 | |
149 -DORTHANC_PATH=\"${CMAKE_SOURCE_DIR}\" | |
150 ) | |
151 | |
152 EmbedResources( | |
153 PREPARE_DATABASE OrthancServer/PrepareDatabase.sql | |
154 ) | |
155 endif() | |
156 | |
157 | |
158 add_library(CoreLibrary | 78 add_library(CoreLibrary |
159 STATIC | 79 STATIC |
160 ${AUTOGENERATED_SOURCES} | 80 ${AUTOGENERATED_SOURCES} |
161 ${THIRD_PARTY_SOURCES} | 81 ${THIRD_PARTY_SOURCES} |
162 | 82 |
210 | 130 |
211 add_executable(Orthanc | 131 add_executable(Orthanc |
212 OrthancServer/main.cpp | 132 OrthancServer/main.cpp |
213 ) | 133 ) |
214 | 134 |
215 TARGET_LINK_LIBRARIES(Orthanc ServerLibrary CoreLibrary) | 135 target_link_libraries(Orthanc ServerLibrary CoreLibrary) |
216 | 136 |
217 | 137 |
138 # Build the unit tests if required | |
218 if (BUILD_UNIT_TESTS) | 139 if (BUILD_UNIT_TESTS) |
219 include(${CMAKE_SOURCE_DIR}/Resources/CMake/GoogleTestConfiguration.cmake) | 140 include(${CMAKE_SOURCE_DIR}/Resources/CMake/GoogleTestConfiguration.cmake) |
220 add_executable(UnitTests | 141 add_executable(UnitTests |
221 ${GTEST_SOURCES} | 142 ${GTEST_SOURCES} |
222 UnitTests/main.cpp | 143 UnitTests/main.cpp |
223 UnitTests/SQLite.cpp | 144 UnitTests/SQLite.cpp |
224 UnitTests/SQLiteChromium.cpp | 145 UnitTests/SQLiteChromium.cpp |
225 UnitTests/Versions.cpp | 146 UnitTests/Versions.cpp |
226 UnitTests/Zip.cpp | 147 UnitTests/Zip.cpp |
227 ) | 148 ) |
228 TARGET_LINK_LIBRARIES(UnitTests ServerLibrary CoreLibrary) | 149 target_link_libraries(UnitTests ServerLibrary CoreLibrary) |
229 endif() | 150 endif() |
230 | 151 |
231 | 152 |
153 # Generate the Doxygen documentation if Doxygen is present | |
232 find_package(Doxygen) | 154 find_package(Doxygen) |
233 if (DOXYGEN_FOUND) | 155 if (DOXYGEN_FOUND) |
234 configure_file( | 156 configure_file( |
235 ${CMAKE_SOURCE_DIR}/Resources/Orthanc.doxygen | 157 ${CMAKE_SOURCE_DIR}/Resources/Orthanc.doxygen |
236 ${CMAKE_CURRENT_BINARY_DIR}/Orthanc.doxygen | 158 ${CMAKE_CURRENT_BINARY_DIR}/Orthanc.doxygen |
238 add_custom_target(doc | 160 add_custom_target(doc |
239 ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Orthanc.doxygen | 161 ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Orthanc.doxygen |
240 WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} | 162 WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} |
241 COMMENT "Generating API documentation with Doxygen" VERBATIM | 163 COMMENT "Generating API documentation with Doxygen" VERBATIM |
242 ) | 164 ) |
243 endif(DOXYGEN_FOUND) | 165 endif() |