Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue 56 + rewritten CMake script #57

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
338 changes: 130 additions & 208 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,218 +1,140 @@
cmake_minimum_required(VERSION 2.8)

project(hlsl2glslfork)

set(CMAKE_SUPPRESS_REGENERATION TRUE)

set(HEADER_FILES
hlslang/Include/BaseTypes.h
hlslang/Include/Common.h
hlslang/Include/InfoSink.h
hlslang/Include/InitializeGlobals.h
hlslang/Include/InitializeParseContext.h
hlslang/Include/intermediate.h
hlslang/Include/PoolAlloc.h
hlslang/Include/Types.h
hlslang/MachineIndependent/SymbolTable.h
)
source_group("Header Files" FILES ${HEADER_FILES})


set(GLSL_CODE_GEN_FILES
hlslang/GLSLCodeGen/glslCommon.cpp
hlslang/GLSLCodeGen/glslCommon.h
hlslang/GLSLCodeGen/glslFunction.cpp
hlslang/GLSLCodeGen/glslFunction.h
hlslang/GLSLCodeGen/glslOutput.cpp
hlslang/GLSLCodeGen/glslOutput.h
hlslang/GLSLCodeGen/glslStruct.cpp
hlslang/GLSLCodeGen/glslStruct.h
hlslang/GLSLCodeGen/glslSymbol.cpp
hlslang/GLSLCodeGen/glslSymbol.h
hlslang/GLSLCodeGen/hlslCrossCompiler.cpp
hlslang/GLSLCodeGen/hlslCrossCompiler.h
hlslang/GLSLCodeGen/hlslLinker.cpp
hlslang/GLSLCodeGen/hlslLinker.h
hlslang/GLSLCodeGen/hlslSupportLib.cpp
hlslang/GLSLCodeGen/hlslSupportLib.h
hlslang/GLSLCodeGen/propagateMutable.cpp
hlslang/GLSLCodeGen/propagateMutable.h
hlslang/GLSLCodeGen/typeSamplers.cpp
hlslang/GLSLCodeGen/typeSamplers.h
)
source_group("GLSL Code Gen" FILES ${GLSL_CODE_GEN_FILES})

set(INCLUDE_FILES
include
)

source_group("include" FILES ${INCLUDE_FILES})

