kcat / openal-soft

OpenAL Soft is a software implementation of the OpenAL 3D audio API.
Other
2.2k stars 532 forks source link

Compiling OpenAL from source as a git submodule #699

Closed beckylum0216 closed 2 years ago

beckylum0216 commented 2 years ago

Hi,

Trying to compile from source as an embedded library within my project. The system is Windows 11, using MSVC CXX17 and C11 compilers. The build breaks as it is looking for unistd.h a posix file. The stacktrace is as follows:

[ 92%] Building CXX object libs/openal-soft/CMakeFiles/OpenAL.dir/core/rtkit.cpp.obj
rtkit.cpp
D:\Murdoch\ICT397.2022\milestone_two\rfts\libs\openal-soft\core\rtkit.h(47): error C2061: syntax error: identifier 'pid_t'
D:\Murdoch\ICT397.2022\milestone_two\rfts\libs\openal-soft\core\rtkit.h(54): error C2061: syntax error: identifier 'pid_t'
D:\Murdoch\ICT397.2022\milestone_two\rfts\libs\openal-soft\core\rtkit.cpp(41): fatal error C1083: Cannot open include file: 'unistd.h': No such file or directory

I am not quite sure why OpenAL is looking for posix files on my windows system. Is there a workaround through CMake?

Attached are the cmake files used to make the library:

cmake_minimum_required(VERSION 3.15)
project(rfts LANGUAGES C CXX)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_C_STANDARD 11)

set(CMAKE_POLICY_DEFAULT_CMP0054 NEW)

# Assimp bug
set(ASSIMP_BUILD_DRACO OFF CACHE BOOL "..." FORCE)

# Copy build instructions for glad
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/res/cmake/glad/CMakeLists.txt
        DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/libs/glad)

# Copy build instructions for imgui
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/res/cmake/imgui/CMakeLists.txt
        DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/libs/imgui)
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/res/cmake/imgui_backend/CMakeLists.txt
        DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/libs/imgui/backends)

# Copy build instructions for lua
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/res/cmake/lua/CMakeLists.txt
        DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/libs/lua)

# Copy build instructions for stb
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/res/cmake/stb/CMakeLists.txt
        DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/libs/stb)

# cereal settings
set(SKIP_PERFORMANCE_COMPARISON ON CACHE BOOL "Turn off performance comparison" FORCE)

# openal settings
message(STATUS "System: " ${CMAKE_SYSTEM_NAME} " WIN32: " ${WIN32})
set(LIBTYPE STATIC)
set(ALSOFT_EXAMPLES FALSE)
set(WIN32 TRUE)

add_subdirectory(libs)
add_subdirectory(src)
add_subdirectory(tests)
set(librfts lib${PROJECT_NAME})
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/../res DESTINATION ${CMAKE_BINARY_DIR})
add_library(${librfts} STATIC)
add_subdirectory(core)
add_subdirectory(controller)
add_subdirectory(model)
add_subdirectory(view)

message(STATUS "Build mode: " ${CMAKE_BUILD_TYPE})
if (CMAKE_BUILD_TYPE MATCHES "Debug")
    set(DEBUG_POSTFIX "d")
else ()
    set(DEBUG_POSTFIX "")
endif ()

configure_file(${CMAKE_SOURCE_DIR}/libs/assimp/include/assimp/config.h.in
        ${CMAKE_SOURCE_DIR}/libs/assimp/include/assimp/config.h)

set(SDL2_LIBRARY ${CMAKE_CURRENT_SOURCE_DIR}/../res/libs/sdl/SDL2${DEBUG_POSTFIX}.dll)
set(GLAD_LIBRARY ${CMAKE_CURRENT_SOURCE_DIR}/../res/libs/glad/glad${DEBUG_POSTFIX}.dll)
set(pugixml_INCLUDE ${CMAKE_CURRENT_SOURCE_DIR}/../libs/pugixml/src)
set(LuaBridge ${CMAKE_CURRENT_SOURCE_DIR}/../libs/LuaBridge/source)
set(LUA_INCLUDE ${CMAKE_CURRENT_SOURCE_DIR}/../libs/lua)
set(GLM_INCLUDE ${CMAKE_CURRENT_SOURCE_DIR}/../libs/glm)
set(GLFW_INCLUDE ${CMAKE_CURRENT_SOURCE_DIR}/../libs/glfw/include)
set(SDL_INCLUDE ${CMAKE_CURRENT_SOURCE_DIR}/../libs/SDL/include)
set(GLAD_INCLUDE ${CMAKE_BINARY_DIR}/libs/glad/include)
set(ASSIMP_INCLUDE ${CMAKE_CURRENT_SOURCE_DIR}/../libs/assimp/include)
set(STB_INCLUDE ${CMAKE_CURRENT_SOURCE_DIR}/../libs/stb)
set(RP3D_INCLUDE ${CMAKE_CURRENT_SOURCE_DIR}/../libs/reactphysics3d/include)
set(SOL2_INCLUDE ${CMAKE_CURRENT_SOURCE_DIR}/../libs/sol2/include)
set(CEREAL_INCLUDE ${CMAKE_CURRENT_SOURCE_DIR}/../libs/cereal/include)
set(IMGUI_INCLUDE ${CMAKE_CURRENT_SOURCE_DIR}/../libs/imgui)
set(IMGUI_BACK_INCLUDE ${CMAKE_CURRENT_SOURCE_DIR}/../libs/imgui/backends)

