comparison Orthanc/Resources/CMake/Compiler.cmake @ 14:f7379096e014

fix
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 04 Jan 2016 14:21:51 +0100
parents
children
comparison
equal deleted inserted replaced
13:a07ee8b6946e 14:f7379096e014
1 # This file sets all the compiler-related flags
2
3 if (CMAKE_CROSSCOMPILING)
4 # Cross-compilation necessarily implies standalone and static build
5 SET(STATIC_BUILD ON)
6 SET(STANDALONE_BUILD ON)
7 endif()
8
9 if (CMAKE_COMPILER_IS_GNUCXX)
10 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wno-long-long -Wno-implicit-function-declaration")
11 # --std=c99 makes libcurl not to compile
12 # -pedantic gives a lot of warnings on OpenSSL
13 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -pedantic -Wno-long-long -Wno-variadic-macros")
14
15 if (CMAKE_CROSSCOMPILING)
16 # http://stackoverflow.com/a/3543845/881731
17 set(CMAKE_RC_COMPILE_OBJECT "<CMAKE_RC_COMPILER> -O coff -I<CMAKE_CURRENT_SOURCE_DIR> <SOURCE> <OBJECT>")
18 endif()
19
20 elseif (MSVC)
21 # Use static runtime under Visual Studio
22 # http://www.cmake.org/Wiki/CMake_FAQ#Dynamic_Replace
23 # http://stackoverflow.com/a/6510446
24 foreach(flag_var
25 CMAKE_C_FLAGS_DEBUG
26 CMAKE_CXX_FLAGS_DEBUG
27 CMAKE_C_FLAGS_RELEASE
28 CMAKE_CXX_FLAGS_RELEASE
29 CMAKE_C_FLAGS_MINSIZEREL
30 CMAKE_CXX_FLAGS_MINSIZEREL
31 CMAKE_C_FLAGS_RELWITHDEBINFO
32 CMAKE_CXX_FLAGS_RELWITHDEBINFO)
33 string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
34 string(REGEX REPLACE "/MDd" "/MTd" ${flag_var} "${${flag_var}}")
35 endforeach(flag_var)
36
37 # Add /Zm256 compiler option to Visual Studio to fix PCH errors
38 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Zm256")
39
40 add_definitions(
41 -D_CRT_SECURE_NO_WARNINGS=1
42 -D_CRT_SECURE_NO_DEPRECATE=1
43 )
44 include_directories(${ORTHANC_ROOT}/Resources/ThirdParty/VisualStudio)
45 link_libraries(netapi32)
46 endif()
47
48
49 if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux" OR
50 ${CMAKE_SYSTEM_NAME} STREQUAL "kFreeBSD" OR
51 ${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD")
52 set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -Wl,--no-undefined")
53 set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--no-undefined")
54
55 if (NOT DEFINED ENABLE_PLUGINS_VERSION_SCRIPT OR
56 ENABLE_PLUGINS_VERSION_SCRIPT)
57 set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--version-script=${ORTHANC_ROOT}/Plugins/Samples/Common/VersionScript.map")
58 endif()
59
60 # Remove the "-rdynamic" option
61 # http://www.mail-archive.com/cmake@cmake.org/msg08837.html
62 set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "")
63 link_libraries(uuid pthread rt)
64
65 if (NOT ${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD")
66 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--as-needed")
67 set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -Wl,--as-needed")
68 set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--as-needed")
69 add_definitions(
70 -D_LARGEFILE64_SOURCE=1
71 -D_FILE_OFFSET_BITS=64
72 )
73 link_libraries(dl)
74 endif()
75
76 elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
77 if (MSVC)
78 message("MSVC compiler version = " ${MSVC_VERSION} "\n")
79 # Starting Visual Studio 2013 (version 1800), it is not possible
80 # to target Windows XP anymore
81 if (MSVC_VERSION LESS 1800)
82 add_definitions(
83 -DWINVER=0x0501
84 -D_WIN32_WINNT=0x0501
85 )
86 endif()
87 else()
88 add_definitions(
89 -DWINVER=0x0501
90 -D_WIN32_WINNT=0x0501
91 )
92 endif()
93
94 add_definitions(
95 -D_CRT_SECURE_NO_WARNINGS=1
96 )
97 link_libraries(rpcrt4 ws2_32)
98
99 if (CMAKE_COMPILER_IS_GNUCXX)
100 # This is a patch for MinGW64
101 SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--allow-multiple-definition -static-libgcc -static-libstdc++")
102 SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--allow-multiple-definition -static-libgcc -static-libstdc++")
103
104 CHECK_LIBRARY_EXISTS(winpthread pthread_create "" HAVE_WIN_PTHREAD)
105 if (HAVE_WIN_PTHREAD)
106 # This line is necessary to compile with recent versions of MinGW,
107 # otherwise "libwinpthread-1.dll" is not statically linked.
108 SET(CMAKE_CXX_STANDARD_LIBRARIES "${CMAKE_CXX_STANDARD_LIBRARIES} -Wl,-Bstatic -lstdc++ -lpthread -Wl,-Bdynamic")
109 add_definitions(-DHAVE_WIN_PTHREAD=1)
110 else()
111 add_definitions(-DHAVE_WIN_PTHREAD=0)
112 endif()
113 endif()
114
115 elseif (${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
116 SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -exported_symbols_list ${ORTHANC_ROOT}/Plugins/Samples/Common/ExportedSymbols.list")
117
118 add_definitions(
119 -D_XOPEN_SOURCE=1
120 )
121 link_libraries(iconv)
122
123 endif()
124
125
126 if ("${CMAKE_SYSTEM_VERSION}" STREQUAL "LinuxStandardBase")
127 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --lsb-target-version=${LSB_TARGET_VERSION} -I${LSB_PATH}/include")
128 SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --lsb-target-version=${LSB_TARGET_VERSION} -nostdinc++ -I${LSB_PATH}/include -I${LSB_PATH}/include/c++ -I${LSB_PATH}/include/c++/backward -fpermissive")
129 SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} --lsb-target-version=${LSB_TARGET_VERSION} -L${LSB_LIBPATH}")
130 endif()
131
132
133 if (${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD")
134 # In FreeBSD, the "/usr/local/" folder contains the ports and need to be imported
135 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -I/usr/local/include")
136 SET(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} -I/usr/local/include")
137 SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -L/usr/local/lib")
138 SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -L/usr/local/lib")
139 endif()
140
141
142 if (${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
143 CHECK_INCLUDE_FILES(rpc.h HAVE_UUID_H)
144 else()
145 CHECK_INCLUDE_FILES(uuid/uuid.h HAVE_UUID_H)
146 endif()
147
148 if (NOT HAVE_UUID_H)
149 message(FATAL_ERROR "Please install the uuid-dev package")
150 endif()
151
152
153 if (STATIC_BUILD)
154 add_definitions(-DORTHANC_STATIC=1)
155 else()
156 add_definitions(-DORTHANC_STATIC=0)
157 endif()