set(MACHINE_INDEPENDENT_FILES
hlslang/MachineIndependent/HLSL2GLSL.cpp
hlslang/MachineIndependent/hlslang.l
hlslang/MachineIndependent/hlslang.y
hlslang/MachineIndependent/InfoSink.cpp
hlslang/MachineIndependent/Initialize.cpp
hlslang/MachineIndependent/Initialize.h
hlslang/MachineIndependent/Intermediate.cpp
hlslang/MachineIndependent/intermOut.cpp
hlslang/MachineIndependent/IntermTraverse.cpp
hlslang/MachineIndependent/localintermediate.h
#hlslang/MachineIndependent/parseConst.cpp
hlslang/MachineIndependent/ParseHelper.cpp
hlslang/MachineIndependent/ParseHelper.h
hlslang/MachineIndependent/PoolAlloc.cpp
hlslang/MachineIndependent/RemoveTree.cpp
hlslang/MachineIndependent/RemoveTree.h
hlslang/MachineIndependent/SymbolTable.cpp
hlslang/MachineIndependent/SymbolTable.h
hlslang/MachineIndependent/ConstantFolding.cpp
cmake_minimum_required(VERSION 2.8.12)

project(hlsl2glsl)

# derived from msvs2010 project

set(CMAKE_PROGRAM_PATH ${CMAKE_CURRENT_SOURCE_DIR}/tools ${CMAKE_CURRENT_SOURCE_DIR}/tools/bin)
find_package(BISON REQUIRED)
find_package(FLEX REQUIRED)
set(ENV{BISON_SIMPLE} ${CMAKE_CURRENT_SOURCE_DIR}/tools/bison.simple)
set(ENV{BISON_HAIRY} ${CMAKE_CURRENT_SOURCE_DIR}/tools/bison.simple)
execute_process(COMMAND ${BISON_EXECUTABLE} -d -t -v -o ${PROJECT_BINARY_DIR}/gen_hlslang_tab.cpp hlslang.y WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/hlslang/MachineIndependent)
execute_process(COMMAND ${FLEX_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/hlslang/MachineIndependent/hlslang.l WORKING_DIRECTORY ${PROJECT_BINARY_DIR})
file(WRITE ${PROJECT_BINARY_DIR}/hlslang_tab.h "#include <gen_hlslang_tab.hpp>")

set(HLSL2GLSL_HEADER
hlslang/MachineIndependent/Initialize.h
hlslang/MachineIndependent/localintermediate.h
hlslang/MachineIndependent/ParseHelper.h
hlslang/MachineIndependent/preprocessor/mojoshader.h
hlslang/MachineIndependent/preprocessor/mojoshader_internal.h
hlslang/MachineIndependent/RemoveTree.h
${PROJECT_BINARY_DIR}/gen_hlslang_tab.hpp
hlslang/MachineIndependent/preprocessor/sourceloc.h
hlslang/Include/BaseTypes.h
hlslang/Include/Common.h
hlslang/Include/InfoSink.h
hlslang/Include/InitializeGlobals.h
hlslang/Include/InitializeParseContext.h
hlslang/Include/intermediate.h
hlslang/Include/PoolAlloc.h
hlslang/MachineIndependent/SymbolTable.h
hlslang/Include/Types.h
include/hlsl2glsl.h
hlslang/GLSLCodeGen/glslCommon.h
hlslang/GLSLCodeGen/glslFunction.h
hlslang/GLSLCodeGen/glslOutput.h
hlslang/GLSLCodeGen/glslStruct.h
hlslang/GLSLCodeGen/glslSymbol.h
hlslang/GLSLCodeGen/hlslCrossCompiler.h
hlslang/GLSLCodeGen/hlslLinker.h
hlslang/GLSLCodeGen/hlslSupportLib.h
hlslang/GLSLCodeGen/propagateMutable.h
hlslang/GLSLCodeGen/typeSamplers.h
)

source_group("Machine Independent" FILES ${MACHINE_INDEPENDENT_FILES})

set(MACHINE_INDEPENDENT_CPP_FILES
hlslang/MachineIndependent/preprocessor/mojoshader_common.cpp
hlslang/MachineIndependent/preprocessor/mojoshader_internal.h
hlslang/MachineIndependent/preprocessor/mojoshader_lexer.cpp
hlslang/MachineIndependent/preprocessor/mojoshader_preprocessor.cpp
hlslang/MachineIndependent/preprocessor/mojoshader.cpp
hlslang/MachineIndependent/preprocessor/mojoshader.h
hlslang/MachineIndependent/preprocessor/sourceloc.cpp
hlslang/MachineIndependent/preprocessor/sourceloc.h
set(HLSL2GLSL_SRCS
hlslang/MachineIndependent/ConstantFolding.cpp
hlslang/MachineIndependent/HLSL2GLSL.cpp
hlslang/MachineIndependent/InfoSink.cpp
hlslang/MachineIndependent/Initialize.cpp
hlslang/MachineIndependent/Intermediate.cpp
hlslang/MachineIndependent/intermOut.cpp
hlslang/MachineIndependent/IntermTraverse.cpp
hlslang/MachineIndependent/ParseHelper.cpp
hlslang/MachineIndependent/PoolAlloc.cpp
hlslang/MachineIndependent/preprocessor/mojoshader.cpp
hlslang/MachineIndependent/preprocessor/mojoshader_common.cpp
hlslang/MachineIndependent/preprocessor/mojoshader_lexer.cpp
hlslang/MachineIndependent/preprocessor/mojoshader_preprocessor.cpp
hlslang/MachineIndependent/preprocessor/sourceloc.cpp
hlslang/MachineIndependent/RemoveTree.cpp
hlslang/MachineIndependent/SymbolTable.cpp
${PROJECT_BINARY_DIR}/Gen_hlslang.cpp
${PROJECT_BINARY_DIR}/gen_hlslang_tab.cpp
hlslang/GLSLCodeGen/glslCommon.cpp
hlslang/GLSLCodeGen/glslFunction.cpp
hlslang/GLSLCodeGen/glslOutput.cpp
hlslang/GLSLCodeGen/glslStruct.cpp
hlslang/GLSLCodeGen/glslSymbol.cpp
hlslang/GLSLCodeGen/hlslCrossCompiler.cpp
hlslang/GLSLCodeGen/hlslLinker.cpp
hlslang/GLSLCodeGen/hlslSupportLib.cpp
hlslang/GLSLCodeGen/propagateMutable.cpp
hlslang/GLSLCodeGen/typeSamplers.cpp
)

source_group("Machine Independent\\CPP" FILES ${MACHINE_INDEPENDENT_CPP_FILES})


if (WIN32)
EXEC_PROGRAM(${CMAKE_COMMAND} ARGS "-E write_regv \"${hkey}\" \"${dir}\"")
endif ()


set(MACHINE_INDEPENDENT_GENERATED_SOURCE_FILES
${CMAKE_CURRENT_SOURCE_DIR}/hlslang/MachineIndependent/Gen_hlslang.cpp
${CMAKE_CURRENT_SOURCE_DIR}/hlslang/MachineIndependent/hlslang_tab.cpp
${CMAKE_CURRENT_SOURCE_DIR}/hlslang/MachineIndependent/hlslang_tab.h
)

SET_SOURCE_FILES_PROPERTIES(${MACHINE_INDEPENDENT_GENERATED_SOURCE_FILES} PROPERTIES
GENERATED 1
)

source_group("Machine Independent\\Generated Source" FILES ${MACHINE_INDEPENDENT_GENERATED_SOURCE_FILES})


# Add system specific settings
if (WIN32)
set(OSDEPENDENT_FILES
hlslang/OSDependent/Windows/main.cpp
hlslang/OSDependent/Windows/osinclude.h
hlslang/OSDependent/Windows/ossource.cpp
)
source_group("OSDependent\\Windows" FILES ${OSDEPENDENT_FILES})
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/hlslang/OSDependent/Windows)

add_custom_command(OUTPUT hlslang/MachineIndependent/Gen_hlslang_tab.cpp hlslang/MachineIndependent/hlslang_tab.h
COMMAND set ARGS "BISON_SIMPLE=../../tools/bison.simple"
COMMAND set ARGS "BISON_HAIRY=../../tools/bison.simple"
COMMAND ../../tools/bison.exe ARGS -d -t -v hlslang.y
COMMAND copy ARGS /y hlslang_tab.c Gen_hlslang_tab.cpp
COMMAND del ARGS hlslang_tab.c
COMMAND del ARGS hlslang.output
MAIN_DEPENDENCY hlslang/MachineIndependent/hlslang.y
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/hlslang/MachineIndependent
COMMENT "Executing Bison on hlslang.y"
)

add_custom_command(OUTPUT hlslang/MachineIndependent/Gen_hlslang.cpp
COMMAND ../../tools/flex.exe ARGS hlslang.l
MAIN_DEPENDENCY hlslang/MachineIndependent/hlslang.l
DEPENDS hlslang/MachineIndependent/hlslang_tab.h
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/hlslang/MachineIndependent
COMMENT "Executing flex on hlslang.l"
)

SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /D\"_HAS_ITERATOR_DEBUGGING=0\" /D\"_SECURE_SCL=0\" /D\"_CRT_SECURE_NO_WARNINGS\"")
SET(TEST_LIBS opengl32.lib)
elseif (APPLE)
set(OSDEPENDENT_FILES
hlslang/OSDependent/Mac/osinclude.h
hlslang/OSDependent/Mac/ossource.cpp
)
source_group("OSDependent\\Mac" FILES ${OSDEPENDENT_FILES})
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/hlslang/OSDependent/Mac)

