Getting a running version of modularized cmakelists up and running

This commit is contained in:
Alexander Bock
2015-05-23 02:03:06 +02:00
parent f2a7ea9630
commit b882ba6078
11 changed files with 300 additions and 186 deletions

View File

@@ -48,7 +48,7 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${OPENSPACE_BASE_DIR}/bin/openspace)
set_property(GLOBAL PROPERTY USE_FOLDERS On)
set_property(GLOBAL PROPERTY PREDEFINED_TARGETS_FOLDER CMake)
include(${OPENSPACE_CMAKE_EXT_DIR}/module_macros.cmake)
include(${OPENSPACE_CMAKE_EXT_DIR}/module_common.cmake)
include(${OPENSPACE_EXT_DIR}/ghoul/ext/CopySharedLibraries.cmake)
#############################
# Set current OpenSpace Version
@@ -80,6 +80,7 @@ target_link_libraries(OpenSpace libOpenSpace)
#############################
# General Options
#############################
option(OPENSPACE_WARNINGS_AS_ERRORS "Treat warnings as errors" OFF)
if (MSVC)
option(OPENSPACE_ENABLE_VLD "Enable the Visual Leak Detector" OFF)
if (OPENSPACE_ENABLE_VLD)
@@ -97,9 +98,14 @@ if (MSVC)
endif ()
target_compile_options(libOpenSpace PUBLIC "/MP" "/wd4201" "/wd4127")
if (OPENSPACE_WARNINGS_AS_ERRORS)
target_compile_options(libOpenSpace PUBLIC "/WX")
target_compile_options(OpenSpace PUBLIC "/WX")
endif ()
set_target_properties(OpenSpace PROPERTIES LINK_FLAGS
"/NODEFAULTLIB:LIBCMTD.lib /NODEFAULTLIB:LIBCMT.lib"
)
"/NODEFAULTLIB:LIBCMTD.lib /NODEFAULTLIB:LIBCMT.lib"
)
elseif (APPLE)
target_compile_definitions(libOpenSpace PUBLIC "__APPLE__")
@@ -225,19 +231,78 @@ endif (OPENSPACE_HAVE_TESTS)
# Modules
#############################
#add_internal_modules
generate_unset_mod_options_and_depend_sort(${OPENSPACE_MODULE_DIR} OPENSPACE_SORTED_MODULES)
#Resolve dependencies for selected modules
resolve_module_dependencies(${OPENSPACE_MODULE_DIR} ${OPENSPACE_SORTED_MODULES})
# Get all modules in the correct order based on their dependencies
file(GLOB moduleDirs RELATIVE ${OPENSPACE_MODULE_DIR} ${OPENSPACE_MODULE_DIR}/*)
set(sortedModules ${moduleDirs})
foreach (dir ${moduleDirs})
if(IS_DIRECTORY ${OPENSPACE_MODULE_DIR}/${dir})
set(defaultModule OFF)
if (EXISTS "${OPENSPACE_MODULE_DIR}/${dir}/include.cmake")
unset(OPENSPACE_DEPENDENCIES)
unset(DEFAULT_MODULE)
include(${OPENSPACE_MODULE_DIR}/${dir}/include.cmake)
foreach (moduleDir ${OPENSPACE_SORTED_MODULES})
openspace_dir_to_mod_prefix(module ${moduleDir})
if (${module})
add_subdirectory(modules/${moduleDir})
target_link_libraries(libOpenSpace openspace-module-${moduleDir})
if (DEFINED DEFAULT_MODULE)
set(defaultModule ${DEFAULT_MODULE})
endif ()
if (OPENSPACE_DEPENDENCIES)
foreach (dependency ${OPENSPACE_DEPENDENCIES})
create_library_name(${dependency} library)
if (TARGET ${library})
# already registered
list(REMOVE_ITEM OPENSPACE_DEPENDENCIES ${dependency})
endif ()
endforeach ()
list(APPEND OPENSPACE_DEPENDENCIES ${dir})
list(FIND sortedModules ${dir} dir_index)
# if (NOT dir STREQUAL "base")
# list(INSERT OPENSPACE_DEPENDENCIES 0 "base")
# endif ()
list(INSERT sortedModules ${dir_index} ${OPENSPACE_DEPENDENCIES})
list(REMOVE_DUPLICATES sortedModules)
endif ()
endif ()
create_option_name(${dir} optionName)
option(${optionName} "Build ${dir} Module" ${defaultModule})
# create_library_name(${module} ${library})
else ()
list(REMOVE_ITEM sortedModules ${dir})
endif ()
endforeach ()
# Automatically set dependent modules to ON
set(dir_list ${sortedModules})
list(REVERSE dir_list)
foreach (dir ${dir_list})
create_option_name(${dir} optionName)
if (${optionName})
if (EXISTS "${OPENSPACE_MODULE_DIR}/${dir}/include.cmake")
unset(OPENSPACE_DEPENDENCIES)
unset(DEFAULT_MODULE)
include(${OPENSPACE_MODULE_DIR}/${dir}/include.cmake)
if (OPENSPACE_DEPENDENCIES)
foreach (dependency ${OPENSPACE_DEPENDENCIES})
create_option_name(${dependency} dependencyOptionName)
set(${dependencyOptionName} ON CACHE BOOL "ff" FORCE)
message(STATUS "${dependencyOptionName} was set to build, due to dependency towards ${optionName}")
endforeach ()
endif ()
endif ()
endif ()
endforeach ()
# Add subdirectories in the correct order
foreach (module ${sortedModules})
create_option_name(${module} optionName)
if (${optionName})
create_library_name(${module} libraryName)
add_subdirectory(${OPENSPACE_MODULE_DIR}/${module})
target_link_libraries(libOpenSpace ${libraryName})
endif ()
endforeach ()
#############################
# Project Folder structure (where appropriate)

View File

@@ -22,6 +22,8 @@
# OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #
#########################################################################################
include(${OPENSPACE_CMAKE_EXT_DIR}/module_definition.cmake)
set(HEADER_FILES
${CMAKE_CURRENT_SOURCE_DIR}/rendering/modelgeometry.h
${CMAKE_CURRENT_SOURCE_DIR}/rendering/planetgeometry.h
@@ -89,15 +91,7 @@ set(SHADER_FILES
)
source_group("Shader Files" FILES ${SHADER_FILES})
set(MODULE_CLASS_FILES
${CMAKE_CURRENT_SOURCE_DIR}/basemodule.h
${CMAKE_CURRENT_SOURCE_DIR}/basemodule.cpp
create_new_module(
"Base"
${HEADER_FILES} ${SOURCE_FILES} ${SHADER_FILES}
)
add_library(openspace-module-base ${HEADER_FILES} ${SOURCE_FILES} ${MODULE_CLASS_FILES})
target_include_directories(openspace-module-base PUBLIC "${OPENSPACE_BASE_DIR}/include" "${OPENSPACE_BASE_DIR}")
get_property(OPENSPACE_INCLUDE_DIR TARGET libOpenSpace PROPERTY INTERFACE_INCLUDE_DIRECTORIES)
target_include_directories(openspace-module-base PUBLIC ${OPENSPACE_INCLUDE_DIR})
get_property(OPENSPACE_DEFINITIONS TARGET libOpenSpace PROPERTY INTERFACE_COMPILE_DEFINITIONS)
target_compile_definitions(openspace-module-base PUBLIC ${OPENSPACE_DEFINITIONS})

View File

@@ -0,0 +1 @@
set(DEFAULT_MODULE ON)

View File

@@ -120,7 +120,7 @@ bool RenderablePath::initialize() {
bool RenderablePath::deinitialize() {
glDeleteVertexArrays(1, &_vaoID);
glDeleteBuffers(1, &_vBufferID);
Renderable::deinitialize();
//Renderable::deinitialize();
return true;
}

View File

@@ -125,7 +125,7 @@ bool RenderableTrail::initialize() {
bool RenderableTrail::deinitialize() {
glDeleteVertexArrays(1, &_vaoID);
glDeleteBuffers(1, &_vBufferID);
Renderable::deinitialize();
//Renderable::deinitialize();
return true;
}

View File

@@ -22,54 +22,58 @@
# OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #
#########################################################################################
include(${OPENSPACE_CMAKE_EXT_DIR}/module_definition.cmake)
set(HEADER_FILES
${CMAKE_CURRENT_SOURCE_DIR}/rendering/planetgeometryprojection.h
${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderablecrawlingline.h
${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderablefov.h
${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderableplaneprojection.h
${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderableplanetprojection.h
${CMAKE_CURRENT_SOURCE_DIR}/rendering/simplespheregeometryprojection.h
${CMAKE_CURRENT_SOURCE_DIR}/rendering/writeToTexture.h
${CMAKE_CURRENT_SOURCE_DIR}/util/decoder.h
${CMAKE_CURRENT_SOURCE_DIR}/util/hongkangparser.h
${CMAKE_CURRENT_SOURCE_DIR}/util/imagesequencer.h
${CMAKE_CURRENT_SOURCE_DIR}/util/imagesequencer2.h
${CMAKE_CURRENT_SOURCE_DIR}/util/instrumentdecoder.h
${CMAKE_CURRENT_SOURCE_DIR}/util/labelparser.h
${CMAKE_CURRENT_SOURCE_DIR}/util/scannerdecoder.h
${CMAKE_CURRENT_SOURCE_DIR}/util/sequenceparser.h
${CMAKE_CURRENT_SOURCE_DIR}/util/targetdecoder.h
${CMAKE_CURRENT_SOURCE_DIR}/rendering/planetgeometryprojection.h
${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderablecrawlingline.h
${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderablefov.h
${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderableplaneprojection.h
${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderableplanetprojection.h
${CMAKE_CURRENT_SOURCE_DIR}/rendering/simplespheregeometryprojection.h
${CMAKE_CURRENT_SOURCE_DIR}/rendering/writeToTexture.h
${CMAKE_CURRENT_SOURCE_DIR}/util/decoder.h
${CMAKE_CURRENT_SOURCE_DIR}/util/hongkangparser.h
${CMAKE_CURRENT_SOURCE_DIR}/util/imagesequencer.h
${CMAKE_CURRENT_SOURCE_DIR}/util/imagesequencer2.h
${CMAKE_CURRENT_SOURCE_DIR}/util/instrumentdecoder.h
${CMAKE_CURRENT_SOURCE_DIR}/util/labelparser.h
${CMAKE_CURRENT_SOURCE_DIR}/util/scannerdecoder.h
${CMAKE_CURRENT_SOURCE_DIR}/util/sequenceparser.h
${CMAKE_CURRENT_SOURCE_DIR}/util/targetdecoder.h
)
source_group("Header Files" FILES ${HEADER_FILES})
set(SOURCE_FILES
${CMAKE_CURRENT_SOURCE_DIR}/rendering/planetgeometryprojection.cpp
${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderablecrawlingline.cpp
${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderablefov.cpp
${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderableplaneprojection.cpp
${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderableplanetprojection.cpp
${CMAKE_CURRENT_SOURCE_DIR}/rendering/simplespheregeometryprojection.cpp
${CMAKE_CURRENT_SOURCE_DIR}/util/decoder.cpp
${CMAKE_CURRENT_SOURCE_DIR}/util/hongkangparser.cpp
${CMAKE_CURRENT_SOURCE_DIR}/util/imagesequencer.cpp
${CMAKE_CURRENT_SOURCE_DIR}/util/imagesequencer2.cpp
${CMAKE_CURRENT_SOURCE_DIR}/util/instrumentdecoder.cpp
${CMAKE_CURRENT_SOURCE_DIR}/util/labelparser.cpp
${CMAKE_CURRENT_SOURCE_DIR}/util/scannerdecoder.cpp
${CMAKE_CURRENT_SOURCE_DIR}/util/sequenceparser.cpp
${CMAKE_CURRENT_SOURCE_DIR}/util/targetdecoder.cpp
${CMAKE_CURRENT_SOURCE_DIR}/rendering/planetgeometryprojection.cpp
${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderablecrawlingline.cpp
${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderablefov.cpp
${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderableplaneprojection.cpp
${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderableplanetprojection.cpp
${CMAKE_CURRENT_SOURCE_DIR}/rendering/simplespheregeometryprojection.cpp
${CMAKE_CURRENT_SOURCE_DIR}/util/decoder.cpp
${CMAKE_CURRENT_SOURCE_DIR}/util/hongkangparser.cpp
${CMAKE_CURRENT_SOURCE_DIR}/util/imagesequencer.cpp
${CMAKE_CURRENT_SOURCE_DIR}/util/imagesequencer2.cpp
${CMAKE_CURRENT_SOURCE_DIR}/util/instrumentdecoder.cpp
${CMAKE_CURRENT_SOURCE_DIR}/util/labelparser.cpp
${CMAKE_CURRENT_SOURCE_DIR}/util/scannerdecoder.cpp
${CMAKE_CURRENT_SOURCE_DIR}/util/sequenceparser.cpp
${CMAKE_CURRENT_SOURCE_DIR}/util/targetdecoder.cpp
)
source_group("Source Files" FILES ${SOURCE_FILES})
set(MODULE_CLASS_FILES
${CMAKE_CURRENT_SOURCE_DIR}/newhorizonsmodule.h
${CMAKE_CURRENT_SOURCE_DIR}/newhorizonsmodule.cpp
set(SHADER_FILES
${CMAKE_CURRENT_SOURCE_DIR}/shaders/crawlingline_fs.glsl
${CMAKE_CURRENT_SOURCE_DIR}/shaders/crawlingline_vs.glsl
${CMAKE_CURRENT_SOURCE_DIR}/shaders/fov_fs.glsl
${CMAKE_CURRENT_SOURCE_DIR}/shaders/fov_vs.glsl
${CMAKE_CURRENT_SOURCE_DIR}/shaders/projectiveTexture_fs.glsl
${CMAKE_CURRENT_SOURCE_DIR}/shaders/projectiveTexture_vs.glsl
)
source_group("Shader Files" FILES ${SHADER_FILES})
add_library(openspace-module-newhorizons ${HEADER_FILES} ${SOURCE_FILES} ${MODULE_CLASS_FILES})
target_include_directories(openspace-module-newhorizons PUBLIC "${OPENSPACE_BASE_DIR}/include" "${OPENSPACE_BASE_DIR}")
get_property(OPENSPACE_INCLUDE_DIR TARGET libOpenSpace PROPERTY INTERFACE_INCLUDE_DIRECTORIES)
target_include_directories(openspace-module-newhorizons PUBLIC ${OPENSPACE_INCLUDE_DIR})
get_property(OPENSPACE_DEFINITIONS TARGET libOpenSpace PROPERTY INTERFACE_COMPILE_DEFINITIONS)
target_compile_definitions(openspace-module-newhorizons PUBLIC ${OPENSPACE_DEFINITIONS})
create_new_module(
"NewHorizons"
${HEADER_FILES} ${SOURCE_FILES} ${SHADER_FILES}
)

View File

@@ -22,6 +22,8 @@
# OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #
#########################################################################################
include(${OPENSPACE_CMAKE_EXT_DIR}/module_definition.cmake)
set(HEADER_FILES
${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderablevolume.h
${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderablevolumegl.h
@@ -34,15 +36,7 @@ set(SOURCE_FILES
)
source_group("Source Files" FILES ${SOURCE_FILES})
set(MODULE_CLASS_FILES
${CMAKE_CURRENT_SOURCE_DIR}/volumemodule.h
${CMAKE_CURRENT_SOURCE_DIR}/volumemodule.cpp
create_new_module(
"Volume"
${HEADER_FILES} ${SOURCE_FILES} ${SHADER_FILES}
)
add_library(openspace-module-volume ${HEADER_FILES} ${SOURCE_FILES} ${MODULE_CLASS_FILES})
target_include_directories(openspace-module-volume PUBLIC "${OPENSPACE_BASE_DIR}/include" "${OPENSPACE_BASE_DIR}")
get_property(OPENSPACE_INCLUDE_DIR TARGET libOpenSpace PROPERTY INTERFACE_INCLUDE_DIRECTORIES)
target_include_directories(openspace-module-volume PUBLIC ${OPENSPACE_INCLUDE_DIR})
get_property(OPENSPACE_DEFINITIONS TARGET libOpenSpace PROPERTY INTERFACE_COMPILE_DEFINITIONS)
target_compile_definitions(openspace-module-volume PUBLIC ${OPENSPACE_DEFINITIONS})

View File

@@ -0,0 +1 @@
set(DEFAULT_MODULE ON)

View File

@@ -0,0 +1,33 @@
#########################################################################################
# #
# OpenSpace #
# #
# Copyright (c) 2014-2015 #
# #
# Permission is hereby granted, free of charge, to any person obtaining a copy of this #
# software and associated documentation files (the "Software"), to deal in the Software #
# without restriction, including without limitation the rights to use, copy, modify, #
# merge, publish, distribute, sublicense, and/or sell copies of the Software, and to #
# permit persons to whom the Software is furnished to do so, subject to the following #
# conditions: #
# #
# The above copyright notice and this permission notice shall be included in all copies #
# or substantial portions of the Software. #
# #
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, #
# INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A #
# PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT #
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF #
# CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE #
# OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #
#########################################################################################
function (create_library_name module_name library_name)
string(TOLOWER ${module_name} module_name)
set(${library_name} "openspace-module-${module_name}" PARENT_SCOPE)
endfunction ()
function (create_option_name module_name option_name)
string(TOUPPER ${module_name} module_name)
set(${option_name} "OPENSPACE_MODULE_${module_name}" PARENT_SCOPE)
endfunction ()

View File

@@ -0,0 +1,131 @@
#########################################################################################
# #
# OpenSpace #
# #
# Copyright (c) 2014-2015 #
# #
# Permission is hereby granted, free of charge, to any person obtaining a copy of this #
# software and associated documentation files (the "Software"), to deal in the Software #
# without restriction, including without limitation the rights to use, copy, modify, #
# merge, publish, distribute, sublicense, and/or sell copies of the Software, and to #
# permit persons to whom the Software is furnished to do so, subject to the following #
# conditions: #
# #
# The above copyright notice and this permission notice shall be included in all copies #
# or substantial portions of the Software. #
# #
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, #
# INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A #
# PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT #
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF #
# CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE #
# OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #
#########################################################################################
include (${OPENSPACE_CMAKE_EXT_DIR}/module_common.cmake)
function (create_new_module
module_name
# Sources
)
set(sources ${ARGN})
project(${module_name})
# Create a library name of the style: openspace-module-${name}
create_library_name(${module_name} library_name)
message(STATUS "Configuring module ${MODULE_NAME}: ${library_name}")
add_module_files()
add_library(${library_name} ${sources})
set_common_compile_settings(${library_name})
set_openspace_includes(${library_name})
handle_dependencies(${library_name} ${module_name})
endfunction ()
# I couldn't make adding the module files to the ${sources} variable to work with a function ---abock
# Adds the <name>module.h and <name>module.cpp files to the list of sources and provides
# Them with a source group
macro (add_module_files)
string(TOLOWER ${module_name} module_name_lower)
set(module_files
${CMAKE_CURRENT_SOURCE_DIR}/${module_name_lower}module.h
${CMAKE_CURRENT_SOURCE_DIR}/${module_name_lower}module.cpp
)
source_group("Module Files" FILES ${module_files})
list(APPEND sources ${module_files})
endmacro ()
# Set the compiler settings that are common to all modules
function (set_common_compile_settings target_name)
if (MSVC)
target_compile_options(${library_name} PUBLIC
"/MP" # Enabling multi-threaded compilation
"/wd4100" # Unreferenced formal parameter [too frequent in external libs]
"/wd4127" # constant conditional expression [used for do/while semicolon swallowing]
"/wd4201" # nameless struct/union [standard is ubiquitous]
"/wd4505" # Unreferenced function was removed
"/W4"
)
if (OPENSPACE_WARNINGS_AS_ERRORS)
target_compile_options(${library_name} PUBLIC "/Wx")
endif ()
endif ()
endfunction ()
# Propagate the include directives from the libOpenSpace target into this module
function (set_openspace_includes target_name)
get_property(
OPENSPACE_INCLUDE_DIR
TARGET libOpenSpace
PROPERTY INTERFACE_INCLUDE_DIRECTORIES
)
target_include_directories(${target_name} PUBLIC
"${OPENSPACE_BASE_DIR}"
${OPENSPACE_INCLUDE_DIR}
)
get_property(
OPENSPACE_DEFINES
TARGET libOpenSpace
PROPERTY INTERFACE_COMPILE_DEFINITIONS
)
target_compile_definitions(${target_name} PUBLIC ${OPENSPACE_DEFINES})
target_link_libraries(${target_name} libOpenSpace)
endfunction ()
# Loads the dependencies from 'include.cmake' and deals with them
function (handle_dependencies target_name module_name)
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/include.cmake")
include(${CMAKE_CURRENT_SOURCE_DIR}/include.cmake)
# if (NOT ${module_name} STREQUAL "Base")
# list(APPEND OPENSPACE_DEPENDENCIES "base")
# endif ()
# Handle OpenSpace dependencies
foreach (dep ${OPENSPACE_DEPENDENCIES})
create_library_name(${dep} dep_library)
target_link_libraries(${target_name} ${dep_library})
get_property(
DEP_INCLUDE_DIR
TARGET ${dep_library}
PROPERTY INTERFACE_INCLUDE_DIRECTORIES
)
target_include_directories(${target_name} PUBLIC ${DEP_INCLUDE_DIR})
endforeach ()
# Handle extenal dependencies
foreach (dep ${EXTERNAL_DEPENDENCIES})
string(TOUPPER ${dep} dep_upper)
find_package(${dep} REQUIRED)
target_include_directories(${target_name} PUBLIC
${${dep_upper}_INCLUDE_DIR} ${${dep_upper}_INCLUDE_DIRS}
)
target_link_libraries(${target_name} ${${dep_upper}_LIBRARIES})
endforeach ()
endif ()
endfunction ()

View File

@@ -1,109 +0,0 @@
#########################################################################################
# #
# OpenSpace #
# #
# Copyright (c) 2014-2015 #
# #
# Permission is hereby granted, free of charge, to any person obtaining a copy of this #
# software and associated documentation files (the "Software"), to deal in the Software #
# without restriction, including without limitation the rights to use, copy, modify, #
# merge, publish, distribute, sublicense, and/or sell copies of the Software, and to #
# permit persons to whom the Software is furnished to do so, subject to the following #
# conditions: #
# #
# The above copyright notice and this permission notice shall be included in all copies #
# or substantial portions of the Software. #
# #
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, #
# INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A #
# PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT #
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF #
# CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE #
# OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #
#########################################################################################
macro(first_case_upper retval in_value)
string(TOLOWER ${in_value} value)
string(SUBSTRING ${value} 0 1 first_letter)
string(TOUPPER ${first_letter} first_letter)
string(REGEX REPLACE "^.(.*)" "${first_letter}\\1" result "${value}")
set(${retval} ${result})
endmacro()
macro(openspace_mod_name_to_dir retval)
set(the_list "")
foreach(item ${ARGN})
string(REGEX MATCH "(^OpenSpace.*.Module$)" found_item ${item})
if(found_item)
string(REGEX REPLACE "(^OpenSpace)|(Module$)" "" new_item ${item})
string(TOLOWER ${new_item} l_new_item)
list(APPEND the_list ${l_new_item})
endif()
endforeach()
set(${retval} ${the_list})
endmacro()
macro(openspace_dir_to_mod_prefix retval)
set(the_list "")
foreach(item ${ARGN})
string(TOUPPER ${item} u_item)
list(APPEND the_list OPENSPACE_MODULE_${u_item})
endforeach()
set(${retval} ${the_list})
endmacro()
macro(generate_unset_mod_options_and_depend_sort module_root_path retval)
file(GLOB sub-dir RELATIVE ${module_root_path} ${module_root_path}/*)
set(sorted_dirs ${sub-dir})
foreach(dir ${sub-dir})
if(IS_DIRECTORY ${module_root_path}/${dir})
if(EXISTS "${module_root_path}/${dir}/depends.cmake")
include(${module_root_path}/${dir}/depends.cmake)
foreach(dependency ${dependencies})
list(FIND OPENSPACE_MODULE_PACKAGE_NAMES ${dependency} module_index)
if(NOT module_index EQUAL -1)
list(REMOVE_ITEM dependencies ${dependency})
endif()
endforeach()
openspace_mod_name_to_dir(depend_folders ${dependencies})
list(APPEND depend_folders ${dir})
list(FIND sorted_dirs ${dir} dir_index)
list(INSERT sorted_dirs ${dir_index} ${depend_folders})
list(REMOVE_DUPLICATES sorted_dirs)
endif()
openspace_dir_to_mod_prefix(mod_name ${dir})
if(NOT DEFINED ${mod_name})
first_case_upper(dir_name_cap ${dir})
option(${mod_name} "Build ${dir_name_cap} Module" OFF)
endif()
else()
list(REMOVE_ITEM sorted_dirs ${dir})
endif()
endforeach()
set(${retval} ${sorted_dirs})
endmacro()
macro(resolve_module_dependencies module_root_path)
#Reverse list (as it is depend sorted) and go over dependencies one more time
#If build is ON, then switch dependencies ON
set(dir_list ${ARGN})
list(REVERSE dir_list)
foreach(dir ${dir_list})
openspace_dir_to_mod_prefix(mod_name ${dir})
if(${mod_name})
if(EXISTS "${module_root_path}/${dir}/depends.cmake")
include(${module_root_path}/${dir}/depends.cmake)
openspace_mod_name_to_dir(depend_folders ${dependencies})
foreach(depend_folder ${depend_folders})
openspace_dir_to_mod_prefix(depend_mod_name ${depend_folder})
first_case_upper(depend_name_cap ${depend_folder})
if(NOT ${depend_mod_name})
set(${depend_mod_name} ON CACHE BOOL "Build ${depend_name_cap} Module" FORCE)
message(STATUS "${depend_mod_name} was set to build, due to dependency towards ${mod_name}")
endif()
endforeach()
endif()
endif()
endforeach()
endmacro()