# Creates and names a library, sets it as either STATIC # or SHARED, and provides the relative paths to its source code. # You can define multiple libraries, and CMake builds them for you. # Gradle automatically packages shared libraries with your APK.
add_library( # Sets the name of the library. native-lib # Sets the library as a shared library. SHARED # Provides a relative path to your source file(s). # src/main/cpp/native-lib.cpp ${SRC_LIST} )
# Searches for a specified prebuilt library and stores the path as a # variable. Because CMake includes system libraries in the search path by # default, you only need to specify the name of the public NDK library # you want to add. CMake verifies that the library exists before # completing its build.
find_library( # Sets the name of the path variable. log-lib
# Specifies the name of the NDK library that # you want CMake to locate. log)
# Specifies libraries CMake should link to your target library. You # can link multiple libraries, such as libraries you define in this # build script, prebuilt third-party libraries, or system libraries.
#------------------------------------------------------------------- # This file is part of the CMake build system for OGRE # (Object-oriented Graphics Rendering Engine) # For the latest info, see http://www.ogre3d.org/ # # The contents of this file are placed in the public domain. Feel # free to make use of it in any way you like. #-------------------------------------------------------------------
###################################################################### # OGRE BUILD SYSTEM # Welcome to the CMake build system for OGRE. # This is the main file where we prepare the general build environment # and provide build configuration options. ###################################################################### # 设置cmake的最低版本 cmake_minimum_required(VERSION 3.10)
# Use relative paths # This is mostly to reduce path size for command-line limits on windows if(WIN32) # This seems to break Xcode projects so definitely don't enable on Apple builds set(CMAKE_USE_RELATIVE_PATHS true) set(CMAKE_SUPPRESS_REGENERATION true) endif()
if (APPLE AND NOT ANDROID) SET(CMAKE_SIZEOF_VOID_P 4) set(CMAKE_XCODE_ATTRIBUTE_GCC_VERSION "com.apple.compilers.llvm.clang.1_0") set(CMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LANGUAGE_STANDARD "c++11") set(CMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LIBRARY "libc++") # otherwise apple defines a macro named check that conflicts with boost add_definitions(-D__ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORES=0) endif ()
project(OGRE)
# Include necessary submodules set(CMAKE_MODULE_PATH "${OGRE_SOURCE_DIR}/CMake" "${OGRE_SOURCE_DIR}/CMake/Utils" "${OGRE_SOURCE_DIR}/CMake/Packages" )
##################################################################### # Set up the basic build environment #####################################################################
if (NOT CMAKE_BUILD_TYPE) # CMake defaults to leaving CMAKE_BUILD_TYPE empty. This screws up # differentiation between debug and release builds. set(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING "Choose the type of build, options are: None (CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel." FORCE) endif ()
# determine Ogre version numbers include(OgreGetVersion) ogre_get_version(${OGRE_SOURCE_DIR}/OgreMain/include/OgrePrerequisites.h) message(STATUS "Configuring OGRE ${OGRE_VERSION}") # Configure version file for use by scripts configure_file("${OGRE_TEMPLATES_DIR}/version.txt.in" "${OGRE_BINARY_DIR}/version.txt" @ONLY)
# determine if we are compiling for a 32bit or 64bit system include(CheckTypeSize) CHECK_TYPE_SIZE("void*" OGRE_PTR_SIZE BUILTIN_TYPES_ONLY) if (OGRE_PTR_SIZE EQUAL 8) set(OGRE_PLATFORM_X64 TRUE) else () set(OGRE_PLATFORM_X64 FALSE) endif ()
if (WIN32) # Create debug libraries with _d postfix set(CMAKE_DEBUG_POSTFIX "_d") endif ()
# Set compiler specific build flags if (NOT ANDROID AND UNIX OR MINGW) include(CheckCXXCompilerFlag) check_cxx_compiler_flag(-msse OGRE_GCC_HAS_SSE) if (OGRE_GCC_HAS_SSE) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse") endif () endif()
if(UNIX) # This is a set of sensible warnings that provide meaningful output set(OGRE_WARNING_FLAGS "-Wall -Winit-self -Wcast-qual -Wwrite-strings -Wextra -Wundef -Wmissing-declarations -Wno-unused-parameter -Wshadow -Wno-missing-field-initializers -Wno-long-long") if (EMSCRIPTEN) set(OGRE_WARNING_FLAGS "${OGRE_WARNING_FLAGS} -Wno-warn-absolute-paths") endif () set(CMAKE_CXX_FLAGS "${OGRE_WARNING_FLAGS} ${CMAKE_CXX_FLAGS}") endif () if (MSVC) add_definitions(-D_MT -D_USRDLL) # MSVC does not like Ogre::Singleton (header pragma is enough for MSVC2015+ though) add_definitions(/wd4661) if (CMAKE_BUILD_TOOL STREQUAL "nmake") # set variable to state that we are using nmake makefiles set(NMAKE TRUE) endif () set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /fp:fast") # Enable intrinsics on MSVC in debug mode set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /Oi") if (CMAKE_CL_64) # Visual Studio bails out on debug builds in 64bit mode unless # this flag is set... set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /bigobj") set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} /bigobj") endif ()
if (OGRE_PROJECT_FOLDERS) # Turn on the ability to create folders to organize projects (.vcproj) # It creates "CMakePredefinedTargets" folder by default and adds CMake # defined projects like INSTALL.vcproj and ZERO_CHECK.vcproj set_property(GLOBAL PROPERTY USE_FOLDERS ON) endif()
if (MSVC_VERSION GREATER 1500 OR MSVC_VERSION EQUAL 1500) option(OGRE_BUILD_MSVC_MP "Enable build with multiple processes in Visual Studio" TRUE) else() set(OGRE_BUILD_MSVC_MP FALSE CACHE BOOL "Compiler option /MP requires at least Visual Studio 2008 (VS9) or newer" FORCE) endif() if(OGRE_BUILD_MSVC_MP) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP") endif () if(MSVC_VERSION GREATER 1400 OR MSVC_VERSION EQUAL 1400) option(OGRE_BUILD_MSVC_ZM "Add /Zm256 compiler option to Visual Studio to fix PCH errors" TRUE) else() set(OGRE_BUILD_MSVC_ZM FALSE CACHE BOOL "Compiler option /Zm256 requires at least Visual Studio 2005 (VS8) or newer" FORCE) endif() if(OGRE_BUILD_MSVC_ZM) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Zm256") endif () endif () if (MINGW) add_definitions(-D_WIN32_WINNT=0x0501) if( CMAKE_SIZEOF_VOID_P EQUAL 4 ) # set architecture to i686, since otherwise some versions of MinGW can't link # the atomic primitives set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=i686") endif () # disable this optimisation because it breaks release builds (reason unknown) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-tree-slp-vectorize") # Ignore some really annoying warnings which also happen in dependencies set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-error=cast-qual -Wno-unused-local-typedefs") endif ()
if((CMAKE_CXX_COMPILER_ID MATCHES "Clang|GNU") AND NOT OGRE_STATIC) set(OGRE_VISIBILITY_FLAGS "-DOGRE_GCC_VISIBILITY") # for legacy headers endif()
# determine system endianess if (MSVC OR ANDROID OR EMSCRIPTEN OR APPLE_IOS) # This doesn't work on VS 2010 # MSVC only builds for intel anyway # all IOS devices are little endian set(OGRE_TEST_BIG_ENDIAN FALSE) else() include(TestBigEndian) test_big_endian(OGRE_TEST_BIG_ENDIAN) endif()
# Add OgreMain include path if (APPLE_IOS) # Set static early for proper dependency detection set(OGRE_STATIC TRUE) endif()
# Specify build paths set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${OGRE_BINARY_DIR}/lib") set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${OGRE_BINARY_DIR}/lib") set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${OGRE_BINARY_DIR}/bin") if (WIN32 OR APPLE) if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) # We don't want to install in default system location, install is really for the SDK, so call it that set(CMAKE_INSTALL_PREFIX "${OGRE_BINARY_DIR}/sdk" CACHE PATH "OGRE install prefix" FORCE ) endif (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) endif(WIN32 OR APPLE)
# Enable the PVRTC codec if OpenGL ES is being built if(OGRE_BUILD_RENDERSYSTEM_GLES2) set(OGRE_CONFIG_ENABLE_PVRTC TRUE CACHE BOOL "Forcing PVRTC codec for OpenGL ES" FORCE) set(OGRE_CONFIG_ENABLE_ETC TRUE CACHE BOOL "Forcing ETC codec for OpenGL ES" FORCE) endif()
# Enable the ETC codec if OpenGL 3+ is being built if(OGRE_BUILD_RENDERSYSTEM_GL3PLUS) set(OGRE_CONFIG_ENABLE_ETC TRUE CACHE BOOL "Forcing ETC codec for OpenGL 3+" FORCE) endif()
# Find dependencies include(Dependencies)
###################################################################### # Provide user options to customise the build process ######################################################################
# Customise what to build option(OGRE_STATIC "Static build" FALSE) option(OGRE_ENABLE_PRECOMPILED_HEADERS "Use precompiled headers to speed up build" TRUE) set(OGRE_RESOURCEMANAGER_STRICT "2" CACHE STRING "Make ResourceManager strict for faster operation. Possible values: 0 - OFF search in all groups twice - for case sensitive and insensitive lookup [DEPRECATED] 1 - PEDANTIC require an explicit resource group. Case sensitive lookup. 2 - STRICT search in default group if not specified otherwise. Case sensitive lookup. ") set_property(CACHE OGRE_RESOURCEMANAGER_STRICT PROPERTY STRINGS 0 1 2)
# For Visual studio enable project folders by default. # Hide option from other compilers. if (MSVC) option(OGRE_PROJECT_FOLDERS "Organize project into project folders." TRUE) endif ()
################################################################### # configure global build settings based on selected build options ################################################################### include(ConfigureBuild)
################################################################### # disable way too common compiler warnings on project level ################################################################### if(MSVC) add_definitions( /wd4251 /wd4275 ) endif()
################################################################## # Now setup targets ##################################################################
# Setup tests (before samples so that PlayPen is included in browser) if (OGRE_BUILD_TESTS) # enable CTest ENABLE_TESTING() INCLUDE(CTest) add_subdirectory(Tests) endif ()
# Setup samples add_subdirectory(Samples)
# Setup command-line tools if (OGRE_BUILD_TOOLS) add_subdirectory(Tools) endif ()
# Setup XSIExporter if (OGRE_BUILD_XSIEXPORTER) add_subdirectory(Tools/XSIExport) endif ()
# Install documentation add_subdirectory(Docs)
# Install media files if (OGRE_INSTALL_SAMPLES OR OGRE_INSTALL_SAMPLES_SOURCE) add_subdirectory(Samples/Media) endif ()
# Install CMake modules if (OGRE_INSTALL_CMAKE) add_subdirectory(CMake) endif ()
# Provide CPack packaging target include(Packaging)