add_custom_command(OUTPUT hlslang/MachineIndependent/Gen_hlslang_tab.cpp hlslang/MachineIndependent/hlslang_tab.h
COMMAND set ARGS "BISON_SIMPLE=../../tools/bison.simple"
COMMAND set ARGS "BISON_HAIRY=../../tools/bison.simple"
COMMAND bison ARGS -o hlslang_tab.cpp -d -t -v hlslang.y
COMMAND mv hlslang_tab.hpp hlslang_tab.h
MAIN_DEPENDENCY hlslang/MachineIndependent/hlslang.y
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/hlslang/MachineIndependent
COMMENT "Executing Bison on hlslang.y"
)

add_custom_command(OUTPUT hlslang/MachineIndependent/Gen_hlslang.cpp
COMMAND flex ARGS hlslang.l
MAIN_DEPENDENCY hlslang/MachineIndependent/hlslang.l
DEPENDS hlslang/MachineIndependent/hlslang_tab.h
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/hlslang/MachineIndependent
COMMENT "Executing flex on hlslang.l"
)
FIND_LIBRARY(OPENGL_LIBRARY OpenGL)
FIND_LIBRARY(COCOA_LIBRARY Cocoa)
SET(TEST_LIBS ${OPENGL_LIBRARY} ${COCOA_LIBRARY})
elseif (UNIX)
set(OSDEPENDENT_FILES
hlslang/OSDependent/Linux/osinclude.h
hlslang/OSDependent/Linux/ossource.cpp
)
source_group("OSDependent\\Linux" FILES ${OSDEPENDENT_FILES})
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/hlslang/OSDependent/Linux)

add_custom_command(OUTPUT hlslang/MachineIndependent/hlslang_tab.cpp hlslang/MachineIndependent/hlslang_tab.h
COMMAND set ARGS "BISON_SIMPLE=../../tools/bison.simple"
COMMAND set ARGS "BISON_HAIRY=../../tools/bison.simple"
COMMAND bison ARGS -o hlslang_tab.cpp -d -t -v hlslang.y
COMMAND mv hlslang_tab.hpp hlslang_tab.h
MAIN_DEPENDENCY hlslang/MachineIndependent/hlslang.y
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/hlslang/MachineIndependent
COMMENT "Executing Bison on hlslang.y"
)