file(GLOB_RECURSE RTFS_HDR RELATIVE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/*.hpp)
file(GLOB_RECURSE GLM_HDR ${CMAKE_SOURCE_DIR}/libs/glm/glm/*.hpp)

# assimp settings
set(BUILD_ASSIMP_TOOLS ON)
set(ASSIMP_BUILD_STATIC_LIB ON)
set(ASSIMP_BUILD_TESTS OFF)
set(ASSIMP_BUILD_ASSIMP_VIEW ON)
# bug in assimp library
# https://stackoverflow.com/questions/66286971/trouble-building-assimp-in-visual-studio-from-cmake-subdirectory
set(ASSIMP_BUILD_DRACO OFF CACHE BOOL "..." FORCE)

# SDL settings
set(SDL_STATIC ON CACHE BOOL "" FORCE)
set(SDL_SHARED OFF CACHE BOOL "" FORCE)

# glad settings
set(${library_type} "STATIC")
message(STATUS "glad property: " ${library_type} " " ${SHARED_LIBRARY})

# glfw settings
set(GLFW_BUILD_DOCS OFF CACHE BOOL "" FORCE)
set(GLFW_BUILD_TESTS OFF CACHE BOOL "" FORCE)
set(GLFW_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)

find_package(OpenGL REQUIRED)

message(STATUS "OpenGL: " ${OPENGL_FOUND})

message(STATUS "Binary Directory: " ${CMAKE_BINARY_DIR})

set(INTERFACE_LIBS
        #        LuaBridge
        glm
        OpenGL::GL
        stb
        cereal
        sol2
        )

set(LIBS
        glad
        assimp
        #reactphysics3d
        SDL2-static
        lua
        libufbx
        libimgui
        libimguibackend
        OpenAL
        )

set(EXTERNAL
        )

set(PUB_INCLUDES
        assimp
        ${GLM_INCLUDE}
        ${LUA_INCLUDE}
        ${OPENGL_INCLUDE_DIR}
        ${GLAD_INCLUDE}
        ${RP3D_INCLUDE}
        ${SDL_INCLUDE}
        ${STB_INCLUDE}
        ${SOL2_INCLUDE}
        ${CEREAL_INCLUDE}
        ${IMGUI_INCLUDE}
        ${IMGUI_BACK_INCLUDE}
        )

set(PVT_INCLUDES
        )

set(SYSTEM_INCLUDES

        )

set(SRC
        core
        model
        view
        controller
        )

file(GLOB_RECURSE rtfs_LIBRARY "${CMAKE_BINARY_DIR}/src/*.lib")
file(GLOB_RECURSE EXCLUDE)

foreach (obj ${EXCLUDE})
    message(STATUS "Excluding: " ${obj})
    list(REMOVE_ITEM LIBS ${obj})
endforeach ()

target_include_directories(${librfts} PRIVATE ${SRC} SYSTEM INTERFACE ${INTERFACE_INCLUDES} PUBLIC ${PUB_INCLUDES} PRIVATE ${PVT_INCLUDES})
target_link_libraries(${librfts} INTERFACE ${INTERFACE_LIBS} PUBLIC ${LIBS})

target_compile_options(${librfts} PRIVATE
        $<$<CXX_COMPILER_ID:MSVC>:/W4 /WX>
        $<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wall -Wextra -pedantic -Werror>
        )

add_executable(${PROJECT_NAME} main.cpp)
target_include_directories(${PROJECT_NAME} PRIVATE ${SRC} ${PVT_INCLUDES} PUBLIC ${PUB_INCLUDES})
target_link_libraries(${PROJECT_NAME}   PRIVATE ${librfts} ${EXTERNAL}
                                        PUBLIC ${LIBS} ${STATIC_LIBS}
                                        INTERFACE ${INTERFACE_LIBS})

target_compile_options(${PROJECT_NAME} PRIVATE
        $<$<CXX_COMPILER_ID:MSVC>:/W4 /WX>
        $<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wall -Wextra -pedantic -Werror>
        )

set_target_properties(${PROJECT_NAME} ${librfts} ${STATIC_LIBS} ${LIBS}
        PROPERTIES
        ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/src"
        LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/src"
        RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/src"
        )

foreach (obj ${rtfs_LIBRARY})
    message(STATUS "libs: " ${obj})
    add_custom_command(TARGET ${PROJECT_NAME}
            POST_BUILD
            COMMAND ${CMAKE_COMMAND} -E copy
            ${obj}
            ${CMAKE_BINARY_DIR}/tests/src
            COMMENT "rtfs libs copied!!!")
endforeach ()
kcat commented 2 years ago

For some reason it thinks D-Bus exists on Windows, so is trying to build RTKit support which otherwise expects a Unix-like system. This should be fixed with commit c870e550fa37d10e8a9d7d15ef1d6370d1e0399e, although you can also set ALSOFT_RTKIT=OFF with CMake to disable it on earlier versions.

beckylum0216 commented 2 years ago

Ah cool, the fix worked. Thanks. Closing the issue.