diff options
author | Chad Versace <chad.versace@linux.intel.com> | 2013-08-19 23:38:37 -0700 |
---|---|---|
committer | Chad Versace <chad.versace@linux.intel.com> | 2013-08-19 23:46:53 -0700 |
commit | 2b9748a7f552a56f4042b017d3bfcfe9e61c7de4 (patch) | |
tree | 8049902c45b72ef6c181e9085dcb8be6d4b4179d | |
parent | f8b573fd7e7d9225e3d20a0bca401bab64c0f865 (diff) |
cmake: Refactor detection of operating system
Add new module WaffleDefineOS that defines booleans `waffle_on_linux`
and `waffle_on_mac`. Replace each check on CMAKE_SYSTEM_NAME with
a check on one of these new bools.
Signed-off-by: Chad Versace <chad.versace@linux.intel.com>
-rw-r--r-- | CMakeLists.txt | 1 | ||||
-rw-r--r-- | Options.cmake | 2 | ||||
-rw-r--r-- | cmake/Modules/WaffleDefineCompilerFlags.cmake | 4 | ||||
-rw-r--r-- | cmake/Modules/WaffleDefineOS.cmake | 32 | ||||
-rw-r--r-- | cmake/Modules/WaffleFindDependencies.cmake | 2 | ||||
-rw-r--r-- | cmake/Modules/WaffleValidateOptions.cmake | 4 | ||||
-rw-r--r-- | examples/CMakeLists.txt | 4 | ||||
-rw-r--r-- | src/waffle/CMakeLists.txt | 4 | ||||
-rw-r--r-- | tests/functional/CMakeLists.txt | 2 |
9 files changed, 44 insertions, 11 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 7a809c5..a6695fe 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -29,6 +29,7 @@ cmake_minimum_required(VERSION 2.8) list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/Modules") +include(WaffleDefineOS) include(Options.cmake) include(WaffleDefineInternalOptions) include(WaffleValidateOptions) diff --git a/Options.cmake b/Options.cmake index cc50dc5..923505b 100644 --- a/Options.cmake +++ b/Options.cmake @@ -1,4 +1,4 @@ -if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux") +if(waffle_on_linux) # On Linux, you must enable at least one of the below options. option(waffle_has_glx "Build support for GLX" OFF) option(waffle_has_wayland "Build support for Wayland" OFF) diff --git a/cmake/Modules/WaffleDefineCompilerFlags.cmake b/cmake/Modules/WaffleDefineCompilerFlags.cmake index b2628df..0f4cdec 100644 --- a/cmake/Modules/WaffleDefineCompilerFlags.cmake +++ b/cmake/Modules/WaffleDefineCompilerFlags.cmake @@ -29,7 +29,7 @@ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --std=c99") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror=implicit-function-declaration") -if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux") +if(waffle_on_linux) # On MacOS, the SSE2 headers trigger this error. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror=missing-prototypes") endif() @@ -50,7 +50,7 @@ if(waffle_has_tls_model_initial_exec) add_definitions(-DWAFFLE_HAS_TLS_MODEL_INITIAL_EXEC) endif() -if("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin") +if(waffle_on_mac) add_definitions(-DWAFFLE_HAS_CGL) endif() diff --git a/cmake/Modules/WaffleDefineOS.cmake b/cmake/Modules/WaffleDefineOS.cmake new file mode 100644 index 0000000..e437947 --- /dev/null +++ b/cmake/Modules/WaffleDefineOS.cmake @@ -0,0 +1,32 @@ +# Copyright 2013 Intel Corporation +# +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# - Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# - Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux") + set(waffle_on_linux true) +elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin") + set(waffle_on_mac true) +else() + message(FATAL_ERROR "Unrecognized CMAKE_SYSTEM_NAME=\"${CMAKE_SYSTEM_NAME|\"") +endif() diff --git a/cmake/Modules/WaffleFindDependencies.cmake b/cmake/Modules/WaffleFindDependencies.cmake index 498d775..8fb9d2a 100644 --- a/cmake/Modules/WaffleFindDependencies.cmake +++ b/cmake/Modules/WaffleFindDependencies.cmake @@ -25,7 +25,7 @@ find_package(PkgConfig) -if("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin") +if(waffle_on_mac) find_package(OpenGL REQUIRED) find_library(COCOA_FRAMEWORK Cocoa REQUIRED) find_library(CORE_FOUNDATION_FRAMEWORK CoreFoundation REQUIRED) diff --git a/cmake/Modules/WaffleValidateOptions.cmake b/cmake/Modules/WaffleValidateOptions.cmake index 8bc7d16..03eb4ba 100644 --- a/cmake/Modules/WaffleValidateOptions.cmake +++ b/cmake/Modules/WaffleValidateOptions.cmake @@ -44,7 +44,7 @@ if(DEFINED waffle_install_docdir) "details.") endif() -if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux") +if(waffle_on_linux) if(NOT waffle_has_glx AND NOT waffle_has_wayland AND NOT waffle_has_x11_egl AND NOT waffle_has_gbm) message(FATAL_ERROR @@ -52,7 +52,7 @@ if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux") "waffle_has_glx, waffle_has_wayland, " "waffle_has_x11_egl, waffle_has_gbm.") endif() -elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin") +elseif(waffle_on_mac) if(waffle_has_gbm) message(FATAL_ERROR "Option is not supported on Darwin: waffle_has_gbm.") endif() diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index eb09669..48147f9 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -7,7 +7,7 @@ install(FILES Makefile.example # Target: simple-x11-egl (executable) # ---------------------------------------------------------------------------- -if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux") +if(waffle_on_linux) add_executable(simple-x11-egl simple-x11-egl.c) target_link_libraries(simple-x11-egl ${waffle_libname}) endif() @@ -19,7 +19,7 @@ endif() add_executable(gl_basic gl_basic.c) target_link_libraries(gl_basic ${waffle_libname}) -if("${CMAKE_SYSTEM_NAME}" STREQUAL Darwin) +if(waffle_on_mac) set_target_properties(gl_basic PROPERTIES COMPILE_FLAGS "-ObjC" diff --git a/src/waffle/CMakeLists.txt b/src/waffle/CMakeLists.txt index cdb8981..a743096 100644 --- a/src/waffle/CMakeLists.txt +++ b/src/waffle/CMakeLists.txt @@ -59,7 +59,7 @@ set(waffle_sources core/wcore_util.c ) -if("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin") +if(waffle_on_mac) list(APPEND waffle_sources cgl/cgl_config.m cgl/cgl_context.m @@ -98,7 +98,7 @@ if(waffle_has_glx) ) endif() -if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux") +if(waffle_on_linux) list(APPEND waffle_sources linux/linux_dl.c linux/linux_platform.c diff --git a/tests/functional/CMakeLists.txt b/tests/functional/CMakeLists.txt index dbf481c..6ad923d 100644 --- a/tests/functional/CMakeLists.txt +++ b/tests/functional/CMakeLists.txt @@ -7,7 +7,7 @@ set(gl_basic_test_sources gl_basic_test.c ) -if("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin") +if(waffle_on_mac) list(APPEND gl_basic_test_sources gl_basic_cocoa.m ) |