Commit 4ad6ad39 authored by Sebastian Eichelbaum's avatar Sebastian Eichelbaum
Browse files

[ADD] - now copying and optional linking of shaders is done

parent 93a6beb5
......@@ -45,8 +45,6 @@ INCLUDE( ${PROJECT_SOURCE_DIR}/../tools/CMakeModules/Utils.cmake )
SET( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin )
SET( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib )
SET( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib )
# We additionally want to place common shared files to this path:
SET( SHARED_FILES_RELATIVE "../share/${CMAKE_PROJECT_NAME}" CACHE INTERNAL "Relative path to bin/ denoting the destination for shaders and cfg files." )
# CMAKE automatism to select static vs. shared building:
IF( NOT CMAKE_GENERATOR MATCHES "Visual Studio" )
......@@ -114,6 +112,10 @@ ELSE()
ENDIF()
SET( CMAKE_CXX_FLAGS_RELWITHDEBINFO "-g -DDEBUG -O2" CACHE STRING "" FORCE )
# other options
OPTION( OW_HANDLE_SHADERS "This ensures that shaders are available in build directory after build." ON )
OPTION( OW_LINK_SHADERS "If turned on, shaders do not get copied. They get linked. This is a nice option for developers." OFF )
# ---------------------------------------------------------------------------------------------------------------------------------------------------
#
# REQUIRED third party libs
......
......@@ -22,6 +22,8 @@
#
#---------------------------------------------------------------------------
SET( LibName ${OWCoreName} )
# Set the prefix and suffix of dynamically loadable modules to match
# CMAKEs naming of them. The quotes are necessary so the shell doesn't mess
# with these defines. Unfortunately, the Visual Studio has problems handling
......@@ -37,12 +39,12 @@ ENDIF()
# Add sources as target
# ---------------------------------------------------------------------------------------------------------------------------------------------------
# Collect the compile-files for OWCore
COLLECT_COMPILE_FILES( "${CMAKE_CURRENT_SOURCE_DIR}" CORE_CPP_FILES CORE_H_FILES CORE_TEST_FILES )
# Collect the compile-files for this target
COLLECT_COMPILE_FILES( "${CMAKE_CURRENT_SOURCE_DIR}" TARGET_CPP_FILES TARGET_H_FILES TARGET_TEST_FILES )
# Setup the OWCore target
ADD_LIBRARY( ${OWCoreName} SHARED ${CORE_CPP_FILES} ${CORE_H_FILES} )
TARGET_LINK_LIBRARIES( ${OWCoreName} ${OWExtBioSigName} ${OWExtEEPName} ${OWExtNiftiName}
# Setup the target
ADD_LIBRARY( ${LibName} SHARED ${TARGET_CPP_FILES} ${TARGET_H_FILES} )
TARGET_LINK_LIBRARIES( ${LibName} ${OWExtBioSigName} ${OWExtEEPName} ${OWExtNiftiName}
${Boost_LIBRARIES} ${CMAKE_DL_LIBS} ${OPENGL_gl_LIBRARY} ${OPENSCENEGRAPH_LIBRARIES}
)
......@@ -51,11 +53,12 @@ TARGET_LINK_LIBRARIES( ${OWCoreName} ${OWExtBioSigName} ${OWExtEEPName} ${OWExtN
# ---------------------------------------------------------------------------------------------------------------------------------------------------
# Setup tests of this target
SETUP_TESTS( "${CORE_TEST_FILES}" "${OWCoreName}" "" )
SETUP_TESTS( "${TARGET_TEST_FILES}" "${LibName}" "" )
# ---------------------------------------------------------------------------------------------------------------------------------------------------
# Copy Shaders
# ---------------------------------------------------------------------------------------------------------------------------------------------------
COLLECT_SHADER_FILES( ${CMAKE_CURRENT_SOURCE_DIR} GLSL_FILES )
SETUP_SHADERS( "${GLSL_FILES}" "${CMAKE_BINARY_DIR}/share/shaders" )
......@@ -45,6 +45,15 @@ FUNCTION( COLLECT_COMPILE_FILES _DirString _CPPFiles _HFiles _TestFiles )
SET( ${_TestFiles} "${TEST_FILES}" PARENT_SCOPE )
ENDFUNCTION( COLLECT_COMPILE_FILES )
# Recursively searches shader files with extension glsl.
# _DirString where to search
# _GLSLFiles the list of files found
FUNCTION( COLLECT_SHADER_FILES _DirString _GLSLFiles )
# recursively get all files
FILE( GLOB_RECURSE GLSL_FILES ${_DirString}/*.glsl )
SET( ${_GLSLFiles} "${GLSL_FILES}" PARENT_SCOPE )
ENDFUNCTION( COLLECT_SHADER_FILES )
# Add tests and copy their fixtures by specifiying the test headers. This is completely automatic and is done recusrively (fixtures). The test
# filenames need to be absolute. The fixtures are searched in CMAKE_CURRENT_SOURCE_DIR.
# _TEST_FILES the list of test header files.
......@@ -121,3 +130,28 @@ FUNCTION( SETUP_TESTS _TEST_FILES _TEST_TARGET )
ENDIF( OW_COMPILE_TESTS )
ENDFUNCTION( SETUP_TESTS )
# This function sets up the build system to ensure that the specified list of shaders is available after build in the target directory.
# _Shaders list of shaders
# _TargetDir the directory where to put the shaders
FUNCTION( SETUP_SHADERS _Shaders _TargetDir )
# only if we are allowed to
IF( OW_HANDLE_SHADERS )
EXECUTE_PROCESS( COMMAND ${CMAKE_COMMAND} -E make_directory ${_TargetDir} )
# should we copy or link them?
SET( ShaderOperation "copy_if_different" )
IF ( OW_LINK_SHADERS ) # link
SET( ShaderOperation "create_symlink" )
ENDIF( OW_LINK_SHADERS )
# now do the operation for each shader
FOREACH( fname ${_Shaders} )
# We need the plain filename (create_symlink needs it)
STRING( REGEX REPLACE "^.*/" "" StrippedFileName "${fname}" )
# let cmake do it
EXECUTE_PROCESS( COMMAND ${CMAKE_COMMAND} -E ${ShaderOperation} ${fname} "${_TargetDir}/${StrippedFileName}" )
ENDFOREACH( fname )
ENDIF( OW_HANDLE_SHADERS )
ENDFUNCTION( SETUP_SHADERS )
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment