2021-08-19 15:09:30 +01:00
|
|
|
set(librw_MAINPROJECT ON)
|
|
|
|
if(DEFINED PROJECT_NAME)
|
|
|
|
set(librw_MAINPROJECT OFF)
|
|
|
|
endif()
|
|
|
|
|
2020-10-26 23:41:07 +00:00
|
|
|
cmake_minimum_required(VERSION 3.8)
|
2021-06-17 22:44:07 +01:00
|
|
|
project(librw
|
|
|
|
VERSION 0.0.1
|
|
|
|
LANGUAGES C CXX
|
|
|
|
)
|
|
|
|
set(librw_AUTHOR aap)
|
2020-10-26 23:41:07 +00:00
|
|
|
|
2020-11-30 19:22:18 +00:00
|
|
|
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
|
|
|
|
|
2020-10-26 23:41:07 +00:00
|
|
|
if(WIN32)
|
|
|
|
set(LIBRW_PLATFORMS "NULL" "GL3" "D3D9")
|
2021-06-17 22:44:07 +01:00
|
|
|
set(LIBRW_PLATFORM_GL3_REQUIRES_OPENGL ON)
|
|
|
|
elseif(NINTENDO_SWITCH)
|
|
|
|
set(LIBRW_PLATFORMS "NULL" "GL3")
|
|
|
|
set(LIBRW_PLATFORM_GL3_REQUIRES_OPENGL OFF)
|
2021-06-22 20:17:05 +01:00
|
|
|
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake/nx")
|
2021-06-22 18:47:36 +01:00
|
|
|
include(NXFunctions)
|
2021-06-22 20:17:05 +01:00
|
|
|
elseif(PS2)
|
2021-07-09 18:32:45 +01:00
|
|
|
set(LIBRW_PLATFORMS "PS2")
|
2021-06-22 20:17:05 +01:00
|
|
|
set(LIBRW_PLATFORM_GL3_REQUIRES_OPENGL OFF)
|
|
|
|
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake/ps2")
|
|
|
|
include(PS2Functions)
|
2020-10-26 23:41:07 +00:00
|
|
|
else()
|
2021-06-22 20:17:05 +01:00
|
|
|
set(LIBRW_PLATFORMS "NULL" "GL3")
|
2021-06-17 22:44:07 +01:00
|
|
|
set(LIBRW_PLATFORM_GL3_REQUIRES_OPENGL ON)
|
2020-10-26 23:41:07 +00:00
|
|
|
endif()
|
2021-07-09 18:32:45 +01:00
|
|
|
list(GET LIBRW_PLATFORMS 0 LIBRW_PLATFORM_DEFAULT)
|
|
|
|
set(LIBRW_PLATFORM "${LIBRW_PLATFORM_DEFAULT}" CACHE STRING "Platform")
|
2020-10-26 23:41:07 +00:00
|
|
|
set_property(CACHE LIBRW_PLATFORM PROPERTY STRINGS ${LIBRW_PLATFORMS})
|
|
|
|
message(STATUS "LIBRW_PLATFORM = ${LIBRW_PLATFORM} (choices=${LIBRW_PLATFORMS})")
|
|
|
|
set("LIBRW_PLATFORM_${LIBRW_PLATFORM}" ON)
|
|
|
|
if(NOT LIBRW_PLATFORM IN_LIST LIBRW_PLATFORMS)
|
|
|
|
message(FATAL_ERROR "Illegal LIBRW_PLATFORM=${LIBRW_PLATFORM}")
|
|
|
|
endif()
|
|
|
|
|
2023-01-05 18:42:46 +00:00
|
|
|
set(LIBRW_GL3_GFXLIBS "GLFW" "SDL2" "EXTGL3")
|
2020-11-30 19:22:18 +00:00
|
|
|
set(LIBRW_GL3_GFXLIB "GLFW" CACHE STRING "gfxlib for gl3")
|
|
|
|
set_property(CACHE LIBRW_GL3_GFXLIB PROPERTY STRINGS ${LIBRW_GL3_GFXLIBS})
|
|
|
|
if(LIBRW_PLATFORM_GL3)
|
|
|
|
message(STATUS "LIBRW_GL3_GFXLIB = ${LIBRW_GL3_GFXLIB} (choices=${LIBRW_GL3_GFXLIBS})")
|
|
|
|
endif()
|
|
|
|
if(NOT LIBRW_GL3_GFXLIB IN_LIST LIBRW_GL3_GFXLIBS)
|
|
|
|
message(FATAL_ERROR "Illegal LIBRW_GL3_GFXLIB=${LIBRW_GL3_GFXLIB}")
|
|
|
|
endif()
|
|
|
|
|
2020-10-26 23:41:07 +00:00
|
|
|
if(LIBRW_PLATFORM_PS2)
|
|
|
|
enable_language(DSM)
|
|
|
|
endif()
|
|
|
|
|
2021-06-22 18:47:36 +01:00
|
|
|
if(NOT COMMAND librw_platform_target)
|
|
|
|
function(librw_platform_target)
|
|
|
|
endfunction()
|
|
|
|
endif()
|
|
|
|
|
2021-06-22 21:51:20 +01:00
|
|
|
include(CMakeDependentOption)
|
|
|
|
|
2021-08-19 15:09:30 +01:00
|
|
|
option(LIBRW_TOOLS "Build librw tools" ${librw_MAINPROJECT})
|
|
|
|
option(LIBRW_INSTALL "Install librw files" ${librw_MAINPROJECT})
|
2021-07-09 18:32:45 +01:00
|
|
|
cmake_dependent_option(LIBRW_EXAMPLES "Build librw examples" ON "LIBRW_TOOLS;NOT LIBRW_PLATFORM_NULL" OFF)
|
2020-10-26 23:41:07 +00:00
|
|
|
|
|
|
|
if(LIBRW_INSTALL)
|
|
|
|
include(GNUInstallDirs)
|
|
|
|
set(LIBRW_INSTALL_INCLUDEDIR "${CMAKE_INSTALL_INCLUDEDIR}/librw")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
add_subdirectory(src)
|
|
|
|
|
2021-08-19 15:36:00 +01:00
|
|
|
if(LIBRW_TOOLS AND NOT LIBRW_PLATFORM_PS2 AND NOT LIBRW_PLATFORM_NULL)
|
2020-10-26 23:41:07 +00:00
|
|
|
add_subdirectory(skeleton)
|
|
|
|
endif()
|
|
|
|
|
2021-06-22 21:51:20 +01:00
|
|
|
add_subdirectory(tools)
|
|
|
|
|
2020-10-26 23:41:07 +00:00
|
|
|
if(LIBRW_INSTALL)
|
|
|
|
include(CMakePackageConfigHelpers)
|
2020-11-30 19:22:18 +00:00
|
|
|
configure_package_config_file(cmake/librw-config.cmake.in librw-config.cmake
|
2020-10-26 23:41:07 +00:00
|
|
|
INSTALL_DESTINATION "${CMAKE_INSTALL_PREFIX}"
|
2020-12-03 17:11:55 +00:00
|
|
|
)
|
2020-10-26 23:41:07 +00:00
|
|
|
install(
|
|
|
|
FILES "${CMAKE_CURRENT_BINARY_DIR}/librw-config.cmake"
|
|
|
|
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}"
|
2020-12-03 17:11:55 +00:00
|
|
|
)
|
2020-10-26 23:41:07 +00:00
|
|
|
install(
|
2020-11-30 18:26:09 +00:00
|
|
|
EXPORT librw-targets NAMESPACE librw::
|
2020-10-27 00:26:26 +00:00
|
|
|
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}"
|
2020-12-03 17:11:55 +00:00
|
|
|
)
|
2021-01-02 19:43:34 +00:00
|
|
|
|
2021-06-17 22:44:07 +01:00
|
|
|
if(LIBRW_GL3_GFXLIB STREQUAL "SDL2")
|
|
|
|
install(
|
|
|
|
FILES "${CMAKE_CURRENT_LIST_DIR}/cmake/FindSDL2.cmake"
|
|
|
|
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake"
|
|
|
|
)
|
|
|
|
endif()
|
|
|
|
|
2021-01-02 19:43:34 +00:00
|
|
|
string(REPLACE "." ";" cmake_c_compiler_version_list "${CMAKE_C_COMPILER_VERSION}")
|
|
|
|
list(GET cmake_c_compiler_version_list 0 cmake_c_compiler_version_major)
|
|
|
|
|
|
|
|
string(TOLOWER "${LIBRW_PLATFORM}" librw_platform)
|
|
|
|
set(compiler)
|
|
|
|
set(os)
|
|
|
|
if(NOT LIBRW_PLATFORM STREQUAL "PS2")
|
|
|
|
if(MSVC)
|
|
|
|
set(compiler "-msvc${MSVC_VERSION}")
|
|
|
|
elseif(CMAKE_C_COMPILER_ID STREQUAL "GNU")
|
|
|
|
set(compiler "-gcc${cmake_c_compiler_version_major}")
|
|
|
|
elseif(CMAKE_C_COMPILER_ID STREQUAL "Clang")
|
|
|
|
set(compiler "-clang${cmake_c_compiler_version_major}")
|
|
|
|
elseif(CMAKE_C_COMPILER_ID STREQUAL "AppleClang")
|
|
|
|
set(compiler "-appleclang${cmake_c_compiler_version_major}")
|
|
|
|
else()
|
|
|
|
set(compiler "-UNK")
|
|
|
|
message(WARNING "Unknown compiler. Created cpack package will be wrong. (override using cpack -P)")
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
if(LIBRW_PLATFORM_NULL)
|
|
|
|
set(platform "-null")
|
|
|
|
elseif(LIBRW_PLATFORM_PS2)
|
|
|
|
set(platform "-ps2")
|
|
|
|
elseif(LIBRW_PLATFORM_GL3)
|
|
|
|
if(LIBRW_GL3_GFXLIB STREQUAL "GLFW")
|
|
|
|
set(platform "-gl3-glfw")
|
2023-01-05 18:42:46 +00:00
|
|
|
elseif(LIBRW_GL3_GFXLIB STREQUAL "EXTGL3")
|
|
|
|
set(platform "-gl3-extgl3")
|
2021-01-02 19:43:34 +00:00
|
|
|
else()
|
|
|
|
set(platform "-gl3-sdl2")
|
|
|
|
endif()
|
|
|
|
elseif(LIBRW_PLATFORM_D3D9)
|
|
|
|
set(platform "-d3d9")
|
|
|
|
endif()
|
|
|
|
if(NOT LIBRW_PLATFORM_PS2)
|
|
|
|
if(WIN32)
|
|
|
|
set(os "-win")
|
2021-07-09 18:32:45 +01:00
|
|
|
elseif(NINTENDO_SWITCH)
|
|
|
|
set(os "-switch")
|
|
|
|
elseif(PS2)
|
|
|
|
set(os "-ps2")
|
2021-01-02 19:43:34 +00:00
|
|
|
elseif(APPLE)
|
|
|
|
set(os "-apple")
|
|
|
|
elseif(UNIX)
|
|
|
|
set(os "-linux")
|
|
|
|
else()
|
|
|
|
set(compiler "-UNK")
|
|
|
|
message(WARNING "Unknown os. Created cpack package will be wrong. (override using cpack -P)")
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
|
|
|
set(CPACK_PACKAGE_NAME "${PROJECT_NAME}${platform}${os}${compiler}")
|
2020-11-30 18:26:09 +00:00
|
|
|
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "A (partial) re-implementation of RenderWare Graphics")
|
|
|
|
set(CPACK_PACKAGE_VENDOR "aap")
|
|
|
|
set(CPACK_PACKAGE_DESCRIPTION_FILE "${PROJECT_SOURCE_DIR}/LICENSE")
|
|
|
|
set(CPACK_RESOURCE_FILE_LICENSE "${PROJECT_SOURCE_DIR}/LICENSE")
|
|
|
|
set(CPACK_PACKAGE_INSTALL_DIRECTORY "${CPACK_PACKAGE_NAME}")
|
|
|
|
set(CPACK_SOURCE_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}")
|
|
|
|
set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}")
|
2021-01-02 19:43:34 +00:00
|
|
|
set(CPACK_GENERATOR "TXZ")
|
2020-11-30 18:26:09 +00:00
|
|
|
include(CPack)
|
2020-10-26 23:41:07 +00:00
|
|
|
endif()
|