bimg: Restructure bimg*.cmake to be more like bimg*.lua

This commit is contained in:
Sandy Carter
2023-01-07 23:36:58 -05:00
committed by Sandy
parent 422e7cf0f8
commit 03951e805c
16 changed files with 143 additions and 236 deletions

View File

@@ -154,17 +154,7 @@ if(BGFX_INSTALL)
)
if(NOT BGFX_LIBRARY_TYPE MATCHES "SHARED")
install(
TARGETS bimg
bx
astc-encoder
edtaa3
etc1
etc2
iqa
squish
nvtt
pvrtc
tinyexr
TARGETS bimg bx
EXPORT "${TARGETS_EXPORT_NAME}"
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"

View File

@@ -1,24 +0,0 @@
# bgfx.cmake - bgfx building in cmake
# Written in 2017 by Joshua Brookover <joshua.al.brookover@gmail.com>
# To the extent possible under law, the author(s) have dedicated all copyright
# and related and neighboring rights to this software to the public domain
# worldwide. This software is distributed without any warranty.
# You should have received a copy of the CC0 Public Domain Dedication along with
# this software. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
if(TARGET astc-encoder)
return()
endif()
file(GLOB ASTC_ENCODER_SOURCES ${BIMG_DIR}/3rdparty/astc-encoder/source/*.cpp
${BIMG_DIR}/3rdparty/astc-encoder/include/*.h
)
add_library(astc-encoder STATIC ${ASTC_ENCODER_SOURCES})
target_include_directories(
astc-encoder PUBLIC $<BUILD_INTERFACE:${BIMG_DIR}/3rdparty> $<BUILD_INTERFACE:${BIMG_DIR}/3rdparty/astc-encoder>
$<BUILD_INTERFACE:${BIMG_DIR}/3rdparty/astc-encoder/include>
)
set_target_properties(astc-encoder PROPERTIES FOLDER "bgfx/3rdparty")

View File

@@ -1,19 +0,0 @@
# bgfx.cmake - bgfx building in cmake
# Written in 2017 by Joshua Brookover <joshua.al.brookover@gmail.com>
# To the extent possible under law, the author(s) have dedicated all copyright
# and related and neighboring rights to this software to the public domain
# worldwide. This software is distributed without any warranty.
# You should have received a copy of the CC0 Public Domain Dedication along with
# this software. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
if(TARGET edtaa3)
return()
endif()
file(GLOB EDTAA3_SOURCES ${BIMG_DIR}/3rdparty/edtaa3/*.cpp ${BIMG_DIR}/3rdparty/edtaa3/*.h)
add_library(edtaa3 STATIC ${EDTAA3_SOURCES})
target_include_directories(edtaa3 PUBLIC $<BUILD_INTERFACE:${BIMG_DIR}/3rdparty>)
set_target_properties(edtaa3 PROPERTIES FOLDER "bgfx/3rdparty" PREFIX "${CMAKE_STATIC_LIBRARY_PREFIX}bgfx-")

View File

@@ -1,19 +0,0 @@
# bgfx.cmake - bgfx building in cmake
# Written in 2017 by Joshua Brookover <joshua.al.brookover@gmail.com>
# To the extent possible under law, the author(s) have dedicated all copyright
# and related and neighboring rights to this software to the public domain
# worldwide. This software is distributed without any warranty.
# You should have received a copy of the CC0 Public Domain Dedication along with
# this software. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
if(TARGET etc1)
return()
endif()
file(GLOB ETC1_SOURCES ${BIMG_DIR}/3rdparty/etc1/*.cpp ${BIMG_DIR}/3rdparty/etc1/*.h)
add_library(etc1 STATIC ${ETC1_SOURCES})
target_include_directories(etc1 PUBLIC $<BUILD_INTERFACE:${BIMG_DIR}/3rdparty>)
set_target_properties(etc1 PROPERTIES FOLDER "bgfx/3rdparty" PREFIX "${CMAKE_STATIC_LIBRARY_PREFIX}bgfx-")

View File

@@ -1,20 +0,0 @@
# bgfx.cmake - bgfx building in cmake
# Written in 2017 by Joshua Brookover <joshua.al.brookover@gmail.com>
# To the extent possible under law, the author(s) have dedicated all copyright
# and related and neighboring rights to this software to the public domain
# worldwide. This software is distributed without any warranty.
# You should have received a copy of the CC0 Public Domain Dedication along with
# this software. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
if(TARGET etc2)
return()
endif()
file(GLOB ETC2_SOURCES ${BIMG_DIR}/3rdparty/etc2/*.cpp ${BIMG_DIR}/3rdparty/etc2/*.h)
add_library(etc2 STATIC ${ETC2_SOURCES})
target_include_directories(etc2 PUBLIC $<BUILD_INTERFACE:${BIMG_DIR}/3rdparty>)
target_link_libraries(etc2 PUBLIC bx)
set_target_properties(etc2 PROPERTIES FOLDER "bgfx/3rdparty" PREFIX "${CMAKE_STATIC_LIBRARY_PREFIX}bgfx-")

View File

@@ -1,19 +0,0 @@
# bgfx.cmake - bgfx building in cmake
# Written in 2017 by Joshua Brookover <joshua.al.brookover@gmail.com>
# To the extent possible under law, the author(s) have dedicated all copyright
# and related and neighboring rights to this software to the public domain
# worldwide. This software is distributed without any warranty.
# You should have received a copy of the CC0 Public Domain Dedication along with
# this software. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
if(TARGET iqa)
return()
endif()
file(GLOB IQA_SOURCES ${BIMG_DIR}/3rdparty/iqa/source/*.c ${BIMG_DIR}/3rdparty/iqa/include/*.h)
add_library(iqa STATIC ${IQA_SOURCES})
target_include_directories(iqa PUBLIC $<BUILD_INTERFACE:${BIMG_DIR}/3rdparty/iqa/include>)
set_target_properties(iqa PROPERTIES FOLDER "bgfx/3rdparty" PREFIX "${CMAKE_STATIC_LIBRARY_PREFIX}bgfx-")

View File

@@ -1,21 +0,0 @@
# bgfx.cmake - bgfx building in cmake
# Written in 2017 by Joshua Brookover <joshua.al.brookover@gmail.com>
# To the extent possible under law, the author(s) have dedicated all copyright
# and related and neighboring rights to this software to the public domain
# worldwide. This software is distributed without any warranty.
# You should have received a copy of the CC0 Public Domain Dedication along with
# this software. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
if(TARGET squish)
return()
endif()
file(GLOB SQUISH_SOURCES ${BIMG_DIR}/3rdparty/libsquish/*.cpp ${BIMG_DIR}/3rdparty/libsquish/*.h
${BIMG_DIR}/3rdparty/libsquish/*.inl
)
add_library(squish STATIC ${SQUISH_SOURCES})
target_include_directories(squish PUBLIC $<BUILD_INTERFACE:${BIMG_DIR}/3rdparty>)
set_target_properties(squish PROPERTIES FOLDER "bgfx/3rdparty" PREFIX "${CMAKE_STATIC_LIBRARY_PREFIX}bgfx-")

View File

@@ -1,35 +0,0 @@
# bgfx.cmake - bgfx building in cmake
# Written in 2017 by Joshua Brookover <joshua.al.brookover@gmail.com>
# To the extent possible under law, the author(s) have dedicated all copyright
# and related and neighboring rights to this software to the public domain
# worldwide. This software is distributed without any warranty.
# You should have received a copy of the CC0 Public Domain Dedication along with
# this software. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
if(TARGET nvtt)
return()
endif()
file(
GLOB
NVTT_SOURCES
${BIMG_DIR}/3rdparty/nvtt/bc6h/*.cpp
${BIMG_DIR}/3rdparty/nvtt/bc6h/*.h
${BIMG_DIR}/3rdparty/nvtt/bc7/*.cpp
${BIMG_DIR}/3rdparty/nvtt/bc7/*.h
${BIMG_DIR}/3rdparty/nvtt/nvcore/*.h
${BIMG_DIR}/3rdparty/nvtt/nvcore/*.inl
${BIMG_DIR}/3rdparty/nvtt/nvmath/*.cpp
${BIMG_DIR}/3rdparty/nvtt/nvmath/*.h
${BIMG_DIR}/3rdparty/nvtt/*.cpp
${BIMG_DIR}/3rdparty/nvtt/*.h
)
add_library(nvtt STATIC ${NVTT_SOURCES})
target_include_directories(
nvtt PUBLIC $<BUILD_INTERFACE:${BIMG_DIR}/3rdparty> $<BUILD_INTERFACE:${BIMG_DIR}/3rdparty/nvtt>
)
target_link_libraries(nvtt PUBLIC bx)
set_target_properties(nvtt PROPERTIES FOLDER "bgfx/3rdparty" PREFIX "${CMAKE_STATIC_LIBRARY_PREFIX}bgfx-")

View File

@@ -1,19 +0,0 @@
# bgfx.cmake - bgfx building in cmake
# Written in 2017 by Joshua Brookover <joshua.al.brookover@gmail.com>
# To the extent possible under law, the author(s) have dedicated all copyright
# and related and neighboring rights to this software to the public domain
# worldwide. This software is distributed without any warranty.
# You should have received a copy of the CC0 Public Domain Dedication along with
# this software. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
if(TARGET pvrtc)
return()
endif()
file(GLOB PVRTC_SOURCES ${BIMG_DIR}/3rdparty/pvrtc/*.cpp ${BIMG_DIR}/3rdparty/pvrtc/*.h)
add_library(pvrtc STATIC ${PVRTC_SOURCES})
target_include_directories(pvrtc PUBLIC $<BUILD_INTERFACE:${BIMG_DIR}/3rdparty>)
set_target_properties(pvrtc PROPERTIES FOLDER "bgfx/3rdparty" PREFIX "${CMAKE_STATIC_LIBRARY_PREFIX}bgfx-")

View File

@@ -1,11 +0,0 @@
if(TARGET tinyexr)
return()
endif()
file(GLOB_RECURSE TINYEXR_SOURCES ${BIMG_DIR}/3rdparty/tinyexr/*.c ${BIMG_DIR}/3rdparty/tinyexr/*.h)
add_library(tinyexr STATIC ${TINYEXR_SOURCES})
target_include_directories(
tinyexr PUBLIC $<BUILD_INTERFACE:${BIMG_DIR}/3rdparty> $<BUILD_INTERFACE:${BIMG_DIR}/3rdparty/tinyexr/deps/miniz>
)
set_target_properties(tinyexr PROPERTIES FOLDER "bgfx/3rdparty" PREFIX "${CMAKE_STATIC_LIBRARY_PREFIX}bgfx-")

View File

@@ -9,3 +9,5 @@
# this software. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
include(bimg.cmake)
include(bimg_decode.cmake)
include(bimg_encode.cmake)

View File

@@ -8,48 +8,36 @@
# You should have received a copy of the CC0 Public Domain Dedication along with
# this software. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
# Third party libs
include(${CMAKE_CURRENT_LIST_DIR}/../3rdparty/astc-encoder.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/../3rdparty/edtaa3.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/../3rdparty/etc1.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/../3rdparty/etc2.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/../3rdparty/iqa.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/../3rdparty/libsquish.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/../3rdparty/nvtt.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/../3rdparty/pvrtc.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/../3rdparty/tinyexr.cmake)
# Ensure the directory exists
if(NOT IS_DIRECTORY ${BIMG_DIR})
message(SEND_ERROR "Could not load bimg, directory does not exist. ${BIMG_DIR}")
return()
endif()
# Grab the bimg source files
file(GLOB BIMG_SOURCES ${BIMG_DIR}/src/*.cpp)
# Create the bimg target
add_library(bimg STATIC ${BIMG_SOURCES})
# Add include directory of bimg
target_include_directories(
bimg PUBLIC $<BUILD_INTERFACE:${BIMG_DIR}/include> $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)
# bimg dependencies
target_link_libraries(
bimg
PUBLIC bx
PRIVATE astc-encoder
edtaa3
etc1
etc2
iqa
squish
nvtt
pvrtc
tinyexr
)
add_library(bimg STATIC)
# Put in a "bgfx" folder in Visual Studio
set_target_properties(bimg PROPERTIES FOLDER "bgfx")
target_include_directories(
bimg PUBLIC $<BUILD_INTERFACE:${BIMG_DIR}/include>$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
PRIVATE ${BIMG_DIR}/3rdparty/astc-encoder/include #
${BIMG_DIR}/3rdparty/tinyexr/deps/miniz #
)
file(
GLOB_RECURSE
BIMG_SOURCES
${BIMG_DIR}/include/* #
${BIMG_DIR}/src/image.* #
${BIMG_DIR}/src/image_gnf.cpp #
#
${BIMG_DIR}/3rdparty/astc-encoder/source/*.cpp #
${BIMG_DIR}/3rdparty/astc-encoder/source/*.h #
#
${BIMG_DIR}/3rdparty/tinyexr/deps/miniz/miniz.* #
)
target_sources(bimg PRIVATE ${BIMG_SOURCES})
target_link_libraries(bimg PUBLIC bx)

View File

@@ -0,0 +1,37 @@
# bgfx.cmake - bgfx building in cmake
# Written in 2017 by Joshua Brookover <joshua.al.brookover@gmail.com>
#
# To the extent possible under law, the author(s) have dedicated all copyright
# and related and neighboring rights to this software to the public domain
# worldwide. This software is distributed without any warranty.
#
# You should have received a copy of the CC0 Public Domain Dedication along with
# this software. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
# Ensure the directory exists
if(NOT IS_DIRECTORY ${BIMG_DIR})
message(SEND_ERROR "Could not load bimg_decode, directory does not exist. ${BIMG_DIR}")
return()
endif()
add_library(bimg_decode STATIC)
# Put in a "bgfx" folder in Visual Studio
set_target_properties(bimg_decode PROPERTIES FOLDER "bgfx")
target_include_directories(
bimg_decode PUBLIC $<BUILD_INTERFACE:${BIMG_DIR}/include> $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
PRIVATE ${BIMG_DIR}/3rdparty #
${BIMG_DIR}/3rdparty/tinyexr/deps/miniz #
)
file(GLOB_RECURSE BIMG_DECODE_SOURCES #
${BIMG_DIR}/include/* #
${BIMG_DIR}/src/image_decode.* #
#
${BIMG_DIR}/3rdparty/tinyexr/deps/miniz/miniz.* #
)
target_sources(bimg_decode PRIVATE ${BIMG_DECODE_SOURCES})
target_link_libraries(bimg_decode PUBLIC bx)

View File

@@ -0,0 +1,77 @@
# bgfx.cmake - bgfx building in cmake
# Written in 2017 by Joshua Brookover <joshua.al.brookover@gmail.com>
#
# To the extent possible under law, the author(s) have dedicated all copyright
# and related and neighboring rights to this software to the public domain
# worldwide. This software is distributed without any warranty.
#
# You should have received a copy of the CC0 Public Domain Dedication along with
# this software. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
# Ensure the directory exists
if(NOT IS_DIRECTORY ${BIMG_DIR})
message(SEND_ERROR "Could not load bimg_encode, directory does not exist. ${BIMG_DIR}")
return()
endif()
add_library(bimg_encode STATIC)
# Put in a "bgfx" folder in Visual Studio
set_target_properties(bimg_encode PROPERTIES FOLDER "bgfx")
target_include_directories(
bimg_encode
PUBLIC $<BUILD_INTERFACE:${BIMG_DIR}/include> $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
PRIVATE ${BIMG_DIR}/3rdparty #
${BIMG_DIR}/3rdparty/astc-encoder/include #
${BIMG_DIR}/3rdparty/iqa/include #
${BIMG_DIR}/3rdparty/nvtt #
${BIMG_DIR}/3rdparty/tinyexr/deps/miniz #
)
file(
GLOB_RECURSE
BIMG_ENCODE_SOURCES
${BIMG_DIR}/include/* #
${BIMG_DIR}/src/image_encode.* #
${BIMG_DIR}/src/image_cubemap_filter.* #
${BIMG_DIR}/3rdparty/libsquish/**.cpp #
${BIMG_DIR}/3rdparty/libsquish/**.h #
${BIMG_DIR}/3rdparty/edtaa3/**.cpp #
${BIMG_DIR}/3rdparty/edtaa3/**.h #
${BIMG_DIR}/3rdparty/etc1/**.cpp #
${BIMG_DIR}/3rdparty/etc1/**.h #
${BIMG_DIR}/3rdparty/etc2/**.cpp #
${BIMG_DIR}/3rdparty/etc2/**.hpp #
${BIMG_DIR}/3rdparty/nvtt/**.cpp #
${BIMG_DIR}/3rdparty/nvtt/**.h #
${BIMG_DIR}/3rdparty/pvrtc/**.cpp #
${BIMG_DIR}/3rdparty/pvrtc/**.h #
${BIMG_DIR}/3rdparty/tinyexr/**.h #
${BIMG_DIR}/3rdparty/iqa/include/**.h #
${BIMG_DIR}/3rdparty/iqa/source/**.c #
)
target_sources(bimg_encode PRIVATE ${BIMG_ENCODE_SOURCES})
target_link_libraries(bimg_encode PUBLIC bx)
include(CheckCXXCompilerFlag)
foreach(flag "-Wno-implicit-fallthrough" "-Wno-shadow" "-Wno-shift-negative-value" "-Wno-undef")
check_cxx_compiler_flag(${flag} flag_supported)
if(flag_supported)
target_compile_options(bimg_encode PRIVATE ${flag})
endif()
endforeach()
foreach(flag "-Wno-class-memaccess" "-Wno-deprecated-copy")
check_cxx_compiler_flag(${flag} flag_supported)
if(flag_supported)
foreach(file ${BIMG_ENCODE_SOURCES})
get_source_file_property(lang ${file} LANGUAGE)
if(lang STREQUAL "CXX")
set_source_files_properties(${file} PROPERTIES COMPILE_OPTIONS ${flag})
endif()
endforeach()
endif()
endforeach()

View File

@@ -146,7 +146,7 @@ function(add_example ARG_NAME)
if(ARG_COMMON)
add_library(example-${ARG_NAME} STATIC EXCLUDE_FROM_ALL ${SOURCES})
target_include_directories(example-${ARG_NAME} PUBLIC ${BGFX_DIR}/examples/common)
target_link_libraries(example-${ARG_NAME} PUBLIC bgfx bx bimg dear-imgui meshoptimizer)
target_link_libraries(example-${ARG_NAME} PUBLIC bgfx bx bimg bimg_decode dear-imgui meshoptimizer)
if(BGFX_WITH_GLFW)
find_package(glfw3 REQUIRED)
target_link_libraries(example-${ARG_NAME} PUBLIC glfw)

View File

@@ -12,7 +12,7 @@ include(CMakeParseArguments)
add_executable(texturec ${BIMG_DIR}/tools/texturec/texturec.cpp)
set_target_properties(texturec PROPERTIES FOLDER "bgfx/tools")
target_link_libraries(texturec bimg)
target_link_libraries(texturec PRIVATE bimg_decode bimg_encode bimg)
if(BGFX_CUSTOM_TARGETS)
add_dependencies(tools texturec)
endif()