[2.1] Ogre compilation on the fly (as git submodule and cmake subdirectory)

Discussion area about developing with Ogre-Next (2.1, 2.2 and beyond)


Post Reply
Hideman
Gnoblar
Posts: 1
Joined: Fri Nov 02, 2018 9:29 pm

[2.1] Ogre compilation on the fly (as git submodule and cmake subdirectory)

Post by Hideman »

Hello Ogre's community,

I want to build a voxels game with your graphic engine I already started project with some features and now it's time to implement the rendering system so after many search I think Ogre it's a great choice and specially Ogre 2.1 fit to needs.

I already read 2.1 wiki and it's compile perfectly and samples run perfectly too (without ogredeps on Linux). I also found your EmptyProject to start dealing with Ogre and my problem it's that Ogre need to be prebuild and installed and copied (or linked) in EmptyProject/Dependencies/Ogre but isn't what I want.

I using git submodule to link all primaries libraries to my project. So all libs are in Libs dir at the top of my project and sources in Sources directory.
And finally I use cmake sub_directory to configure my projet (I prefer it instead brutally add_recursively, and needed to separate my project submodules into different targets).

My project structure:

Code: Select all

MyProject
├── CMakeLists.txt
├── Libs
│   ├── CMakeLists.txt
│   ├── FastNoiseSIMD # git submodule
│   ├── FastNoiseSIMD.cmake.h
│   ├── ogredeps
│   └── Ogre # git submodule branch v2.1
├── README.md
├── Resources
└── Sources

Code: Select all

#/CMakeLists.txt
cmake_minimum_required (VERSION 3.10)
include(GenerateExportHeader)
project(TheCraftNation CXX C)

set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_EXTENSIONS ON)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED ON)

set(CMAKE_VERBOSE_MAKEFILE FALSE)

set(CMAKE_CXX_VISIBILITY_PRESET hidden)
set(CMAKE_VISIBILITY_INLINES_HIDDEN 1)

set(CMAKE_CXX_FLAGS -O3)

IF (WIN32)
    set(CMAKE_EXE_LINKER_FLAGS -static)
ENDIF()

add_subdirectory(Sources)
add_subdirectory(Libs)
# [...] setup targets with sources, include directories and libraries.

Code: Select all

