1+
12cmake_minimum_required (VERSION 3.20)
23project (mario_isn C)
34
4- # Langage & bundle macOS
5+ # =====================================
6+ # Language / IDE helpers
7+ # =====================================
58set (CMAKE_C_STANDARD 99)
6- set (CMAKE_MACOSX_BUNDLE TRUE )
7- set (MACOSX_BUNDLE_BUNDLE_NAME "MarioISN" )
8- set (MACOSX_BUNDLE_GUI_IDENTIFIER "fr.aymnms.marioisn" )
9- set (MACOSX_BUNDLE_SHORT_VERSION_STRING "1.0.0" )
10- set (MACOSX_BUNDLE_LONG_VERSION_STRING "1.0" )
11- set (MACOSX_BUNDLE_BUNDLE_VERSION "1.0.0" )
12- set (MACOSX_BUNDLE_ICON_FILE MyIcon.icns)
13-
14- # Pour VS Code / IntelliSense
159set (CMAKE_EXPORT_COMPILE_COMMANDS ON )
1610
17- # Trouver SDL2 via les packages CMake fournis par Homebrew
18- find_package (SDL2 REQUIRED CONFIG)
19- find_package (SDL2_image REQUIRED CONFIG)
20- find_package (SDL2_mixer REQUIRED CONFIG)
11+ # =====================================
12+ # Platform-specific bundle/target settings
13+ # =====================================
14+ # On macOS we build an .app bundle; on other OSes we build a regular executable
15+ if (APPLE )
16+ set (PLATFORM_BUNDLE MACOSX_BUNDLE )
17+ set (CMAKE_MACOSX_BUNDLE TRUE )
18+ set (MACOSX_BUNDLE_BUNDLE_NAME "MarioISN" )
19+ set (MACOSX_BUNDLE_GUI_IDENTIFIER "fr.aymnms.marioisn" )
20+ set (MACOSX_BUNDLE_SHORT_VERSION_STRING "1.0.0" )
21+ set (MACOSX_BUNDLE_LONG_VERSION_STRING "1.0" )
22+ set (MACOSX_BUNDLE_BUNDLE_VERSION "1.0.0" )
23+ set (MACOSX_BUNDLE_ICON_FILE MyIcon.icns)
24+ endif ()
25+
26+ # =====================================
27+ # Dependencies: SDL2 family
28+ # Try CMake config packages first (Homebrew/vcpkg), fallback to pkg-config (Linux)
29+ # =====================================
30+ find_package (SDL2 QUIET CONFIG)
31+ find_package (SDL2_image QUIET CONFIG)
32+ find_package (SDL2_mixer QUIET CONFIG)
2133
22- # Exécutable (cible)
23- add_executable (mario_isn MACOSX_BUNDLE
34+ if (NOT SDL2_FOUND OR NOT SDL2_image_FOUND OR NOT SDL2_mixer_FOUND)
35+ find_package (PkgConfig REQUIRED)
36+ pkg_check_modules(SDL2 REQUIRED sdl2)
37+ pkg_check_modules(SDL2_image REQUIRED SDL2_image)
38+ pkg_check_modules(SDL2_mixer REQUIRED SDL2_mixer)
39+ set (HAVE_SDL_PKGCFG TRUE )
40+ endif ()
41+
42+ # =====================================
43+ # Executable target
44+ # =====================================
45+ add_executable (mario_isn ${PLATFORM_BUNDLE}
46+ src/globals.c
2447 src/main.c
2548 src/display.c
2649 src/path .c
2750 src/menu/init_menu.c
28- src/menu/menu .c
51+ src/menu/MENU .c
2952 src/game/init_game.c
3053 src/game/GAME.c
3154 src/game/conditions.c
@@ -39,29 +62,83 @@ add_executable(mario_isn MACOSX_BUNDLE
3962 src/game/joueur/music.c
4063 src/game/joueur/niveau.c
4164 src/game/joueur/saut_joueur.c
42- ${CMAKE_SOURCE_DIR} /ressources/MyIcon.icns
4365)
4466
45- # Indique où la placer dans le bundle
46- set_source_files_properties (${CMAKE_SOURCE_DIR} /ressources/MyIcon.icns
47- PROPERTIES MACOSX_PACKAGE_LOCATION "Resources" )
67+ # Autorise les définitions communes (rétro-compatibilité GCC <10)
68+ if (CMAKE_C_COMPILER_ID MATCHES "GNU|Clang" )
69+ target_compile_options (mario_isn PRIVATE -fcommon)
70+ endif ()
4871
49- # Portée des includes du projet (headers locaux)
50- target_include_directories (mario_isn PRIVATE
51- ${CMAKE_SOURCE_DIR} /include
52- )
72+ # Add headers include path (project-local)
73+ target_include_directories (mario_isn PRIVATE ${CMAKE_SOURCE_DIR} /include )
5374
54- # Lien contre SDL2 (targets importées = include + libs + defines gérés)
55- target_link_libraries (mario_isn PRIVATE
75+ # Link SDL depending on how it was found
76+ if (NOT HAVE_SDL_PKGCFG)
77+ target_link_libraries (mario_isn PRIVATE
5678 SDL2::SDL2
5779 SDL2_image::SDL2_image
58- SDL2_mixer::SDL2_mixer
59- )
80+ SDL2_mixer::SDL2_mixer)
81+ else ()
82+ target_include_directories (mario_isn PRIVATE
83+ ${SDL2_INCLUDE_DIRS} ${SDL2_image_INCLUDE_DIRS} ${SDL2_mixer_INCLUDE_DIRS} )
84+ target_link_libraries (mario_isn PRIVATE
85+ ${SDL2_LINK_LIBRARIES} ${SDL2_image_LINK_LIBRARIES} ${SDL2_mixer_LINK_LIBRARIES} )
86+ endif ()
6087
61- # Copie des assets dans le bundle .app (Resources)
62- add_custom_command (TARGET mario_isn POST_BUILD
63- COMMAND ${CMAKE_COMMAND} -E make_directory $<TARGET_BUNDLE_CONTENT_DIR:mario_isn>/Resources
64- COMMAND ${CMAKE_COMMAND} -E copy_directory
65- ${CMAKE_SOURCE_DIR} /ressources
66- $<TARGET_BUNDLE_CONTENT_DIR:mario_isn>/Resources
67- )
88+ # =====================================
89+ # Resources / Assets
90+ # =====================================
91+ # Project resources layout at source:
92+ # ressources/
93+ # MyIcon.icns
94+ # img/ musique/ bin/
95+
96+ if (APPLE )
97+ # Add icon into the bundle and place it under Contents/Resources
98+ target_sources (mario_isn PRIVATE ${CMAKE_SOURCE_DIR} /ressources/MyIcon.icns)
99+ set_source_files_properties (${CMAKE_SOURCE_DIR} /ressources/MyIcon.icns
100+ PROPERTIES MACOSX_PACKAGE_LOCATION "Resources" )
101+
102+ # Copy assets into the app bundle Resources so SDL_GetBasePath() finds img/, musique/, bin/
103+ add_custom_command (TARGET mario_isn POST_BUILD
104+ COMMAND ${CMAKE_COMMAND} -E make_directory
105+ $<TARGET_BUNDLE_CONTENT_DIR:mario_isn>/Resources
106+ COMMAND ${CMAKE_COMMAND} -E copy_directory
107+ ${CMAKE_SOURCE_DIR} /ressources/img
108+ $<TARGET_BUNDLE_CONTENT_DIR:mario_isn>/Resources/img
109+ COMMAND ${CMAKE_COMMAND} -E copy_directory
110+ ${CMAKE_SOURCE_DIR} /ressources/musique
111+ $<TARGET_BUNDLE_CONTENT_DIR:mario_isn>/Resources/musique
112+ COMMAND ${CMAKE_COMMAND} -E copy_directory
113+ ${CMAKE_SOURCE_DIR} /ressources/bin
114+ $<TARGET_BUNDLE_CONTENT_DIR:mario_isn>/Resources/bin
115+ )
116+
117+ elseif (WIN32 )
118+ # On Windows, copy assets next to the .exe
119+ add_custom_command (TARGET mario_isn POST_BUILD
120+ COMMAND ${CMAKE_COMMAND} -E copy_directory
121+ ${CMAKE_SOURCE_DIR} /ressources/img
122+ $<TARGET_FILE_DIR:mario_isn>/img
123+ COMMAND ${CMAKE_COMMAND} -E copy_directory
124+ ${CMAKE_SOURCE_DIR} /ressources/musique
125+ $<TARGET_FILE_DIR:mario_isn>/musique
126+ COMMAND ${CMAKE_COMMAND} -E copy_directory
127+ ${CMAKE_SOURCE_DIR} /ressources/bin
128+ $<TARGET_FILE_DIR:mario_isn>/bin
129+ )
130+
131+ elseif (UNIX )
132+ # On Linux, copy assets next to the executable
133+ add_custom_command (TARGET mario_isn POST_BUILD
134+ COMMAND ${CMAKE_COMMAND} -E copy_directory
135+ ${CMAKE_SOURCE_DIR} /ressources/img
136+ $<TARGET_FILE_DIR:mario_isn>/img
137+ COMMAND ${CMAKE_COMMAND} -E copy_directory
138+ ${CMAKE_SOURCE_DIR} /ressources/musique
139+ $<TARGET_FILE_DIR:mario_isn>/musique
140+ COMMAND ${CMAKE_COMMAND} -E copy_directory
141+ ${CMAKE_SOURCE_DIR} /ressources/bin
142+ $<TARGET_FILE_DIR:mario_isn>/bin
143+ )
144+ endif ()
0 commit comments