annotate Resources/Orthanc/CMake/Compiler.cmake @ 153:c78ec45f3695

sync
author Sebastien Jodogne <s.jodogne@gmail.com>
date Sat, 16 Mar 2024 11:55:27 +0100
parents 4cf3c2bc119f
children 6fada29b6759
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
40
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 36
diff changeset
1 # Orthanc - A Lightweight, RESTful DICOM Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 36
diff changeset
2 # Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 36
diff changeset
3 # Department, University Hospital of Liege, Belgium
153
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 132
diff changeset
4 # Copyright (C) 2017-2024 Osimis S.A., Belgium
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 132
diff changeset
5 # Copyright (C) 2021-2024 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
40
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 36
diff changeset
6 #
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 36
diff changeset
7 # This program is free software: you can redistribute it and/or
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 36
diff changeset
8 # modify it under the terms of the GNU Lesser General Public License
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 36
diff changeset
9 # as published by the Free Software Foundation, either version 3 of
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 36
diff changeset
10 # the License, or (at your option) any later version.
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 36
diff changeset
11 #
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 36
diff changeset
12 # This program is distributed in the hope that it will be useful, but
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 36
diff changeset
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 36
diff changeset
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 36
diff changeset
15 # Lesser General Public License for more details.
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 36
diff changeset
16 #
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 36
diff changeset
17 # You should have received a copy of the GNU Lesser General Public
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 36
diff changeset
18 # License along with this program. If not, see
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 36
diff changeset
19 # <http://www.gnu.org/licenses/>.
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 36
diff changeset
20
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 36
diff changeset
21
36
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 # This file sets all the compiler-related flags
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 # Save the current compiler flags to the cache every time cmake configures the project
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}" CACHE STRING "compiler flags" FORCE)
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" CACHE STRING "compiler flags" FORCE)
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 include(CheckLibraryExists)
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32 if ((CMAKE_CROSSCOMPILING AND NOT
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 "${CMAKE_SYSTEM_VERSION}" STREQUAL "CrossToolNg") OR
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 "${CMAKE_SYSTEM_VERSION}" STREQUAL "LinuxStandardBase")
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 # Cross-compilation necessarily implies standalone and static build
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 SET(STATIC_BUILD ON)
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 SET(STANDALONE_BUILD ON)
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 endif()
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 if ("${CMAKE_SYSTEM_VERSION}" STREQUAL "LinuxStandardBase")
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 # Cache the environment variables "LSB_CC" and "LSB_CXX" for further
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 # use by "ExternalProject" in CMake
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 SET(CMAKE_LSB_CC $ENV{LSB_CC} CACHE STRING "")
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 SET(CMAKE_LSB_CXX $ENV{LSB_CXX} CACHE STRING "")
153
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 132
diff changeset
46
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 132
diff changeset
47 # This is necessary to build "Orthanc mainline - Framework LSB
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 132
diff changeset
48 # Release" on "buildbot-worker-debian11"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 132
diff changeset
49 set(LSB_PTHREAD_NONSHARED "${LSB_PATH}/lib64-${LSB_TARGET_VERSION}/libpthread_nonshared.a")
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 132
diff changeset
50 if (EXISTS ${LSB_PTHREAD_NONSHARED})
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 132
diff changeset
51 set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${LSB_PTHREAD_NONSHARED}")
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 132
diff changeset
52 endif()
36
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 endif()
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 if (CMAKE_COMPILER_IS_GNUCXX)
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wno-long-long")
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 # --std=c99 makes libcurl not to compile
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 # -pedantic gives a lot of warnings on OpenSSL
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wno-long-long -Wno-variadic-macros")
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 if (CMAKE_CROSSCOMPILING)
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 # http://stackoverflow.com/a/3543845/881731
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 set(CMAKE_RC_COMPILE_OBJECT "<CMAKE_RC_COMPILER> -O coff -I<CMAKE_CURRENT_SOURCE_DIR> <SOURCE> <OBJECT>")
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 endif()
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 elseif (MSVC)
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 # Use static runtime under Visual Studio
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 # http://www.cmake.org/Wiki/CMake_FAQ#Dynamic_Replace
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 # http://stackoverflow.com/a/6510446
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 foreach(flag_var
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 CMAKE_C_FLAGS_DEBUG
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 CMAKE_CXX_FLAGS_DEBUG
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 CMAKE_C_FLAGS_RELEASE
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 CMAKE_CXX_FLAGS_RELEASE
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 CMAKE_C_FLAGS_MINSIZEREL
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 CMAKE_CXX_FLAGS_MINSIZEREL
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 CMAKE_C_FLAGS_RELWITHDEBINFO
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 CMAKE_CXX_FLAGS_RELWITHDEBINFO)
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 string(REGEX REPLACE "/MDd" "/MTd" ${flag_var} "${${flag_var}}")
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 endforeach(flag_var)
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 # Add /Zm256 compiler option to Visual Studio to fix PCH errors
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Zm256")
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 # New in Orthanc 1.5.5
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 if (MSVC_MULTIPLE_PROCESSES)
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90 # "If you omit the processMax argument in the /MP option, the
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 # compiler obtains the number of effective processors from the
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 # operating system, and then creates one process per effective
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 # processor"
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 # https://blog.kitware.com/cmake-building-with-all-your-cores/
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95 # https://docs.microsoft.com/en-us/cpp/build/reference/mp-build-with-multiple-processes
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /MP")
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP")
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 endif()
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100 add_definitions(
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101 -D_CRT_SECURE_NO_WARNINGS=1
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102 -D_CRT_SECURE_NO_DEPRECATE=1
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103 )
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105 if (MSVC_VERSION LESS 1600)
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106 # Starting with Visual Studio >= 2010 (i.e. macro _MSC_VER >=
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107 # 1600), Microsoft ships a standard-compliant <stdint.h>
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 # header. For earlier versions of Visual Studio, give access to a
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 # compatibility header.
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110 # http://stackoverflow.com/a/70630/881731
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111 # https://en.wikibooks.org/wiki/C_Programming/C_Reference/stdint.h#External_links
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 include_directories(${CMAKE_CURRENT_LIST_DIR}/../../Resources/ThirdParty/VisualStudio)
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113 endif()
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115 link_libraries(netapi32)
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116 endif()
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119 if (${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD" OR
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120 ${CMAKE_SYSTEM_NAME} STREQUAL "OpenBSD")
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121 # In FreeBSD/OpenBSD, the "/usr/local/" folder contains the ports and need to be imported
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -I/usr/local/include")
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123 SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -I/usr/local/include")
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124 SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -L/usr/local/lib")
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125 SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -L/usr/local/lib")
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126 endif()
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129 if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux" OR
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130 ${CMAKE_SYSTEM_NAME} STREQUAL "kFreeBSD" OR
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131 ${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD" OR
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132 ${CMAKE_SYSTEM_NAME} STREQUAL "OpenBSD")
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
133
153
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 132
diff changeset
134 if (# NOT ${CMAKE_SYSTEM_VERSION} STREQUAL "LinuxStandardBase" AND
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 132
diff changeset
135 NOT ${CMAKE_SYSTEM_NAME} STREQUAL "OpenBSD" AND
36
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
136 NOT ${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD")
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137 # The "--no-undefined" linker flag makes the shared libraries
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138 # (plugins ModalityWorklists and ServeFolders) fail to compile on
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139 # OpenBSD, and make the PostgreSQL plugin complain about missing
153
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 132
diff changeset
140 # "environ" global variable in FreeBSD.
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 132
diff changeset
141 #
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 132
diff changeset
142 # TODO - Furthermore, on Linux Standard Base running on Debian 12,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 132
diff changeset
143 # the "-Wl,--no-undefined" seems to break the compilation (added
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 132
diff changeset
144 # after Orthanc 1.12.2). This is disabled for now.
36
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145 set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -Wl,--no-undefined")
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146 set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--no-undefined")
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
147 endif()
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
148
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149 # Remove the "-rdynamic" option
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
150 # http://www.mail-archive.com/cmake@cmake.org/msg08837.html
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
151 set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "")
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
152 link_libraries(pthread)
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
153
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
154 if (NOT ${CMAKE_SYSTEM_NAME} STREQUAL "OpenBSD")
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155 link_libraries(rt)
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
156 endif()
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
157
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
158 if (NOT ${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD" AND
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
159 NOT ${CMAKE_SYSTEM_NAME} STREQUAL "OpenBSD")
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
160 link_libraries(dl)
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
161 endif()
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
162
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
163 if (NOT ${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD" AND
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
164 NOT ${CMAKE_SYSTEM_NAME} STREQUAL "OpenBSD")
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
165 # The "--as-needed" linker flag is not available on FreeBSD and OpenBSD
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
166 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--as-needed")
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
167 set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -Wl,--as-needed")
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
168 set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--as-needed")
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
169 endif()
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
170
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
171 if (NOT ${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD" AND
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
172 NOT ${CMAKE_SYSTEM_NAME} STREQUAL "OpenBSD")
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
173 # FreeBSD/OpenBSD have just one single interface for file
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
174 # handling, which is 64bit clean, so there is no need to define macro
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
175 # for LFS (Large File Support).
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
176 # https://ohse.de/uwe/articles/lfs.html
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
177 add_definitions(
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
178 -D_LARGEFILE64_SOURCE=1
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
179 -D_FILE_OFFSET_BITS=64
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
180 )
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
181 endif()
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
182
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
183 elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
184 if (MSVC)
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
185 message("MSVC compiler version = " ${MSVC_VERSION} "\n")
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
186 # Starting Visual Studio 2013 (version 1800), it is not possible
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
187 # to target Windows XP anymore
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
188 if (MSVC_VERSION LESS 1800)
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
189 add_definitions(
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
190 -DWINVER=0x0501
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
191 -D_WIN32_WINNT=0x0501
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
192 )
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
193 endif()
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
194 else()
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
195 add_definitions(
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
196 -DWINVER=0x0501
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
197 -D_WIN32_WINNT=0x0501
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
198 )
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
199 endif()
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
200
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
201 add_definitions(
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
202 -D_CRT_SECURE_NO_WARNINGS=1
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
203 )
69
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 56
diff changeset
204 link_libraries(rpcrt4 ws2_32 iphlpapi) # "iphlpapi" is for "SystemToolbox::GetMacAddresses()"
36
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
205
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
206 if (CMAKE_COMPILER_IS_GNUCXX)
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
207 # Some additional C/C++ compiler flags for MinGW
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
208 SET(MINGW_NO_WARNINGS "-Wno-unused-function -Wno-unused-variable")
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
209 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${MINGW_NO_WARNINGS} -Wno-pointer-to-int-cast -Wno-int-to-pointer-cast")
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
210 SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${MINGW_NO_WARNINGS}")
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
211
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
212 if (DYNAMIC_MINGW_STDLIB)
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
213 else()
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
214 # This is a patch for MinGW64
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
215 SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--allow-multiple-definition -static-libgcc -static-libstdc++")
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
216 SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--allow-multiple-definition -static-libgcc -static-libstdc++")
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
217 endif()
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
218
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
219 CHECK_LIBRARY_EXISTS(winpthread pthread_create "" HAVE_WIN_PTHREAD)
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
220 if (HAVE_WIN_PTHREAD)
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
221 if (DYNAMIC_MINGW_STDLIB)
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
222 else()
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
223 # This line is necessary to compile with recent versions of MinGW,
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
224 # otherwise "libwinpthread-1.dll" is not statically linked.
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
225 SET(CMAKE_CXX_STANDARD_LIBRARIES "${CMAKE_CXX_STANDARD_LIBRARIES} -Wl,-Bstatic -lstdc++ -lpthread -Wl,-Bdynamic")
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
226 endif()
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
227 add_definitions(-DHAVE_WIN_PTHREAD=1)
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
228 else()
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
229 add_definitions(-DHAVE_WIN_PTHREAD=0)
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
230 endif()
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
231 endif()
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
232
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
233 elseif (${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
234 add_definitions(
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
235 -D_XOPEN_SOURCE=1
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
236 )
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
237 link_libraries(iconv)
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
238
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
239 elseif (CMAKE_SYSTEM_NAME STREQUAL "Emscripten")
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
240 message("Building using Emscripten (for WebAssembly or asm.js targets)")
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
241 include(${CMAKE_CURRENT_LIST_DIR}/EmscriptenParameters.cmake)
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
242
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
243 elseif (CMAKE_SYSTEM_NAME STREQUAL "Android")
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
244
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
245 else()
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
246 message("Unknown target platform: ${CMAKE_SYSTEM_NAME}")
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
247 message(FATAL_ERROR "Support your platform here")
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
248 endif()
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
249
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
250
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
251 if (DEFINED ENABLE_PROFILING AND ENABLE_PROFILING)
113
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 100
diff changeset
252 if (CMAKE_COMPILER_IS_GNUCXX OR
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 100
diff changeset
253 CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
36
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
254 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pg")
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
255 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pg")
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
256 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pg")
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
257 set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -pg")
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
258 set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -pg")
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
259 else()
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
260 message(FATAL_ERROR "Don't know how to enable profiling on your configuration")
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
261 endif()
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
262 endif()
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
263
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
264
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
265 if (CMAKE_COMPILER_IS_GNUCXX)
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
266 # "When creating a static library using binutils (ar) and there
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
267 # exist a duplicate object name (e.g. a/Foo.cpp.o, b/Foo.cpp.o), the
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
268 # resulting static library can end up having only one of the
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
269 # duplicate objects. [...] This bug only happens if there are many
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
270 # objects." The trick consists in replacing the "r" argument
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
271 # ("replace") provided to "ar" (as used in CMake < 3.1) by the "q"
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
272 # argument ("quick append"). This is because of the fact that CMake
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
273 # will invoke "ar" several times with several batches of ".o"
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
274 # objects, and using "r" would overwrite symbols defined in
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
275 # preceding batches. https://cmake.org/Bug/view.php?id=14874
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
276 set(CMAKE_CXX_ARCHIVE_APPEND "<CMAKE_AR> <LINK_FLAGS> q <TARGET> <OBJECTS>")
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
277 endif()
132
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
278
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
279
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
280 # This function defines macro "__ORTHANC_FILE__" as a replacement to
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
281 # macro "__FILE__", as the latter leaks the full path of the source
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
282 # files in the binaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
283 # https://stackoverflow.com/questions/8487986/file-macro-shows-full-path
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
284 # https://twitter.com/wget42/status/1676877802375634944?s=20
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
285 function(DefineSourceBasenameForTarget targetname)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
286 # Microsoft Visual Studio is extremely slow if using
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
287 # "set_property()", we only enable this feature for gcc and clang
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
288 if (CMAKE_COMPILER_IS_GNUCXX OR
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
289 CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
290 get_target_property(source_files "${targetname}" SOURCES)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
291 foreach(sourcefile ${source_files})
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
292 get_filename_component(basename "${sourcefile}" NAME)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
293 set_property(
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
294 SOURCE "${sourcefile}" APPEND
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
295 PROPERTY COMPILE_DEFINITIONS "__ORTHANC_FILE__=\"${basename}\"")
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
296 endforeach()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
297 endif()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
298 endfunction()