#/Libs/CMakeLists.txt
message("
############################################################
##  Fast Noise SIMD setup
############################################################
")

set(directory FastNoiseSIMD)
set(library_name FastNoiseSIMD)
set(file_prefix FastNoiseSIMD)

set_property(DIRECTORY ${PROJECT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT ${library_name})

#if (CMAKE_SYSTEM_PROCESSOR MATCHES "arm" OR CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64")
option(FN_COMPILE_NEON
        "Only on arm or aarch64."
        ON)
#endif ()

option(FN_COMPILE_SSE2
        ""
        ON)
option(FN_COMPILE_SSE41
        ""
        ON)
option(FN_COMPILE_AVX2
        "This does not break support for pre AVX CPUs, AVX code is only run if support is detected."
        OFF)
option(FN_COMPILE_AVX512
        "Only the latest compilers will support this."
        OFF)
option(FN_USE_FMA
        "Using FMA instructions with AVX(51)2/NEON provides a small performance increase but can cause \
minute variations in noise output compared to other SIMD levels due to higher calculation precision."
        ON)
option(FN_ALIGNED_SETS
        "Using aligned sets of memory for float arrays allows faster storing of SIMD data."
        ON)

configure_file(FastNoiseSIMD.cmake.h FastNoiseSIMD/FastNoiseSIMD/FastNoiseSIMD.h)

if (MSVC)
    set(CMAKE_CXX_FLAGS /arch:AVX2)
else ()
    set(CMAKE_CXX_FLAGS -march=core-avx2)
endif ()

add_library(FAST_NOISE_SIMD STATIC
        FastNoiseSIMD/FastNoiseSIMD/FastNoiseSIMD.cpp
        FastNoiseSIMD/FastNoiseSIMD/FastNoiseSIMD_avx2.cpp
        FastNoiseSIMD/FastNoiseSIMD/FastNoiseSIMD_avx512.cpp
        FastNoiseSIMD/FastNoiseSIMD/FastNoiseSIMD_internal.cpp
        FastNoiseSIMD/FastNoiseSIMD/FastNoiseSIMD_neon.cpp
        FastNoiseSIMD/FastNoiseSIMD/FastNoiseSIMD_sse2.cpp
        FastNoiseSIMD/FastNoiseSIMD/FastNoiseSIMD_sse41.cpp
)

target_include_directories(FAST_NOISE_SIMD PRIVATE
        FastNoiseSIMD/FastNoiseSIMD
)

set(FAST_NOISE_SIMD_HEADERS
        FastNoiseSIMD/FastNoiseSIMD/FastNoiseSIMD.h
        # FastNoiseSIMD/FastNoiseSIMD/FastNoiseSIMD_internal.h
        PARENT_SCOPE
)

message("
############################################################
##  Ogre setup
############################################################
")
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/ogredeps")
    message("----- Ogredeps found! -----")
else()
    message("----- Pulling Ogredeps -----")
    execute_process(COMMAND hg clone https://bitbucket.org/cabalistic/ogredeps/
            WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
    )
endif()

# Set vars
SET(OGRE_DEPENDENCIES_DIR ${CMAKE_CURRENT_SOURCE_DIR}/ogredeps CACHE STRING "_" FORCE)
if(CMAKE_BUILD_TYPE EQUAL Debug)
    SET(OGRE_DEBUG_MODE true CACHE BOOL "_" FORCE)
else()
    SET(OGRE_DEBUG_MODE false CACHE BOOL "_" FORCE)
endif()
SET(OGRE_STATIC true CACHE BOOL "_" FORCE)
SET(OGRE_BUILD_SAMPLES2 false CACHE BOOL "_" FORCE)
SET(OGRE_USE_BOOST false CACHE BOOL "_" FORCE)
SET(OGRE_CONFIG_THREAD_PROVIDER false CACHE BOOL "_" FORCE)
SET(OGRE_CONFIG_THREADS false CACHE BOOL "_" FORCE)

add_subdirectory(ogredeps)
add_subdirectory(ogredeps/src/SDL2) # I don't know why but it's not include by ogredeps/CMakeLists.txt
add_subdirectory(Ogre)

set(OGRE_INCLUDE_DIRS
        ${ZLIB_INCLUDE_DIR}
        ${ZZip_INCLUDE_DIR}
        ${FreeImage_INCLUDE_DIR}
        ${FREETYPE_INCLUDE_DIR}
        ${rapidjson_INCLUDE_DIR}
        ${OPENGL_INCLUDE_DIR}
        ${OPENGLES_INCLUDE_DIR}
        ${OPENGLES2_INCLUDE_DIR}
        ${OPENGLES3_INCLUDE_DIR}
        ${OIS_INCLUDE_DIR}
        ${Cg_INCLUDE_DIR}
        ${X11_INCLUDE_DIR}
        ${DirectX_INCLUDE_DIR}
        ${CppUnit_INCLUDE_DIR}
        ${GLSL_Optimizer_INCLUDE_DIR}
        ${HLSL2GLSL_INCLUDE_DIR}
        ${SDL2_INCLUDE_DIR}
)

message("
############################################################
##  END Libs setup
############################################################
")
Problems:
- Ogre use find_package cmake function to search depndancies so on linux it found system install and don't target ogredeps
- find_package also need that already compiled for work

What I want it's one way to compile all project deps (including Ogre and also ogredeps) and project itself, and leave cmake/Makefile handling changes and recompile what needed.

Thanks in advance for your further response.

Hideman
Post Reply