Changeset 6476

Show
Ignore:
Timestamp:
04/11/07 10:35:58
Author:
robert
Message:

From Eric Wing:
"
Changes include:

A internal cache flag that can be used to detect if this is the first
time running the CMake configuration. This is needed to work around
stupid CMake UI shortcomings about the UI not reflecting anything you
SET unless you use FORCE. But if you use FORCE, you override anything
the user may try to set/override unless you have an exception check.
It turns out the exception check you need is often the first-run
check. This flag is potentially useful for other things too.

An optional switch that turns on more aggressive warnings based on
your compiler.

Some Apple specific stuff for detecting the OS version and enabling
Universal Binaries (and some additional compiler flags that are good
but gcc version dependent). The version check code is unfortunately
really fragile. I need to lobby CMake to return the OS X version
number for us. FYI, building Universal will fail with the current
CMake release due to a bug, but is now fixed in CVS.

"

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • OpenThreads/trunk/CMakeLists.txt

    r6473 r6476  
    124124   FILE(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/bin ${CMAKE_BINARY_DIR}/lib) 
    125125ENDIF("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_BINARY_DIR}") 
     126 
     127 
     128 
     129 
     130############################################################################### 
     131# This is for an advanced option to give aggressive warnings  
     132# under different compilers. If yours is not implemented, this option 
     133# will not be made available. 
     134IF(CMAKE_COMPILER_IS_GNUCXX) 
     135    # To be complete, we might also do GNUCC flags,  
     136    # but everything here is C++ code. 
     137    # # FYI, if we do implement GNUCC, then -Wmissing-prototypes in another  
     138    # interesting C-specific flag. 
     139    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") 
     140ELSE(CMAKE_COMPILER_IS_GNUCXX) 
     141    IF(MSVC) 
     142        # FIXME: What are good aggressive warning flags for Visual Studio? 
     143        # And do we need to further subcase this for different versions of VS? 
     144        # CMake variables: MSVC60, MSVC70, MSVC71, MSVC80, CMAKE_COMPILER_2005 
     145        SET(OPENTHREADS_AGGRESSIVE_WARNING_FLAGS "/Wall /W4") 
     146    ELSE(MSVC) 
     147        # CMake lacks an elseif, so other non-gcc, non-VS compilers need 
     148        # to be listed below. If unhandled, OPENTHREADS_AGGRESSIVE_WARNING_FLAGS should  
     149        # remain unset. 
     150    ENDIF(MSVC) 
     151ENDIF(CMAKE_COMPILER_IS_GNUCXX) 
     152 
     153# This part is for the CMake menu option to toggle the warnings on/off. 
     154# This will only be made available if we set values for OPENTHREADS_AGGRESSIVE_WARNING_FLAGS. 
     155IF(OPENTHREADS_AGGRESSIVE_WARNING_FLAGS) 
     156    OPTION(OPENTHREADS_USE_AGGRESSIVE_WARNINGS "Enable to activate aggressive warnings" OFF) 
     157    MARK_AS_ADVANCED(OPENTHREADS_USE_AGGRESSIVE_WARNINGS) 
     158 
     159    IF(OPENTHREADS_USE_AGGRESSIVE_WARNINGS) 
     160        IF(NOT "${OLD_CMAKE_CXX_FLAGS_WAS_SET}") 
     161            SET(OLD_CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" CACHE INTERNAL "Old CXX flags") 
     162            SET(OLD_CMAKE_CXX_FLAGS_WAS_SET 1 CACHE INTERNAL "Old CXX flags was set") 
     163            SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OPENTHREADS_AGGRESSIVE_WARNING_FLAGS}" CACHE STRING "Flags used by the compiler during all build types." FORCE) 
     164        ENDIF(NOT "${OLD_CMAKE_CXX_FLAGS_WAS_SET}") 
     165    ELSE(OPENTHREADS_USE_AGGRESSIVE_WARNINGS) 
     166        # FIXME: This will lose any changes made after OLD_CMAKE_CXX_FLAGS was  
     167        # set. The better way would be to parse the string and remove each 
     168        # option explicitly. 
     169        IF("${OLD_CMAKE_CXX_FLAGS_WAS_SET}") 
     170            SET(CMAKE_CXX_FLAGS "${OLD_CMAKE_CXX_FLAGS}" CACHE STRING "Flags used by the compiler during all build types." FORCE) 
     171            SET(OLD_CMAKE_CXX_FLAGS_WAS_SET 0 CACHE INTERNAL "Old CXX flags was set") 
     172        ENDIF("${OLD_CMAKE_CXX_FLAGS_WAS_SET}") 
     173    ENDIF(OPENTHREADS_USE_AGGRESSIVE_WARNINGS) 
     174ENDIF(OPENTHREADS_AGGRESSIVE_WARNING_FLAGS) 
     175 
     176 
     177############################################################################### 
     178# Set defaults for Universal Binaries. We want 32-bit Intel/PPC on 10.4  
     179# and 32/64-bit Intel/PPC on >= 10.5. Anything <= 10.3 doesn't support. 
     180IF(APPLE) 
     181    # These are just defaults/recommendations, but how we want to build 
     182    # out of the box. But the user needs to be able to change these options. 
     183    # So we must only set the values the first time CMake is run, or we  
     184    # will overwrite any changes the user sets. 
     185    # FORCE is used because the options are not reflected in the UI otherwise. 
     186    IF(NOT "${OPENTHREADS_CONFIG_HAS_BEEN_RUN_BEFORE}") 
     187        # This is really fragile, but CMake doesn't provide the OS system  
     188        # version information we need. (Darwin versions can be changed  
     189        # independently of OS X versions.) 
     190        # It does look like CMake handles the CMAKE_OSX_SYSROOT automatically. 
     191        IF(EXISTS /Developer/SDKs/10.5.sdk) 
     192            SET(CMAKE_OSX_ARCHITECTURES "ppc;i386;ppc64;x86_64" CACHE STRING "Build architectures for OSX" FORCE) 
     193            SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility-inlines-hidden" CACHE STRING "Flags used by the compiler during all build types." FORCE) 
     194        ELSE(EXISTS /Developer/SDKs/10.5.sdk) 
     195            IF(EXISTS /Developer/SDKs/MacOSX10.4u.sdk) 
     196                SET(CMAKE_OSX_ARCHITECTURES "ppc;i386;ppc64;x86_64" CACHE STRING "Build architectures for OSX" FORCE) 
     197                #SET(CMAKE_OSX_ARCHITECTURES "ppc;i386" CACHE STRING "Build architectures for OSX" FORCE) 
     198                SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility-inlines-hidden" CACHE STRING "Flags used by the compiler during all build types." FORCE) 
     199            ELSE(EXISTS /Developer/SDKs/MacOSX10.4u.sdk) 
     200                # No Universal Binary support 
     201            ENDIF(EXISTS /Developer/SDKs/MacOSX10.4u.sdk) 
     202        ENDIF(EXISTS /Developer/SDKs/10.5.sdk) 
     203    ENDIF(NOT "${OPENTHREADS_CONFIG_HAS_BEEN_RUN_BEFORE}") 
     204ENDIF(APPLE) 
     205 
    126206 
    127207 
     
    154234ENDIF(BUILD_DOCUMENTATION) 
    155235 
     236 
     237# This needs to be run very last so other parts of the scripts can take 
     238# advantage of this. 
     239IF(NOT "${OPENTHREADS_CONFIG_HAS_BEEN_RUN_BEFORE}") 
     240    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") 
     241ENDIF(NOT "${OPENTHREADS_CONFIG_HAS_BEEN_RUN_BEFORE}") 
     242 
     243