actualitzat cmake
This commit is contained in:
128
CMakeLists.txt
128
CMakeLists.txt
@@ -4,40 +4,140 @@ project(shadertoy_sdl3 LANGUAGES C CXX)
|
|||||||
set(CMAKE_CXX_STANDARD 17)
|
set(CMAKE_CXX_STANDARD 17)
|
||||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||||
|
|
||||||
if(NOT CMAKE_BUILD_TYPE)
|
# Default to Release for single-config generators when none specified
|
||||||
set(CMAKE_BUILD_TYPE Release)
|
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
|
||||||
|
set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type" FORCE)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
find_package(SDL3 REQUIRED)
|
# Paths
|
||||||
|
|
||||||
# comprobaremos que glad.c existe y lo añadimos
|
|
||||||
set(GLAD_SRC "${CMAKE_CURRENT_SOURCE_DIR}/third_party/glad/src/glad.c")
|
set(GLAD_SRC "${CMAKE_CURRENT_SOURCE_DIR}/third_party/glad/src/glad.c")
|
||||||
if(NOT EXISTS "${GLAD_SRC}")
|
if(NOT EXISTS "${GLAD_SRC}")
|
||||||
message(FATAL_ERROR "glad.c no encontrado en: ${GLAD_SRC}")
|
message(FATAL_ERROR "glad.c no encontrado en: ${GLAD_SRC}")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
# glad library
|
||||||
add_library(glad_src STATIC "${GLAD_SRC}")
|
add_library(glad_src STATIC "${GLAD_SRC}")
|
||||||
target_include_directories(glad_src PUBLIC
|
target_include_directories(glad_src PUBLIC
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/third_party/glad/include
|
${CMAKE_CURRENT_SOURCE_DIR}/third_party/glad/include
|
||||||
)
|
)
|
||||||
# forzar el lenguaje de enlace a C para evitar ambigüedades
|
|
||||||
set_target_properties(glad_src PROPERTIES LINKER_LANGUAGE C)
|
set_target_properties(glad_src PROPERTIES LINKER_LANGUAGE C)
|
||||||
|
|
||||||
|
# Executable
|
||||||
add_executable(shadertoy_sdl3
|
add_executable(shadertoy_sdl3
|
||||||
src/main.cpp
|
src/main.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
target_link_libraries(shadertoy_sdl3 PRIVATE glad_src SDL3::SDL3)
|
|
||||||
target_include_directories(shadertoy_sdl3 PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/third_party/glad/include)
|
target_include_directories(shadertoy_sdl3 PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/third_party/glad/include)
|
||||||
|
|
||||||
if (WIN32)
|
# SDL3
|
||||||
|
find_package(SDL3 REQUIRED)
|
||||||
|
target_link_libraries(shadertoy_sdl3 PRIVATE glad_src SDL3::SDL3)
|
||||||
|
|
||||||
|
# Platform-specific flags and linkers (try to mimic your Makefile)
|
||||||
|
if(WIN32)
|
||||||
|
target_compile_definitions(shadertoy_sdl3 PRIVATE WINDOWS_BUILD)
|
||||||
|
if(MSVC)
|
||||||
|
# MSVC: reasonable defaults; adjust as needed
|
||||||
|
target_compile_options(shadertoy_sdl3 PRIVATE /W3 /permissive-)
|
||||||
|
# Link to system libraries (MSVC uses system libs automatically for system includes)
|
||||||
target_link_libraries(shadertoy_sdl3 PRIVATE opengl32)
|
target_link_libraries(shadertoy_sdl3 PRIVATE opengl32)
|
||||||
elseif(APPLE)
|
else()
|
||||||
find_library(COCOA_LIBRARY Cocoa)
|
# MinGW / GNU on Windows
|
||||||
find_library(IOKIT_LIBRARY IOKit)
|
target_compile_options(shadertoy_sdl3 PRIVATE -std=c++17 -Wall -Os -ffunction-sections -fdata-sections)
|
||||||
find_library(CORE_VIDEO_LIBRARY CoreVideo)
|
target_link_options(shadertoy_sdl3 PRIVATE "-Wl,--gc-sections" "-Wl,-Bstatic" "-Wl,-Bdynamic")
|
||||||
target_link_libraries(shadertoy_sdl3 PRIVATE ${COCOA_LIBRARY} ${IOKIT_LIBRARY} ${CORE_VIDEO_LIBRARY})
|
target_link_libraries(shadertoy_sdl3 PRIVATE -lmingw32 -lws2_32 -lSDL3 -lopengl32)
|
||||||
|
endif()
|
||||||
else()
|
else()
|
||||||
|
# POSIX platforms
|
||||||
|
target_compile_options(shadertoy_sdl3 PRIVATE -std=c++17 -Wall -Os)
|
||||||
|
if(APPLE)
|
||||||
|
find_library(COCOA_LIBRARY Cocoa REQUIRED)
|
||||||
|
find_library(IOKIT_LIBRARY IOKit REQUIRED)
|
||||||
|
find_library(CORE_VIDEO_LIBRARY CoreVideo REQUIRED)
|
||||||
|
target_link_libraries(shadertoy_sdl3 PRIVATE ${COCOA_LIBRARY} ${IOKIT_LIBRARY} ${CORE_VIDEO_LIBRARY})
|
||||||
|
target_compile_options(shadertoy_sdl3 PRIVATE -arch arm64)
|
||||||
|
else()
|
||||||
find_package(OpenGL REQUIRED)
|
find_package(OpenGL REQUIRED)
|
||||||
target_link_libraries(shadertoy_sdl3 PRIVATE OpenGL::GL)
|
target_link_libraries(shadertoy_sdl3 PRIVATE OpenGL::GL)
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Ensure RUNTIME output directory for single-config builds (Release/Debug)
|
||||||
|
set_target_properties(shadertoy_sdl3 PROPERTIES
|
||||||
|
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
|
||||||
|
RUNTIME_OUTPUT_DIRECTORY_RELEASE "${CMAKE_BINARY_DIR}/bin/Release"
|
||||||
|
RUNTIME_OUTPUT_DIRECTORY_DEBUG "${CMAKE_BINARY_DIR}/bin/Debug"
|
||||||
|
)
|
||||||
|
|
||||||
|
if(WIN32)
|
||||||
|
set(RELEASE_DIR "${CMAKE_BINARY_DIR}/release_package")
|
||||||
|
set(WINDOWS_ZIP "${CMAKE_BINARY_DIR}/${PROJECT_NAME}-${CMAKE_SYSTEM_PROCESSOR}-win.zip")
|
||||||
|
set(DLL_SOURCE_DIR "${CMAKE_SOURCE_DIR}/release") # coloca tus SDL3.dll aquí
|
||||||
|
|
||||||
|
# PowerShell script que realizará las copias y el ZIP de forma robusta.
|
||||||
|
set(PS_SCRIPT "${CMAKE_BINARY_DIR}/package_windows.ps1")
|
||||||
|
file(WRITE "${PS_SCRIPT}"
|
||||||
|
"param(\n"
|
||||||
|
" [string]\$srcExe,\n"
|
||||||
|
" [string]\$releaseDir,\n"
|
||||||
|
" [string]\$readme,\n"
|
||||||
|
" [string]\$license,\n"
|
||||||
|
" [string]\$shadersDir,\n"
|
||||||
|
" [string]\$dllDir,\n"
|
||||||
|
" [string]\$outZip\n"
|
||||||
|
")\n"
|
||||||
|
"\n"
|
||||||
|
"# Remove old\n"
|
||||||
|
"if (Test-Path \$releaseDir) { Remove-Item -Recurse -Force \$releaseDir }\n"
|
||||||
|
"New-Item -ItemType Directory -Path \$releaseDir | Out-Null\n"
|
||||||
|
"\n"
|
||||||
|
"# Copy exe\n"
|
||||||
|
"Write-Host 'Copying executable...'\n"
|
||||||
|
"Copy-Item -Path \$srcExe -Destination (Join-Path \$releaseDir (Split-Path \$srcExe -Leaf)) -Force\n"
|
||||||
|
"\n"
|
||||||
|
"# Copy README / LICENSE if exist\n"
|
||||||
|
"if (Test-Path \$readme) { Copy-Item -Path \$readme -Destination (Join-Path \$releaseDir 'README.md') -Force }\n"
|
||||||
|
"if (Test-Path \$license) { Copy-Item -Path \$license -Destination (Join-Path \$releaseDir 'LICENSE') -Force }\n"
|
||||||
|
"\n"
|
||||||
|
"# Copy shaders if present\n"
|
||||||
|
"if (Test-Path \$shadersDir) { Copy-Item -Path (Join-Path \$shadersDir '*') -Destination (Join-Path \$releaseDir 'shaders') -Recurse -Force }\n"
|
||||||
|
"\n"
|
||||||
|
"# Copy DLLs if present\n"
|
||||||
|
"if (Test-Path \$dllDir) { Copy-Item -Path (Join-Path \$dllDir '*') -Destination (Join-Path \$releaseDir 'release') -Recurse -Force }\n"
|
||||||
|
"\n"
|
||||||
|
"# Create ZIP\n"
|
||||||
|
"Write-Host 'Creating zip: ' \$outZip\n"
|
||||||
|
"if (Test-Path \$outZip) { Remove-Item -Force \$outZip }\n"
|
||||||
|
"Compress-Archive -Path (Join-Path \$releaseDir '*') -DestinationPath \$outZip\n"
|
||||||
|
"Write-Host 'Package created: ' \$outZip\n"
|
||||||
|
)
|
||||||
|
|
||||||
|
add_custom_target(package_windows
|
||||||
|
COMMAND "${CMAKE_COMMAND}" --build "${CMAKE_BINARY_DIR}" --config Release
|
||||||
|
COMMAND powershell.exe -NoProfile -ExecutionPolicy Bypass -File "${PS_SCRIPT}"
|
||||||
|
-srcExe "$<TARGET_FILE:shadertoy_sdl3>"
|
||||||
|
-releaseDir "${RELEASE_DIR}"
|
||||||
|
-readme "${CMAKE_SOURCE_DIR}/README.md"
|
||||||
|
-license "${CMAKE_SOURCE_DIR}/LICENSE"
|
||||||
|
-shadersDir "${CMAKE_SOURCE_DIR}/shaders"
|
||||||
|
-dllDir "${DLL_SOURCE_DIR}"
|
||||||
|
-outZip "${WINDOWS_ZIP}"
|
||||||
|
COMMENT "Building Release and creating Windows package"
|
||||||
|
BYPRODUCTS "${WINDOWS_ZIP}"
|
||||||
|
)
|
||||||
|
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Helpful messages
|
||||||
|
message(STATUS "CMake generator: ${CMAKE_GENERATOR}")
|
||||||
|
message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
|
||||||
|
message(STATUS "Binary output (runtime): ${CMAKE_BINARY_DIR}/bin")
|
||||||
|
|
||||||
|
# Developer target: build Release and then package on Windows
|
||||||
|
add_custom_target(build_release
|
||||||
|
COMMAND ${CMAKE_COMMAND} --build "${CMAKE_BINARY_DIR}" --config Release
|
||||||
|
COMMENT "Building Release configuration"
|
||||||
|
)
|
||||||
|
|
||||||
|
if(WIN32)
|
||||||
|
add_dependencies(package_windows build_release)
|
||||||
endif()
|
endif()
|
||||||
|
|||||||
21
LICENSE
Normal file
21
LICENSE
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License
|
||||||
|
|
||||||
|
Copyright (c) 2025 Coffee Crisis Arcade Edition
|
||||||
|
|
||||||
|
This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
|
||||||
|
|
||||||
|
You are free to:
|
||||||
|
- Share — copy and redistribute the material in any medium or format
|
||||||
|
- Adapt — remix, transform, and build upon the material
|
||||||
|
|
||||||
|
Under the following terms:
|
||||||
|
- Attribution — You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.
|
||||||
|
- NonCommercial — You may not use the material for commercial purposes.
|
||||||
|
- ShareAlike — If you remix, transform, or build upon the material, you must distribute your contributions under the same license as the original.
|
||||||
|
|
||||||
|
No additional restrictions — You may not apply legal terms or technological measures that legally restrict others from doing anything the license permits.
|
||||||
|
|
||||||
|
To view a copy of this license, visit:
|
||||||
|
https://creativecommons.org/licenses/by-nc-sa/4.0/
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
Reference in New Issue
Block a user