add_custom_command(OUTPUT hlslang/MachineIndependent/Gen_hlslang.cpp
COMMAND flex ARGS hlslang.l
MAIN_DEPENDENCY hlslang/MachineIndependent/hlslang.l
DEPENDS hlslang/MachineIndependent/hlslang_tab.h
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/hlslang/MachineIndependent
COMMENT "Executing flex on hlslang.l"
)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ggdb")
SET(TEST_LIBS GL glut GLEW pthread)
endif ()


include_directories(
${CMAKE_CURRENT_SOURCE_DIR}/include
${CMAKE_CURRENT_SOURCE_DIR}/hlslang
${CMAKE_CURRENT_SOURCE_DIR}/hlslang/MachineIndependent
${PROJECT_BINARY_DIR}
)

add_library(hlsl2glsl
${HEADER_FILES}
${GLSL_CODE_GEN_FILES}
${INCLUDE_FILES}
${MACHINE_INDEPENDENT_FILES}
${MACHINE_INDEPENDENT_CPP_FILES}
${OSDEPENDENT_FILES}
${MACHINE_INDEPENDENT_GENERATED_SOURCE_FILES}
)


include_directories(
${INCLUDE_FILES}
)
# Add system specific settings
if (WIN32)
set(HLSL2GLSL_HEADER
${HLSL2GLSL_HEADER}
hlslang/OSDependent/Windows/osinclude.h
hlslang/OSDependent/Windows/unistd.h
)
set(HLSL2GLSL_SRCS
${HLSL2GLSL_SRCS}
hlslang/OSDependent/Windows/ossource.cpp
)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/hlslang/OSDependent/Windows)
add_definitions(/D "_HAS_ITERATOR_DEBUGGING=0" /D "_SECURE_SCL=0" /D "_CRT_SECURE_NO_WARNINGS")
set(CMAKE_DEBUG_POSTFIX "_d")
elseif(APPLE)
set(HLSL2GLSL_HEADER
${HLSL2GLSL_HEADER}
hlslang/OSDependent/Mac/osinclude.h
)
set(HLSL2GLSL_SRCS
${HLSL2GLSL_SRCS}
hlslang/OSDependent/Mac/ossource.cpp
)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/hlslang/OSDependent/Mac)
else()
set(HLSL2GLSL_HEADER
${HLSL2GLSL_HEADER}
hlslang/OSDependent/Linux/osinclude.h
)
set(HLSL2GLSL_SRCS
${HLSL2GLSL_SRCS}
hlslang/OSDependent/Linux/ossource.cpp
)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/hlslang/OSDependent/Linux)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ggdb")
endif()

add_library(hlsl2glsl ${HLSL2GLSL_HEADER} ${HLSL2GLSL_SRCS})

find_package(OpenGL REQUIRED)
add_executable(hlsl2glsltest tests/hlsl2glsltest/hlsl2glsltest.cpp)

target_link_libraries(hlsl2glsltest hlsl2glsl ${TEST_LIBS})
target_link_libraries(hlsl2glsltest hlsl2glsl)
include_directories(hlsl2glsltest ${OPENGL_INCLUDE_DIRS})
target_link_libraries(hlsl2glsltest ${OPENGL_LIBRARIES})

if(MSVC)
set_target_properties(hlsl2glsl PROPERTIES COMPILE_FLAGS /Fd"$(IntDir)$(TargetName).pdb")

INSTALL(TARGETS hlsl2glsl DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/Debug CONFIGURATIONS Debug)
INSTALL(FILES ${PROJECT_BINARY_DIR}/Debug/hlsl2glsl_d.pdb DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/Debug CONFIGURATIONS Debug)
INSTALL(TARGETS hlsl2glsl DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/MinSizeRel CONFIGURATIONS MinSizeRel)
INSTALL(TARGETS hlsl2glsl DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/Release CONFIGURATIONS Release)
INSTALL(TARGETS hlsl2glsl DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/RelWithDebInfo CONFIGURATIONS RelWithDebInfo)
#INSTALL(FILES ${PROJECT_BINARY_DIR}/RelWithDebInfo/hlsl2glsl.pdb DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/RelWithDebInfo CONFIGURATIONS RelWithDebInfo)
INSTALL(FILES ${CMAKE_SOURCE_DIR}/include/hlsl2glsl.h DESTINATION ${CMAKE_INSTALL_PREFIX}/include)
endif(MSVC)
1 change: 1 addition & 0 deletions hlslang/MachineIndependent/Intermediate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "ParseHelper.h"
#include <float.h>
#include <limits.h>
#include <algorithm>

static TPrecision GetHigherPrecision (TPrecision left, TPrecision right) {
return left > right ? left : right;
Expand Down