root/OpenThreads/trunk/CMakeLists.txt

Revision 6707 (checked in by robert, 2 years ago)

Added VERSION and SOVERSION support

Line 
1 IF(WIN32)
2     CMAKE_MINIMUM_REQUIRED(VERSION 2.4.6 FATAL_ERROR)
3 ELSE(WIN32)
4     IF(APPLE)
5         CMAKE_MINIMUM_REQUIRED(VERSION 2.4.6 FATAL_ERROR)
6     ELSE(APPLE)
7         CMAKE_MINIMUM_REQUIRED(VERSION 2.4.0 FATAL_ERROR)
8     ENDIF(APPLE)
9 ENDIF(WIN32)
10
11
12 PROJECT(OpenThreads)
13
14 # We have some custom .cmake scripts not in the official distribution.
15 # Maybe this can be used override existing behavior if needed?
16 SET(CMAKE_MODULE_PATH "${OpenThreads_SOURCE_DIR}/CMakeModules;${CMAKE_MODULE_PATH}")
17
18 ################################################################################
19 # Installation stuff
20
21 # We want to build SONAMES shared librariess
22 SET(OPENTHREADS_SONAMES TRUE)
23
24 SET(CMAKE_DEBUG_POSTFIX  "d")
25 #SET(INSTALL_BINDIR OpenThreads/bin)
26 #SET(INSTALL_INCDIR OpenThreads/include)
27 #SET(INSTALL_LIBDIR OpenThreads/lib)
28 #SET(INSTALL_DOCDIR OpenThreads/docs)
29
30
31 SET(CMAKE_DEBUG_POSTFIX  "d")
32
33 SET(LIB_POSTFIX "")
34 IF(UNIX AND NOT WIN32 AND NOT APPLE)
35   IF(CMAKE_SIZEOF_VOID_P MATCHES "8")
36       SET(LIB_POSTFIX "64")
37   ENDIF(CMAKE_SIZEOF_VOID_P MATCHES "8")
38 ENDIF(UNIX AND NOT WIN32 AND NOT APPLE)
39
40 ################################################################################
41
42
43 # Add a source group for the include headers so they are seen in IDEs.
44 # Hmmm, this isn't working for me in Xcode.
45 # SOURCE_GROUP(
46 #     "Header Files"
47 #     FILES ${OpenThreads_PUBLIC_HEADERS}
48 # )
49
50 # Make the headers visible to everything
51 INCLUDE_DIRECTORIES(
52     ${OpenThreads_SOURCE_DIR}/include
53 )
54
55 # This is mainly for Windows declspec, but other platforms know
56 # what to do with it.
57 ADD_DEFINITIONS(-DOPENTHREADS_EXPORTS)
58
59 # User Options
60 OPTION(DYNAMIC_OPENTHREADS "Set to ON to build OpenThreads for dynamic linking.  Use OFF for static." ON)
61 IF   (DYNAMIC_OPENTHREADS)
62     SET(OPENTHREADS_USER_DEFINED_DYNAMIC_OR_STATIC "SHARED")
63 ELSE (DYNAMIC_OPENTHREADS)
64     SET(OPENTHREADS_USER_DEFINED_DYNAMIC_OR_STATIC "STATIC")
65 ENDIF(DYNAMIC_OPENTHREADS)
66
67 # Use our modified version of FindThreads.cmake which has Sproc hacks.
68 FIND_PACKAGE(Threads)
69
70 SUBDIRS(src/OpenThreads examples)
71
72 # FIXME: Make optional install test programs
73 # FIXME: /bin directory not correct for Windows
74 # INSTALL_TARGETS(/bin OpenThreads)
75  
76 #SET(OUTPUT_BINDIR ${PROJECT_BINARY_DIR}/bin/${CMAKE_SYSTEM_NAME})
77 SET(OUTPUT_BINDIR ${PROJECT_BINARY_DIR}/bin)
78 MAKE_DIRECTORY(${OUTPUT_BINDIR})
79 SET(EXECUTABLE_OUTPUT_PATH ${OUTPUT_BINDIR})
80
81 #SET(OUTPUT_LIBDIR ${PROJECT_BINARY_DIR}/lib/${CMAKE_SYSTEM_NAME})
82 SET(OUTPUT_LIBDIR ${PROJECT_BINARY_DIR}/lib)
83 MAKE_DIRECTORY(${OUTPUT_LIBDIR})
84 SET(LIBRARY_OUTPUT_PATH ${OUTPUT_LIBDIR})
85
86 ################################################################################
87 # Create bin and lib directories if required
88
89 IF("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_BINARY_DIR}")
90    FILE(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/bin ${CMAKE_BINARY_DIR}/lib)
91 ENDIF("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_BINARY_DIR}")
92
93
94
95
96 ###############################################################################
97 # This is for an advanced option to give aggressive warnings
98 # under different compilers. If yours is not implemented, this option
99 # will not be made available.
100 IF(CMAKE_COMPILER_IS_GNUCXX)
101     # To be complete, we might also do GNUCC flags,
102     # but everything here is C++ code.
103     # FYI, if we do implement GNUCC, then -Wmissing-prototypes in another
104     # interesting C-specific flag.
105     # Also, there is a bug in gcc 4.0. Under C++, -pedantic will create
106     # errors instead of warnings for certain issues, including superfluous
107     # semicolons and commas, and the use of long long. -fpermissive seems
108     # to be the workaround.
109     SET(OPENTHREADS_AGGRESSIVE_WARNING_FLAGS "-Wall -Wparentheses -Wformat=2 -Wno-long-long -Wno-import -pedantic -Wnewline-eof -Wreturn-type -Wmissing-braces -Wunknown-pragmas -Wunused -Wshadow -Woverloaded-virtual -fpermissive")
110 ELSE(CMAKE_COMPILER_IS_GNUCXX)
111     IF(MSVC)
112         # FIXME: What are good aggressive warning flags for Visual Studio?
113         # And do we need to further subcase this for different versions of VS?
114         # CMake variables: MSVC60, MSVC70, MSVC71, MSVC80, CMAKE_COMPILER_2005
115         SET(OPENTHREADS_AGGRESSIVE_WARNING_FLAGS "/Wall /W4")
116     ELSE(MSVC)
117         # CMake lacks an elseif, so other non-gcc, non-VS compilers need
118         # to be listed below. If unhandled, OPENTHREADS_AGGRESSIVE_WARNING_FLAGS should
119         # remain unset.
120     ENDIF(MSVC)
121 ENDIF(CMAKE_COMPILER_IS_GNUCXX)
122
123 # This part is for the CMake menu option to toggle the warnings on/off.
124 # This will only be made available if we set values for OPENTHREADS_AGGRESSIVE_WARNING_FLAGS.
125 IF(OPENTHREADS_AGGRESSIVE_WARNING_FLAGS)
126     OPTION(OPENTHREADS_USE_AGGRESSIVE_WARNINGS "Enable to activate aggressive warnings" OFF)
127     MARK_AS_ADVANCED(OPENTHREADS_USE_AGGRESSIVE_WARNINGS)
128
129     IF(OPENTHREADS_USE_AGGRESSIVE_WARNINGS)
130         IF(NOT "${OLD_CMAKE_CXX_FLAGS_WAS_SET}")
131             SET(OLD_CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" CACHE INTERNAL "Old CXX flags")
132             SET(OLD_CMAKE_CXX_FLAGS_WAS_SET 1 CACHE INTERNAL "Old CXX flags was set")
133             SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OPENTHREADS_AGGRESSIVE_WARNING_FLAGS}" CACHE STRING "Flags used by the compiler during all build types." FORCE)
134         ENDIF(NOT "${OLD_CMAKE_CXX_FLAGS_WAS_SET}")
135     ELSE(OPENTHREADS_USE_AGGRESSIVE_WARNINGS)
136         # FIXME: This will lose any changes made after OLD_CMAKE_CXX_FLAGS was
137         # set. The better way would be to parse the string and remove each
138         # option explicitly.
139         IF("${OLD_CMAKE_CXX_FLAGS_WAS_SET}")
140             SET(CMAKE_CXX_FLAGS "${OLD_CMAKE_CXX_FLAGS}" CACHE STRING "Flags used by the compiler during all build types." FORCE)
141             SET(OLD_CMAKE_CXX_FLAGS_WAS_SET 0 CACHE INTERNAL "Old CXX flags was set")
142         ENDIF("${OLD_CMAKE_CXX_FLAGS_WAS_SET}")
143     ENDIF(OPENTHREADS_USE_AGGRESSIVE_WARNINGS)
144 ENDIF(OPENTHREADS_AGGRESSIVE_WARNING_FLAGS)
145
146
147 ###############################################################################
148 # Set defaults for Universal Binaries. We want 32-bit Intel/PPC on 10.4
149 # and 32/64-bit Intel/PPC on >= 10.5. Anything <= 10.3 doesn't support.
150 IF(APPLE)
151     # These are just defaults/recommendations, but how we want to build
152     # out of the box. But the user needs to be able to change these options.
153     # So we must only set the values the first time CMake is run, or we
154     # will overwrite any changes the user sets.
155     # FORCE is used because the options are not reflected in the UI otherwise.
156     IF(NOT OPENTHREADS_CONFIG_HAS_BEEN_RUN_BEFORE)
157         # This is really fragile, but CMake doesn't provide the OS system
158         # version information we need. (Darwin versions can be changed
159         # independently of OS X versions.)
160         # It does look like CMake handles the CMAKE_OSX_SYSROOT automatically.
161         IF(EXISTS /Developer/SDKs/10.5.sdk)
162             SET(CMAKE_OSX_ARCHITECTURES "ppc;i386;ppc64;x86_64" CACHE STRING "Build architectures for OSX" FORCE)
163             SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility-inlines-hidden" CACHE STRING "Flags used by the compiler during all build types." FORCE)
164         ELSE(EXISTS /Developer/SDKs/10.5.sdk)
165             IF(EXISTS /Developer/SDKs/MacOSX10.4u.sdk)
166                 # Unix layer on Tiger is 64-bit clean/ready so I think
167                 # it is okay to build 64-bit here. This presumes we
168                 # keep non-64-bit ready APIs (e.g. Carbon) out
169                 # of OpenThreads.
170                 SET(CMAKE_OSX_ARCHITECTURES "ppc;i386;ppc64;x86_64" CACHE STRING "Build architectures for OSX" FORCE)
171                 #SET(CMAKE_OSX_ARCHITECTURES "ppc;i386" CACHE STRING "Build architectures for OSX" FORCE)
172                 SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility-inlines-hidden" CACHE STRING "Flags used by the compiler during all build types." FORCE)
173             ELSE(EXISTS /Developer/SDKs/MacOSX10.4u.sdk)
174                 # No Universal Binary support
175             ENDIF(EXISTS /Developer/SDKs/MacOSX10.4u.sdk)
176         ENDIF(EXISTS /Developer/SDKs/10.5.sdk)
177     ENDIF(NOT OPENTHREADS_CONFIG_HAS_BEEN_RUN_BEFORE)
178 ENDIF(APPLE)
179
180
181
182 ################################################################################
183 # For Doxygen
184 INCLUDE(${CMAKE_ROOT}/Modules/Documentation.cmake OPTIONAL)
185
186 # To build the documention, you will have to enable it
187 # and then do the equivalent of "make DoxygenDoc".
188 IF(BUILD_DOCUMENTATION)
189     IF(DOT)
190         SET(HAVE_DOT YES)
191     ELSE(DOT)
192         SET(HAVE_DOT NO)
193     ENDIF(DOT)
194     # This processes our Doxyfile.in and substitutes paths to generate
195     # a final Doxyfile
196     CONFIGURE_FILE(${PROJECT_SOURCE_DIR}/docs/doxyfile.cmake
197         ${PROJECT_BINARY_DIR}/docs/doxyfile
198         )
199     # This creates a new target to build documentation.
200     # It runs ${DOXYGEN} which is the full path and executable to
201     # Doxygen on your system, set by the FindDoxygen.cmake module
202     # (called by FindDocumentation.cmake).
203     # It runs the final generated Doxyfile against it.
204     # The DOT_PATH is substituted into the Doxyfile.
205     ADD_CUSTOM_TARGET(DoxygenDoc ${DOXYGEN}
206         ${PROJECT_BINARY_DIR}/docs/doxyfile
207     )
208 ENDIF(BUILD_DOCUMENTATION)
209
210
211 # This needs to be run very last so other parts of the scripts can take
212 # advantage of this.
213 IF(NOT OPENTHREADS_CONFIG_HAS_BEEN_RUN_BEFORE)
214     SET(OPENTHREADS_CONFIG_HAS_BEEN_RUN_BEFORE 1 CACHE INTERNAL "Flag to track whether this is the first time running CMake or if CMake has been configured before")
215 ENDIF(NOT OPENTHREADS_CONFIG_HAS_BEEN_RUN_BEFORE)
216
217
Note: See TracBrowser for help on using the browser.