From 1c6b9559d416d056445100e47c9f82b2f84d8dbf Mon Sep 17 00:00:00 2001 From: Jon Daniel Date: Wed, 9 Mar 2022 12:56:41 +0100 Subject: [PATCH 1/6] Add CMake build system for unix like systems --- .gitignore | 1 + CMakeLists.txt | 62 ++++ README.md | 288 ++++++++++++++++++ {example4 => examples/putemple}/Makefile.win | 0 {example4 => examples/putemple}/putemple.c | 10 +- {example4 => examples/putemple}/putemple.dev | 0 .../putemple}/putemple_private.h | 0 .../putemple}/putemple_private.rc | 0 {example1 => examples/putgems}/Makefile.win | 0 {example1 => examples/putgems}/putgems.c | 12 +- {example1 => examples/putgems}/putgems.dev | 0 {example2 => examples/puttrain}/Makefile.win | 0 {example2 => examples/puttrain}/puttrain.c | 12 +- {example2 => examples/puttrain}/puttrain.dev | 0 {example3 => examples/viewmap}/Makefile.win | 0 {example3 => examples/viewmap}/viewmap.c | 10 +- {example3 => examples/viewmap}/viewmap.dev | 0 .../viewmap}/viewmap_private.h | 0 .../viewmap}/viewmap_private.rc | 0 libadikted/CMakeLists.txt | 65 ++-- libadikted/{Makefile => Makefile.win} | 0 libadikted/libadikted.pc.in | 12 + mapslang/CMakeLists.txt | 69 +++++ mapslang/{Makefile => Makefile.win} | 0 mapslang/scr_actn.c | 2 +- mapslang/textmenu.c | 1 + 26 files changed, 487 insertions(+), 57 deletions(-) create mode 100644 CMakeLists.txt create mode 100644 README.md rename {example4 => examples/putemple}/Makefile.win (100%) rename {example4 => examples/putemple}/putemple.c (98%) rename {example4 => examples/putemple}/putemple.dev (100%) rename {example4 => examples/putemple}/putemple_private.h (100%) rename {example4 => examples/putemple}/putemple_private.rc (100%) rename {example1 => examples/putgems}/Makefile.win (100%) rename {example1 => examples/putgems}/putgems.c (90%) rename {example1 => examples/putgems}/putgems.dev (100%) rename {example2 => examples/puttrain}/Makefile.win (100%) rename {example2 => examples/puttrain}/puttrain.c (94%) rename {example2 => examples/puttrain}/puttrain.dev (100%) rename {example3 => examples/viewmap}/Makefile.win (100%) rename {example3 => examples/viewmap}/viewmap.c (97%) rename {example3 => examples/viewmap}/viewmap.dev (100%) rename {example3 => examples/viewmap}/viewmap_private.h (100%) rename {example3 => examples/viewmap}/viewmap_private.rc (100%) rename libadikted/{Makefile => Makefile.win} (100%) create mode 100644 libadikted/libadikted.pc.in create mode 100644 mapslang/CMakeLists.txt rename mapslang/{Makefile => Makefile.win} (100%) diff --git a/.gitignore b/.gitignore index 26ec652..35b9d34 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,4 @@ /.settings/ /tmp/ /build/ +Makefile diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..779032a --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,62 @@ +cmake_minimum_required( VERSION 3.1 ) + +project( ADiKtED LANGUAGES C ) +set(PROJECT_DESCRIPTION "Dungeon Keeper 1 map editor") + +include(GNUInstallDirs) +include(FindPkgConfig) + +if( NOT CMAKE_BUILD_TYPE ) + set( CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE ) +endif() + +set( CMAKE_C_STANDARD 99 ) +set( CMAKE_C_STANDARD_REQUIRED ON ) +set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wno-switch -Wno-unused-parameter -Wno-unused-result" ) +set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pedantic" ) +set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wextra" ) +set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror-implicit-function-declaration -Wno-conversion -Wno-traditional-conversion -Wno-sign-compare" ) + +file( GLOB_RECURSE EXAMPLES_PUTGEMS_SOURCES examples/putgems/*.c + examples/putgems/*.h ) +file( GLOB_RECURSE EXAMPLES_PUTTRAIN_SOURCES examples/puttrain/*.c + examples/puttrain/*.h ) +file( GLOB_RECURSE EXAMPLES_VIEWMAP_SOURCES examples/viewmap/*.c + examples/viewmap/*.h ) +file( GLOB_RECURSE EXAMPLES_PUTEMPLE_SOURCES examples/putemple/*.c + examples/putemple/*.h ) + +find_package(SDL REQUIRED SDL::Main) +include_directories(${SDL_INCLUDE_DIR}) + +add_executable(putgems ${EXAMPLES_PUTGEMS_SOURCES} ) +target_link_libraries( putgems PUBLIC adikted m dl) +set_target_properties( putgems PROPERTIES RUNTIME_OUTPUT_DIRECTORY + ${CMAKE_BINARY_DIR} ) +add_test(putgems putgems) + +add_executable(puttrain ${EXAMPLES_PUTTRAIN_SOURCES} ) +target_link_libraries( puttrain PUBLIC adikted m dl) +set_target_properties( putgems PROPERTIES RUNTIME_OUTPUT_DIRECTORY + ${CMAKE_BINARY_DIR} ) +add_test(puttrain puttrain) + +add_executable(viewmap ${EXAMPLES_VIEWMAP_SOURCES} ) +target_link_libraries( viewmap PUBLIC adikted m dl ${SDL_LIBRARIES}) +set_target_properties( viewmap PROPERTIES RUNTIME_OUTPUT_DIRECTORY + ${CMAKE_BINARY_DIR} ) +add_test(viewmap viewmap) + +add_executable(putemple ${EXAMPLES_PUTEMPLE_SOURCES} ) +target_link_libraries( putemple PRIVATE adikted m dl ${SDL_LIBRARIES}) +set_target_properties( putemple PROPERTIES RUNTIME_OUTPUT_DIRECTORY + ${CMAKE_BINARY_DIR} ) +add_test(putemple putemple) + +install(TARGETS putgems puttrain viewmap putemple EXPORT ${PROJECT_NAME}Config + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + PUBLIC_HEADER DESTINATION + ${CMAKE_INSTALL_INCLUDEDIR} + ) diff --git a/README.md b/README.md new file mode 100644 index 0000000..8652071 --- /dev/null +++ b/README.md @@ -0,0 +1,288 @@ +Adikted Dungeon Keeper Map Editor +------------------------------ + +Note - there is now a manual available for ADiKtEd. +It even includes a basic tutorial to quickly learn the program. +A version of it is included within this distribution, +called dk_adikted_manual.htm. You may wish to print this out. + +Here's the Win32 version executable. Just put all the +files in the same directory, edit map.ini as appropriate (you should +change paths to your DK files; you can also change other parameters +if you want), and run it. + +Usage: map [mapfile] [-m ] [-v] [-r] [-n] [-s [mapfile]] [-q] +where: + mapfile Specifies filename (eg newmap), or just map number + (like 18 etc.) which is loaded. Skipping this will start + with new map. + -m logfile Allows you to save all messages shown on the bottom + of screen when Adkted is working. You must specify output + file where the messages will be written (ie. adi_msg.log). + -s [mapfile] Saves the map. Can overwrite the opened file, or save + to another one given as next parameter. Note that commands + that come after this one are executed after the map is saved, + and therefore are lost on quit. + -v Triggers map verification; you could combine it with "-m" option + to get verification result in a text file. + -r Starts new, random map. If [mapfile] was specified, then + it is loaded, but then cleared and replaced by the + random map. + -n Forces to start new map, even if the [mapfile] was specified. + The [mapfile] is loaded, but then replaced. + -q Quits Adikted after the tasks from previous parameters have been + completed. Useful for automated work. + -ds Disable all sounds. Makes Adikted silent, and less annoying. + -du Disable auto updates of both DAT/CLM/W?B and TNG/LGT/APT. + With this, generating maps and starting new one will be very + fast, but the update must be triggered manually before + saving a map. + -bmp Write bitmap miniature of the map. + -dvid Disable showing anything on screen. Screen is not initied + nor refreshed. Useful if you want only run some commands + and quit. + -dinp Disable keyboard input. Adikted will exit after executing + all comands given in parameters. For users it works just + like -q option, but it won't even init keyboard input. + +When ADiKtEd saves a map, it will ask you what you wish to call it +(unless you're not using quick save). I suggest you don't save +directly over the Dungeon Keeper original levels, but keep it +in the current directory until you're finished. +Then, at end, save it on map00001 to access it easily in the game. + +You'll need a level script for your newly created level. You may be +able to get by with the script which comes with the original level 1 +- ie just copy it and paste into TXT file of your new map - but +if not, study the level scripts reference from dk_scripting_ref.htm. +You can also try looking at the original DK and DD levels for examples. + +Press F1 for help. + +TODO before final: + Fixations in room things parameters (height,other) + Fixations in room corner graphics +Version: 0.95b + Prepared two more libAdikted examples + Added some graphics API functions + Started making support of various map sizes + Added support for VSN files + Fixed verification of QUICK_* in script - length up to 511 + Added warning if there are unclosed IF loops +Version: 0.93b + Work on Script Generator started (ctrl+t in script mode) + Work on doxygen documentation of libAdikted started + Renewed file access functions in RNC decompression module + Rewritten MEMFILE module + LIF files (containing level name) are now supported + Created two examples on how to use ADiKtEd library +Version: 0.92b + Minor changes to INI commands and defaults + Disabled changing range of objects which don't have it + Changed name "room effect" into "effect generator" + Extra torches are no longer placed in rooms + Bridge can now recognize if its put on water or lava + Tutorial replaced by larger manual +Version: 0.91b + A little renaming in the ADiKtEd library + Created functions to make the library more independent + Added Home/end keys in script mode + Script update function now updates arguments + Line break (only into two lines) in script viewer + New INI option for loading UnDed maps +Version: 0.90b + Isolated map editing library + Corrected error message on bad arguments of some commands + Added one new custom column (idea by Gonadsonfire) +Version: 0.83b + Fixed memory freeing error (shouldn't hang on exit) + Updated file handling on map miniature generation + Fixed Wall around Scavenger Room and Barracks + Better reinforced wall near lava and water + Better reinforced wall in corners of some rooms +Version: 0.82b + Added verification to 4 next parameters + Improved description of some cubes + Added 'f' in slab mode - draw random fortified wall + Perfected creation of things in corners of some rooms + Fixed the code to compile under linux + Fixed memory allocation error (write before allocation) + Modified file handling on map miniature generation +Version: 0.81b + Fixed load error handling bug + Corrected to allow loading Unded maps + Improved verification algorithm + Added ctrl+d (aggressive clean) in thing mode + Copyright messages built in source code + Changed some default options in INI file + Hero gate number can now be changed using s/x + Extended ADI internal script format + Only 7 script command parameters are not verified yet +Version: 0.80b + Unrecognised script commands converted to REMarks on update + Added SCRIPT_LEVEL_SPACES command in INI file + Added verification of script commands with amount of arguments + Action point number can be changed using s/x + Fixed hero gate numbering (positive number instead of negative) + Positions and ranges can be displayed as fixed point numbers + Most of the script command parameters are verified + Action point/hero grate numbers verified in script file + Added colors and highlighting in script mode + Little corrections to save/load screens +Version: 0.75b + Script file recognition logic extended + Modified frail columns generation to prevent stucked imps + Static light intensivity can now be changed using s/x + Added basic verification of script commands (only command names) + Added experimental script update function ('u' in script mode) + Fixed sensitive tile computing for various things + Extended items verification + Traps, doors and creatures are now numbered (as in official editor) +Version: 0.74b + Extended CLM entries verification + Texture animations are readed when creating BMPs + Correction in BMP resizing algorithm + File reading routine rewritten, better error handling + Added help about elements of various lists + Fixed some mistakes in TNG logic, rewritten TNG categorization + Added "edit object" function (enter key in Thing mode) +Version: 0.73b + Added space saving if screen size is small + INI file commented, and added some options + End of text line is now written as "\r\n", not only "\n" + Level graphic generation improved and more adjustable + Fixed typing path in load/save screens + Changed the way of clearing unused CLM entries + CLM generation code divided to more files + A little more cubes defined + Small correction to BMP creation function +Version: 0.72b + Unified initialization of work modes (probably some errors fixed) + New Load Map (ctrl+l) and Save screens (with preview) + Fixed hanging on ctrl+g key + Extended logging ("-m" command line option) + Some corrections to "add creature" screen + Some new "custom columns" + New graffiti entering screen ('d' in slab mode) +Version: 0.71b + Created some basic structs to close variables + When verifying level ('v') errors are now highlighted + Default effects range set to 5 subtiles + Some global variables replaced by locals + Fixed setting solid property for custom columns +Version: 0.70b + Map miniature size can be now changed in INI file + Fixed damaging the script file + Corrected height of Guard flag +Version: 0.69b + Added bitmap miniature making (ctrl+b) +Version: 0.68b + Script handling changed + More script commands are recognized (but still not all) + Heart flames are placed at proper height +Version: 0.67b + More cube values are defined (invisible for end users) + Some corrections in Column mode + Custom columns function completely rewritten (speed optimized) + Test map generation function, for recognizing cubes + Map is loaded anyway if script loading fails + Information after updating TNG is more detailed +Version: 0.66b + Range of items which have such property is now visible in thing mode + Option to disable objects range visibility in INI file + INI file commands updated + Fixed compile errors and makefile for Linux systems + Added "-du" command line option +Version: 0.63b + Added changing range of lights/effects with '-' and '+' + The last column (which has no slab attached) is updated as rock + Some of the load/save functions rewritten and fixed + WLB files are now maintained and updated properly + Loading/saving of FLG files + FLG entries are maintained quite good + Added room-specific reinforced walls + Added searching for objects (ctrl+f) + Added rework mode (undocumented - for reworking only) +Version: 0.60b + Some corrections in screen colors + Better statistics counting and numbering of hero gates + Auto creating room things for all rooms + Auto creating dungeon heart thing (one per player) + Auto creating torches + Updating owner now results in TNG update + The '[' and ']' keys now works on action points +Version: 0.56a + Some corrections in "manual columns" + Texture change function under ctrl+e + Enter key displays list of slabs + Verification ('v') of things extended + Items and room effects have now "sensitive tile" + Added computing "sensitive tile" for torches and room effects + Fixed some display problems if Adikted window is small +Version: 0.55a + Fixed hanging when F7 (quick load) pressed + Graffiti orientation can now be changed with 'a' + Graffiti can now be oriented for view from top + Extended help system and help file + Corrected white spaces treatment inside map.ini file + Height of graffiti/thing can be changed with '[' and ']' + New, experimental "manual columns" function +Version: 0.54a + Support of all rooms completed + Graffiti support renewed + Created ADI file format, its reading and writing +Version: 0.53a + Compass view under ctrl+p + Added support of Hatchery, Lair, Graveyard, Barracks, Train room + Better function for generating rooms surrounded by lava/water +Version: 0.52a + Added support of Dungeon Heart, Portal, Library, Temple + Some fixups and expansions in TNG support + Added some command line parameters + Rewritten screen refreshing, new look of Thing mode + Help file format extended + Clipboard can now copy action points and static lights + More items can be switched to similar using s/x +Version: 0.51a + New, dynamic CLM generation + Completely new functions to geneate map graphic (DAT/CLM entries) + Written support of all terrain types, but no rooms + No automatic 'thing' generation + Graffiti not working due to DAT support changes + Project moved back to alpha state +Version: 0.51b + Enhanced map verification function (press v in slab mode) + Completely rewritten CLM/DAT support (it was lot of work...) +Version: 0.50b + Most of the TNG support code rewritten completely + Renewed "creature" screen (adding creatures) + New item screen (allows adding ANY item available in the game) + Create room effect function (e key in "thing" mode) +Version: 0.49b + The random map generator has been extended + Added loading and saving of INF,TXT,LGT and WLB files + Re-added updating of DAT and CLM (but not TNG) when saving +Version: 0.48b + The way of interpreting user-typed map names is now unified + All memory allocation routines checked and rewritten + Fixed problem with automatic deletion of DHeart on saving + Added some very beginnings of random map generator (ctrl+r) +Version: 0.47b + Added definitions of more objects, ie. creature lairs + Added hero gate counting and numbering + Some of code rewritten to be more clear +Version: 0.46b + Fixed to allow compilation under new SLang + Win32 version + Fixed coord checking when placing a building + Fixed keyboard codes to be more platform-independent +Version: 0.42b + Quit changed to ctrl+q + Added load (ctrl+l) and new map (ctrl+n) + +Author: + Jon Skeet, skeet@pobox.com + +Dev-C++ IDE version, +rewritten most of the code: + Tomasz Lis diff --git a/example4/Makefile.win b/examples/putemple/Makefile.win similarity index 100% rename from example4/Makefile.win rename to examples/putemple/Makefile.win diff --git a/example4/putemple.c b/examples/putemple/putemple.c similarity index 98% rename from example4/putemple.c rename to examples/putemple/putemple.c index 8af279e..24903e9 100644 --- a/example4/putemple.c +++ b/examples/putemple/putemple.c @@ -1,6 +1,6 @@ /******************************************************************************/ /** @file putemple.c - * ADiKtEd library example 4. + * ADiKtEd library putemple example. * @par Purpose: * Demonstrates fast drawing routines and putting slabs with mouse. * Also, shows how to draw ADiKtEd messages using DK font. @@ -23,7 +23,7 @@ #include #include -#include "../libadikted/adikted.h" +#include "libadikted/adikted.h" #define ONE_LOOP_DELAY 20 /** @@ -404,7 +404,7 @@ static void process_events() // contains error message. // Release the error message. message_release(); - message_info("example4 finished with map load error"); + message_info("putemple finished with map load error"); reload_data=0; level_redraw=0; clip_view=0; @@ -425,7 +425,7 @@ static void process_events() { // Release the error message. message_release(); - message_info("example4 finished with data files load error"); + message_info("putemple finished with data files load error"); level_redraw=0; clip_view=0; done = 1; @@ -493,7 +493,7 @@ int main (int argc, char *argv[]) free_messages(); return 2; } - SDL_WM_SetCaption ("ADiKtEd Libray example 4", NULL); + SDL_WM_SetCaption ("ADiKtEd Libray putemple example", NULL); message_log("Preparing data structures"); // create object for storing map diff --git a/example4/putemple.dev b/examples/putemple/putemple.dev similarity index 100% rename from example4/putemple.dev rename to examples/putemple/putemple.dev diff --git a/example4/putemple_private.h b/examples/putemple/putemple_private.h similarity index 100% rename from example4/putemple_private.h rename to examples/putemple/putemple_private.h diff --git a/example4/putemple_private.rc b/examples/putemple/putemple_private.rc similarity index 100% rename from example4/putemple_private.rc rename to examples/putemple/putemple_private.rc diff --git a/example1/Makefile.win b/examples/putgems/Makefile.win similarity index 100% rename from example1/Makefile.win rename to examples/putgems/Makefile.win diff --git a/example1/putgems.c b/examples/putgems/putgems.c similarity index 90% rename from example1/putgems.c rename to examples/putgems/putgems.c index 6c33380..c6f9eff 100644 --- a/example1/putgems.c +++ b/examples/putgems/putgems.c @@ -1,6 +1,6 @@ /******************************************************************************/ /** @file putgems.c - * ADiKtEd library example 1. + * ADiKtEd library putgems example. * @par Purpose: * This example puts gems on center of gold vein in map 1. * Demonstrates how to load/save map, and how to change slabs. @@ -19,7 +19,7 @@ #include #include -#include "../libadikted/adikted.h" +#include "libadikted/adikted.h" int main(int argc, char *argv[]) { @@ -34,7 +34,7 @@ int main(int argc, char *argv[]) // but still they have to be initialized) init_messages(); - printf("\nexample1: how to put gems on map\n\n"); + printf("\nputgems: how to put gems on map\n\n"); // Setting file name of the map to load format_lvl_fname(lvl,"Levels/MAP00001"); @@ -46,7 +46,7 @@ int main(int argc, char *argv[]) if (result!=ERR_NONE) { printf("cannot load map\n"); - printf("example1 finished with error\n"); + printf("putgems finished with error\n"); system("pause"); // The following two commands should be used to free memory @@ -72,7 +72,7 @@ int main(int argc, char *argv[]) if (result!=ERR_NONE) { printf("cannot save map\n"); - printf("example1 finished with error\n"); + printf("putgems finished with error\n"); system("pause"); // The following two commands should be used to free memory @@ -85,7 +85,7 @@ int main(int argc, char *argv[]) return 1; } printf("map \"%s\" saved\n", get_lvl_savfname(lvl)); - printf("example1 finished successfully\n"); + printf("putgems finished successfully\n"); system("pause"); // The following two commands should be used to free memory diff --git a/example1/putgems.dev b/examples/putgems/putgems.dev similarity index 100% rename from example1/putgems.dev rename to examples/putgems/putgems.dev diff --git a/example2/Makefile.win b/examples/puttrain/Makefile.win similarity index 100% rename from example2/Makefile.win rename to examples/puttrain/Makefile.win diff --git a/example2/puttrain.c b/examples/puttrain/puttrain.c similarity index 94% rename from example2/puttrain.c rename to examples/puttrain/puttrain.c index f4ef6c9..899d0d8 100644 --- a/example2/puttrain.c +++ b/examples/puttrain/puttrain.c @@ -1,6 +1,6 @@ /******************************************************************************/ /** @file puttrain.c - * ADiKtEd library example 2. + * ADiKtEd library puttrain example. * @par Purpose: * This example puts 3x5 training room in bottom right part of map 1. * Demonstrates how to change many slabs at once, @@ -20,7 +20,7 @@ #include #include -#include "../libadikted/adikted.h" +#include "libadikted/adikted.h" int main(int argc, char *argv[]) { @@ -36,7 +36,7 @@ int main(int argc, char *argv[]) // Instead of printing the message directly, we will send it // to the internal messages system. - message_info("example2: how to put a larger room on map"); + message_info("puttrain: how to put a larger room on map"); // Now we can easily get the message back, even multiple times. printf("%s\n",message_get()); @@ -74,7 +74,7 @@ int main(int argc, char *argv[]) // Now, as the buffer is released, the message_info() function // can be used to store next message. - message_info("example2 finished with load error"); + message_info("puttrain finished with load error"); printf("%s\n",message_get()); system("pause"); @@ -118,7 +118,7 @@ int main(int argc, char *argv[]) // Now, as the buffer is released, the message_info() function // can be used to store next message. - message_info("example2 finished with save error"); + message_info("puttrain finished with save error"); printf("%s\n",message_get()); system("pause"); @@ -138,7 +138,7 @@ int main(int argc, char *argv[]) printf("%s\n",message_get()); message_release(); - message_info("example2 finished successfully"); + message_info("puttrain finished successfully"); printf("%s\n",message_get()); system("pause"); diff --git a/example2/puttrain.dev b/examples/puttrain/puttrain.dev similarity index 100% rename from example2/puttrain.dev rename to examples/puttrain/puttrain.dev diff --git a/example3/Makefile.win b/examples/viewmap/Makefile.win similarity index 100% rename from example3/Makefile.win rename to examples/viewmap/Makefile.win diff --git a/example3/viewmap.c b/examples/viewmap/viewmap.c similarity index 97% rename from example3/viewmap.c rename to examples/viewmap/viewmap.c index 09e6f9a..28f3fe4 100644 --- a/example3/viewmap.c +++ b/examples/viewmap/viewmap.c @@ -1,6 +1,6 @@ /******************************************************************************/ /** @file viewmap.c - * ADiKtEd library example 3. + * ADiKtEd library viewmap example. * @par Purpose: * This example shows how to view maps graphically using libAdikted. * Move with mouse, zoom with numpad +/-. @@ -22,7 +22,7 @@ #include #include -#include "../libadikted/adikted.h" +#include "libadikted/adikted.h" #define ONE_LOOP_DELAY 32 /** @@ -279,7 +279,7 @@ static void process_events() // Release the error message. message_release(); - message_info("example3 finished with data files load error"); + message_info("viewmap finished with data files load error"); clip_view=0; done = 1; @@ -339,7 +339,7 @@ int main (int argc, char *argv[]) free_messages(); return 2; } - SDL_WM_SetCaption ("ADiKtEd Libray example 3", NULL); + SDL_WM_SetCaption ("ADiKtEd Libray viewmap example", NULL); // create object for storing map level_init(&lvl,MFV_DKGOLD,NULL); @@ -365,7 +365,7 @@ int main (int argc, char *argv[]) // Release the error message. message_release(); - message_info("example3 finished with map load error"); + message_info("viewmap finished with map load error"); level_free(lvl); level_deinit(&lvl); diff --git a/example3/viewmap.dev b/examples/viewmap/viewmap.dev similarity index 100% rename from example3/viewmap.dev rename to examples/viewmap/viewmap.dev diff --git a/example3/viewmap_private.h b/examples/viewmap/viewmap_private.h similarity index 100% rename from example3/viewmap_private.h rename to examples/viewmap/viewmap_private.h diff --git a/example3/viewmap_private.rc b/examples/viewmap/viewmap_private.rc similarity index 100% rename from example3/viewmap_private.rc rename to examples/viewmap/viewmap_private.rc diff --git a/libadikted/CMakeLists.txt b/libadikted/CMakeLists.txt index 652e56e..b3c1e0f 100644 --- a/libadikted/CMakeLists.txt +++ b/libadikted/CMakeLists.txt @@ -1,43 +1,19 @@ -## -## -## - - -## 3.1 -- CMAKE_C_STANDARD cmake_minimum_required( VERSION 3.1 ) - -if( "${CMAKE_CURRENT_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_BINARY_DIR}" ) - message( FATAL_ERROR "Building in source is forbidden. Change output directory.") -endif() - - project( libadikted LANGUAGES C ) +set(PROJECT_DESCRIPTION "Dungeon Keeper 1 ADiKtEd map editor C library" +include(GNUInstallDirs) +include(FindPkgConfig) if( NOT CMAKE_BUILD_TYPE ) - set( CMAKE_BUILD_TYPE Debug CACHE STRING "Choose the type of build." FORCE ) -endif() - -if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) - ## do not install accidentally to system directory - set( CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/install" CACHE PATH "Install path prefix" FORCE ) + set( CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE ) endif() - set(CMAKE_DEBUG_POSTFIX _d) - -## -## set default compilation standard -## set( CMAKE_C_STANDARD 99 ) set( CMAKE_C_STANDARD_REQUIRED ON ) - - -## -## compiler flags, gcc does not handle "appended" values -## set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall" ) set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pedantic" ) set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wextra" ) @@ -47,7 +23,7 @@ set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror-implicit-function-declaration -Wno- ## ================= build ================= -option( USE_RNG_MT "Use Mersenne Twister RNG" OFF ) +option( USE_RNG_MT "Use Mersenne Twister RNG" ON ) if( USE_RNG_MT ) add_definitions( -DRNG_MT ) endif() @@ -69,12 +45,33 @@ if( NOT USE_RNG_MT ) list(REMOVE_ITEM c_files "${CMAKE_CURRENT_SOURCE_DIR}/mtwist/mtwist.c" ) endif() - add_library( ${TARGET_NAME} ${${TARGET_NAME}_TYPE} ${c_files} ) -target_include_directories( ${TARGET_NAME} PUBLIC ".." PRIVATE "." ) + +target_include_directories(${TARGET_NAME} PUBLIC + ".." + $ + $ + PRIVATE "." + ) + set_target_properties( ${TARGET_NAME} PROPERTIES PUBLIC_HEADER "${h_files}" ) -install( TARGETS ${TARGET_NAME} - PUBLIC_HEADER DESTINATION include/lib${TARGET_NAME} COMPONENT headers - LIBRARY DESTINATION lib COMPONENT binaries +# pkg-config variables +set(target_name "${TARGET_NAME}") +set(install_prefix "${CMAKE_INSTALL_PREFIX}") +set(install_libdir "${CMAKE_INSTALL_LIBDIR}") +set(install_includedir "${CMAKE_INSTALL_INCLUDEDIR}") + +configure_file(lib${TARGET_NAME}.pc.in ${PROJECT_BINARY_DIR}/lib${TARGET_NAME}.pc @ONLY) + +set(ENV{PKG_CONFIG_PATH} "${PROJECT_BINARY_DIR}:$ENV{PKG_CONFIG_PATH}") + +install( TARGETS ${TARGET_NAME} EXPORT lib${TARGET_NAME}Config + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT binaries + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/lib${TARGET_NAME} COMPONENT headers ) + +install(FILES ${PROJECT_BINARY_DIR}/lib${TARGET_NAME}.pc DESTINATION + ${CMAKE_INSTALL_LIBDIR}/pkgconfig/) diff --git a/libadikted/Makefile b/libadikted/Makefile.win similarity index 100% rename from libadikted/Makefile rename to libadikted/Makefile.win diff --git a/libadikted/libadikted.pc.in b/libadikted/libadikted.pc.in new file mode 100644 index 0000000..e1750c0 --- /dev/null +++ b/libadikted/libadikted.pc.in @@ -0,0 +1,12 @@ +prefix=@install_prefix@ +exe_prefix=${prefix} +libdir=${prefix}/@install_libdir@ +includedir=${prefix}/@install_includedir@ + +Name: lib@target_name@ +Description: @PROJECT_DESCRIPTION@ +Version: @PROJECT_VERSION@ + +Requires: +Libs: -L${libdir} -l@target_name@ +Cflags: -I${includedir} -I${includedir}/@target_name@ diff --git a/mapslang/CMakeLists.txt b/mapslang/CMakeLists.txt new file mode 100644 index 0000000..86d4bf7 --- /dev/null +++ b/mapslang/CMakeLists.txt @@ -0,0 +1,69 @@ +cmake_minimum_required( VERSION 3.0 ) +project(mapslang LANGUAGES C) + +include(FindPkgConfig) +include(CMakePackageConfigHelpers) + +set_property( GLOBAL PROPERTY USE_FOLDERS ON ) +set( CMAKE_C_STANDARD 99 ) +set( CMAKE_C_STANDARD_REQUIRED ON ) +set( CMAKE_C_EXTENSIONS ON ) +set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-discarded-qualifiers -Wno-unused-result -Wno-unused-parameter" ) + +set( MAPSLANG_LIBRARY_TYPE "STATIC" CACHE STRING "Linking type for library" ) + +set_property( CACHE MAPSLANG_LIBRARY_TYPE PROPERTY STRINGS STATIC SHARED ) + +if( MAPSLANG_LIBRARY_TYPE MATCHES "SHARED" ) + set(CMAKE_POSITION_INDEPENDENT_CODE ON) +endif() + +if(POLICY CMP0072) + cmake_policy(SET CMP0072 NEW) +endif() + +# Grab the keeperfx source files +file( GLOB MAPSLANG_SOURCES input_kb.c main.c output_scr.c scr_actn.c scr_clm.c scr_cube.c scr_help.c scr_list.c scr_rwrk.c scr_slab.c scr_thing.c scr_tileset.c scr_txted.c scr_txtgen.c textmenu.c var_utils.c ) + +add_executable( mapslang ${MAPSLANG_SOURCES} ) +target_include_directories( mapslang + PUBLIC + $ + $) + +if( UNIX AND NOT APPLE AND NOT EMSCRIPTEN AND NOT ANDROID ) + pkg_search_module(SLANG REQUIRED slang) + pkg_search_module(ADIKTED REQUIRED libadikted) + target_compile_options( mapslang PUBLIC ${ADIKTED_CFLAGS} ${SLANG_CFLAGS}) + target_link_libraries( mapslang PUBLIC ${ADIKTED_LIBRARIES} + ${SLANG_LIBRARIES} -ldl -lm) +endif() + +# Put in a "mapslang" folder in Visual Studio +set_target_properties( mapslang PROPERTIES FOLDER "mapslang" ) + +# Special Visual Studio Flags +if( MSVC ) + target_compile_definitions( mapslang PRIVATE "_CRT_SECURE_NO_WARNINGS" ) +endif() + +if ("${CMAKE_BUILD_TYPE}" STREQUAL "") + set(CMAKE_BUILD_TYPE "None") +endif () + +set(uppercase_CMAKE_BUILD_TYPE TOUPPER "${CMAKE_BUILD_TYPE}" "NONE") +# Add debug config required in keeperfx headers since bx is private +if ( uppercase_CMAKE_BUILD_TYPE} STREQUAL "DEBUG" ) + target_compile_definitions( mapslang PUBLIC "MAPSLANG_DEBUG=1" ) +else() + target_compile_definitions( mapslang PUBLIC "MAPSLANG_DEBUG=0" ) +endif() + +install( TARGETS mapslang + EXPORT "${TARGETS_EXPORT_NAME}" + LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" + ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" + RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" + INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" + ) + diff --git a/mapslang/Makefile b/mapslang/Makefile.win similarity index 100% rename from mapslang/Makefile rename to mapslang/Makefile.win diff --git a/mapslang/scr_actn.c b/mapslang/scr_actn.c index 0086296..224ec0d 100644 --- a/mapslang/scr_actn.c +++ b/mapslang/scr_actn.c @@ -23,7 +23,7 @@ #include #include -#include "../libadikted/adikted.h" +#include "libadikted/adikted.h" #include "var_utils.h" #include "output_scr.h" #include "input_kb.h" diff --git a/mapslang/textmenu.c b/mapslang/textmenu.c index c38485c..9625afa 100644 --- a/mapslang/textmenu.c +++ b/mapslang/textmenu.c @@ -30,6 +30,7 @@ #include "output_scr.h" #include "var_utils.h" + inline union _value menu_value_num(long num) { union _value ret; ret.num=num; return ret; } From 94d62ffa86fde911e8721cdd71a081a0e1c5d282 Mon Sep 17 00:00:00 2001 From: Jon Daniel Date: Wed, 9 Mar 2022 13:27:34 +0100 Subject: [PATCH 2/6] fix typo and add more ignores --- .gitignore | 21 +++++++++++++++++++++ libadikted/CMakeLists.txt | 2 +- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 35b9d34..0ed03cd 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,9 @@ *.dll *.def *.exe +*.so +*.pc +*.cmake /lib/slang* /mapslang/pkg/* .vs/ @@ -14,3 +17,21 @@ /tmp/ /build/ Makefile +CMakeFiles/ +CMakeCache.txt +cmake_install.cmake +install_manifest.txt +libadikted/CMakeFiles/ +libadikted/CMakeCache.txt +libadikted/Makefile +libadikted/cmake_install.cmake +libadikted/install_manifest.txt +mapslang/CMakeFiles/ +mapslang/CMakeCache.txt +mapslang/cmake_install.cmake +mapslang/Makefile +mapslang/install_manifest.txt +putemple +puttrain +putgems +viewmap diff --git a/libadikted/CMakeLists.txt b/libadikted/CMakeLists.txt index b3c1e0f..0472a65 100644 --- a/libadikted/CMakeLists.txt +++ b/libadikted/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required( VERSION 3.1 ) project( libadikted LANGUAGES C ) -set(PROJECT_DESCRIPTION "Dungeon Keeper 1 ADiKtEd map editor C library" +set( PROJECT_DESCRIPTION "Dungeon Keeper 1 ADiKtEd map editor C library" ) include(GNUInstallDirs) include(FindPkgConfig) From 49ad848418fc6cc8cb7b0be1ea8ac2119a8e88ec Mon Sep 17 00:00:00 2001 From: Jon Daniel Date: Wed, 9 Mar 2022 13:36:10 +0100 Subject: [PATCH 3/6] add subdirectories --- CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 779032a..e397582 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -29,6 +29,9 @@ file( GLOB_RECURSE EXAMPLES_PUTEMPLE_SOURCES examples/putemple/*.c find_package(SDL REQUIRED SDL::Main) include_directories(${SDL_INCLUDE_DIR}) +add_subdirectory(libadikted) +add_subdirectory(mapslang) + add_executable(putgems ${EXAMPLES_PUTGEMS_SOURCES} ) target_link_libraries( putgems PUBLIC adikted m dl) set_target_properties( putgems PROPERTIES RUNTIME_OUTPUT_DIRECTORY From 451ca3df389d25a8e7711582e6b21891065f64ea Mon Sep 17 00:00:00 2001 From: Jon Daniel Date: Wed, 9 Mar 2022 15:12:59 +0100 Subject: [PATCH 4/6] remove ../ and rename to map --- .gitignore | 4 ++++ CMakeLists.txt | 24 ++++++++++++------------ mapslang/CMakeLists.txt | 10 +++++----- mapslang/Makefile.win | 4 ++-- mapslang/input_kb.c | 2 +- mapslang/main.c | 2 +- mapslang/output_scr.c | 2 +- mapslang/scr_actn.h | 2 +- mapslang/scr_clm.c | 2 +- mapslang/scr_cube.c | 2 +- mapslang/scr_help.c | 2 +- mapslang/scr_list.c | 2 +- mapslang/scr_rwrk.c | 2 +- mapslang/scr_slab.c | 2 +- mapslang/scr_thing.c | 2 +- mapslang/scr_tileset.c | 6 +++--- mapslang/scr_txted.c | 2 +- mapslang/scr_txtgen.c | 2 +- mapslang/textmenu.c | 2 +- mapslang/textmenu.h | 2 +- mapslang/var_utils.c | 6 +++--- 21 files changed, 44 insertions(+), 40 deletions(-) diff --git a/.gitignore b/.gitignore index 0ed03cd..b493fa6 100644 --- a/.gitignore +++ b/.gitignore @@ -5,10 +5,14 @@ *.def *.exe *.so +*.a *.pc *.cmake /lib/slang* /mapslang/pkg/* +mapslang/mapslang +mapslang/map +map .vs/ .git /.cproject diff --git a/CMakeLists.txt b/CMakeLists.txt index e397582..462da6f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,35 +26,35 @@ file( GLOB_RECURSE EXAMPLES_VIEWMAP_SOURCES examples/viewmap/*.c file( GLOB_RECURSE EXAMPLES_PUTEMPLE_SOURCES examples/putemple/*.c examples/putemple/*.h ) -find_package(SDL REQUIRED SDL::Main) -include_directories(${SDL_INCLUDE_DIR}) +find_package( SDL REQUIRED SDL::Main ) +include_directories( ${SDL_INCLUDE_DIR} ) -add_subdirectory(libadikted) -add_subdirectory(mapslang) +add_subdirectory( libadikted ) +add_subdirectory( mapslang ) -add_executable(putgems ${EXAMPLES_PUTGEMS_SOURCES} ) +add_executable( putgems ${EXAMPLES_PUTGEMS_SOURCES} ) target_link_libraries( putgems PUBLIC adikted m dl) set_target_properties( putgems PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR} ) -add_test(putgems putgems) +add_test( putgems putgems) -add_executable(puttrain ${EXAMPLES_PUTTRAIN_SOURCES} ) +add_executable( puttrain ${EXAMPLES_PUTTRAIN_SOURCES} ) target_link_libraries( puttrain PUBLIC adikted m dl) set_target_properties( putgems PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR} ) -add_test(puttrain puttrain) +add_test( puttrain puttrain ) -add_executable(viewmap ${EXAMPLES_VIEWMAP_SOURCES} ) +add_executable( viewmap ${EXAMPLES_VIEWMAP_SOURCES} ) target_link_libraries( viewmap PUBLIC adikted m dl ${SDL_LIBRARIES}) set_target_properties( viewmap PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR} ) -add_test(viewmap viewmap) +add_test( viewmap viewmap ) -add_executable(putemple ${EXAMPLES_PUTEMPLE_SOURCES} ) +add_executable( putemple ${EXAMPLES_PUTEMPLE_SOURCES} ) target_link_libraries( putemple PRIVATE adikted m dl ${SDL_LIBRARIES}) set_target_properties( putemple PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR} ) -add_test(putemple putemple) +add_test( putemple putemple ) install(TARGETS putgems puttrain viewmap putemple EXPORT ${PROJECT_NAME}Config LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} diff --git a/mapslang/CMakeLists.txt b/mapslang/CMakeLists.txt index 86d4bf7..9c4bb21 100644 --- a/mapslang/CMakeLists.txt +++ b/mapslang/CMakeLists.txt @@ -25,8 +25,8 @@ endif() # Grab the keeperfx source files file( GLOB MAPSLANG_SOURCES input_kb.c main.c output_scr.c scr_actn.c scr_clm.c scr_cube.c scr_help.c scr_list.c scr_rwrk.c scr_slab.c scr_thing.c scr_tileset.c scr_txted.c scr_txtgen.c textmenu.c var_utils.c ) -add_executable( mapslang ${MAPSLANG_SOURCES} ) -target_include_directories( mapslang +add_executable( map ${MAPSLANG_SOURCES} ) +target_include_directories( map PUBLIC $ $) @@ -40,11 +40,11 @@ if( UNIX AND NOT APPLE AND NOT EMSCRIPTEN AND NOT ANDROID ) endif() # Put in a "mapslang" folder in Visual Studio -set_target_properties( mapslang PROPERTIES FOLDER "mapslang" ) +set_target_properties( map PROPERTIES FOLDER "mapslang" ) # Special Visual Studio Flags if( MSVC ) - target_compile_definitions( mapslang PRIVATE "_CRT_SECURE_NO_WARNINGS" ) + target_compile_definitions( map PRIVATE "_CRT_SECURE_NO_WARNINGS" ) endif() if ("${CMAKE_BUILD_TYPE}" STREQUAL "") @@ -59,7 +59,7 @@ else() target_compile_definitions( mapslang PUBLIC "MAPSLANG_DEBUG=0" ) endif() -install( TARGETS mapslang +install( TARGETS map EXPORT "${TARGETS_EXPORT_NAME}" LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" diff --git a/mapslang/Makefile.win b/mapslang/Makefile.win index 8a1b97f..99234b5 100644 --- a/mapslang/Makefile.win +++ b/mapslang/Makefile.win @@ -90,7 +90,7 @@ RES = obj/map_private.res RC = map_private.rc LFLAGS = -static-libgcc $(PLATFORM_FLAGS) LFLAGS_DEBUG = -static-libgcc $(PLATFORM_FLAGS) -DDEBUG -LIBS = -L. -L../libadikted/bin -L..$(SLANG_BIN_FOLDER) -lslang -ladikted +LIBS = -L. -Llibadikted/bin -L..$(SLANG_BIN_FOLDER) -lslang -ladikted SRC = \ input_kb.c \ main.c \ @@ -132,7 +132,7 @@ strip-executables: fill-pkg-directory: $(MKDIR) pkg/docs $(CP) $(BIN) pkg/ - $(CP) ../libadikted/bin/$(LIB_ADIKTED) pkg/ + $(CP) libadikted/bin/$(LIB_ADIKTED) pkg/ $(CP) ..$(SLANG_BIN_FOLDER)/$(LIB_SLANG) pkg/ $(CP) map.hlp pkg/ $(CP) map.ini pkg/ diff --git a/mapslang/input_kb.c b/mapslang/input_kb.c index db2cd6b..5fa6ce1 100644 --- a/mapslang/input_kb.c +++ b/mapslang/input_kb.c @@ -23,7 +23,7 @@ #include #include "output_scr.h" #include "var_utils.h" -#include "../libadikted/adikted.h" +#include "libadikted/adikted.h" short input_initied=false; short disable_sounds=false; diff --git a/mapslang/main.c b/mapslang/main.c index 683cea1..b8c7599 100644 --- a/mapslang/main.c +++ b/mapslang/main.c @@ -4,7 +4,7 @@ #include -#include "../libadikted/adikted.h" +#include "libadikted/adikted.h" #include "scr_actn.h" #include "scr_help.h" #include "scr_txted.h" diff --git a/mapslang/output_scr.c b/mapslang/output_scr.c index 86bdd60..41b1451 100644 --- a/mapslang/output_scr.c +++ b/mapslang/output_scr.c @@ -20,7 +20,7 @@ #include "output_scr.h" -#include "../libadikted/adikted.h" +#include "libadikted/adikted.h" #include #include "scr_actn.h" diff --git a/mapslang/scr_actn.h b/mapslang/scr_actn.h index 61d9417..cca0eef 100644 --- a/mapslang/scr_actn.h +++ b/mapslang/scr_actn.h @@ -21,7 +21,7 @@ #ifndef ADIKT_SCRACTN_H #define ADIKT_SCRACTN_H -#include "../libadikted/globals.h" +#include "libadikted/globals.h" struct LEVEL; diff --git a/mapslang/scr_clm.c b/mapslang/scr_clm.c index 64baebd..d0498b7 100644 --- a/mapslang/scr_clm.c +++ b/mapslang/scr_clm.c @@ -21,7 +21,7 @@ #include "scr_clm.h" -#include "../libadikted/adikted.h" +#include "libadikted/adikted.h" #include "output_scr.h" #include "input_kb.h" #include "scr_actn.h" diff --git a/mapslang/scr_cube.c b/mapslang/scr_cube.c index 90c023f..19a9db1 100644 --- a/mapslang/scr_cube.c +++ b/mapslang/scr_cube.c @@ -20,7 +20,7 @@ #include "scr_cube.h" -#include "../libadikted/adikted.h" +#include "libadikted/adikted.h" #include "output_scr.h" #include "input_kb.h" #include "scr_actn.h" diff --git a/mapslang/scr_help.c b/mapslang/scr_help.c index e6b5741..34604db 100644 --- a/mapslang/scr_help.c +++ b/mapslang/scr_help.c @@ -21,7 +21,7 @@ #include "scr_help.h" -#include "../libadikted/adikted.h" +#include "libadikted/adikted.h" #include "scr_actn.h" #include "output_scr.h" #include "input_kb.h" diff --git a/mapslang/scr_list.c b/mapslang/scr_list.c index 4895c85..82475a5 100644 --- a/mapslang/scr_list.c +++ b/mapslang/scr_list.c @@ -21,7 +21,7 @@ #include "scr_list.h" -#include "../libadikted/adikted.h" +#include "libadikted/adikted.h" #include "output_scr.h" #include "input_kb.h" #include "scr_actn.h" diff --git a/mapslang/scr_rwrk.c b/mapslang/scr_rwrk.c index 567b568..b9b71fe 100644 --- a/mapslang/scr_rwrk.c +++ b/mapslang/scr_rwrk.c @@ -20,7 +20,7 @@ #include "scr_rwrk.h" -#include "../libadikted/adikted.h" +#include "libadikted/adikted.h" #include "output_scr.h" #include "input_kb.h" #include "scr_actn.h" diff --git a/mapslang/scr_slab.c b/mapslang/scr_slab.c index 515b056..7e437f7 100644 --- a/mapslang/scr_slab.c +++ b/mapslang/scr_slab.c @@ -22,7 +22,7 @@ #include "scr_slab.h" #include -#include "../libadikted/adikted.h" +#include "libadikted/adikted.h" #include "output_scr.h" #include "input_kb.h" #include "scr_actn.h" diff --git a/mapslang/scr_thing.c b/mapslang/scr_thing.c index 232c7f5..b838ef3 100644 --- a/mapslang/scr_thing.c +++ b/mapslang/scr_thing.c @@ -22,7 +22,7 @@ #include "scr_thing.h" #include -#include "../libadikted/adikted.h" +#include "libadikted/adikted.h" #include "scr_help.h" #include "output_scr.h" #include "input_kb.h" diff --git a/mapslang/scr_tileset.c b/mapslang/scr_tileset.c index e81f61a..7fe633b 100644 --- a/mapslang/scr_tileset.c +++ b/mapslang/scr_tileset.c @@ -19,9 +19,9 @@ /******************************************************************************/ -#include "../libadikted/globals.h" -#include "../libadikted/lev_data.h" -#include "../libadikted/msg_log.h" +#include "libadikted/globals.h" +#include "libadikted/lev_data.h" +#include "libadikted/msg_log.h" #include "input_kb.h" #include "output_scr.h" #include "scr_actn.h" diff --git a/mapslang/scr_txted.c b/mapslang/scr_txted.c index bc9f902..205bc31 100644 --- a/mapslang/scr_txted.c +++ b/mapslang/scr_txted.c @@ -20,7 +20,7 @@ #include "scr_txted.h" -#include "../libadikted/adikted.h" +#include "libadikted/adikted.h" #include "output_scr.h" #include "input_kb.h" #include "scr_actn.h" diff --git a/mapslang/scr_txtgen.c b/mapslang/scr_txtgen.c index 1d349d8..2b26576 100644 --- a/mapslang/scr_txtgen.c +++ b/mapslang/scr_txtgen.c @@ -24,7 +24,7 @@ #include "scr_txtgen.h" -#include "../libadikted/adikted.h" +#include "libadikted/adikted.h" #include "var_utils.h" #include "input_kb.h" #include "output_scr.h" diff --git a/mapslang/textmenu.c b/mapslang/textmenu.c index 9625afa..5dbc485 100644 --- a/mapslang/textmenu.c +++ b/mapslang/textmenu.c @@ -25,7 +25,7 @@ #include "textmenu.h" -#include "../libadikted/globals.h" +#include "libadikted/globals.h" #include "input_kb.h" #include "output_scr.h" #include "var_utils.h" diff --git a/mapslang/textmenu.h b/mapslang/textmenu.h index a71ec51..7b5e2eb 100644 --- a/mapslang/textmenu.h +++ b/mapslang/textmenu.h @@ -20,7 +20,7 @@ #ifndef BULL_TEXTMENU_H #define BULL_TEXTMENU_H -#include "../libadikted/globals.h" +#include "libadikted/globals.h" #define MIT_NUMERIC 0 #define MIT_BOOLEAN 1 diff --git a/mapslang/var_utils.c b/mapslang/var_utils.c index 0b99b05..f0f630c 100644 --- a/mapslang/var_utils.c +++ b/mapslang/var_utils.c @@ -19,11 +19,11 @@ #include "var_utils.h" -#include "../libadikted/globals.h" +#include "libadikted/globals.h" #include #include "input_kb.h" -#include "../libadikted/msg_log.h" -#include "../libadikted/lev_data.h" +#include "libadikted/msg_log.h" +#include "libadikted/lev_data.h" #include "output_scr.h" #include "scr_actn.h" From 37f9b214e0c53a391d0690160b180a3ff00ea927 Mon Sep 17 00:00:00 2001 From: Jon Daniel Date: Wed, 9 Mar 2022 15:21:26 +0100 Subject: [PATCH 5/6] rename mapslang to map --- mapslang/CMakeLists.txt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mapslang/CMakeLists.txt b/mapslang/CMakeLists.txt index 9c4bb21..43b9291 100644 --- a/mapslang/CMakeLists.txt +++ b/mapslang/CMakeLists.txt @@ -34,8 +34,8 @@ target_include_directories( map if( UNIX AND NOT APPLE AND NOT EMSCRIPTEN AND NOT ANDROID ) pkg_search_module(SLANG REQUIRED slang) pkg_search_module(ADIKTED REQUIRED libadikted) - target_compile_options( mapslang PUBLIC ${ADIKTED_CFLAGS} ${SLANG_CFLAGS}) - target_link_libraries( mapslang PUBLIC ${ADIKTED_LIBRARIES} + target_compile_options( map PUBLIC ${ADIKTED_CFLAGS} ${SLANG_CFLAGS}) + target_link_libraries( map PUBLIC ${ADIKTED_LIBRARIES} ${SLANG_LIBRARIES} -ldl -lm) endif() @@ -54,9 +54,9 @@ endif () set(uppercase_CMAKE_BUILD_TYPE TOUPPER "${CMAKE_BUILD_TYPE}" "NONE") # Add debug config required in keeperfx headers since bx is private if ( uppercase_CMAKE_BUILD_TYPE} STREQUAL "DEBUG" ) - target_compile_definitions( mapslang PUBLIC "MAPSLANG_DEBUG=1" ) + target_compile_definitions( map PUBLIC "MAP_DEBUG=1" ) else() - target_compile_definitions( mapslang PUBLIC "MAPSLANG_DEBUG=0" ) + target_compile_definitions( map PUBLIC "MAP_DEBUG=0" ) endif() install( TARGETS map From 73b28e5e272f13b1ccef05956b9ae298e80c116a Mon Sep 17 00:00:00 2001 From: Jon Daniel Date: Thu, 10 Mar 2022 21:30:11 +0100 Subject: [PATCH 6/6] fix build not include and linking --- CMakeLists.txt | 99 ++++++++++++++++++------------------- libadikted/CMakeLists.txt | 32 ++++++------ libadikted/libadikted.pc.in | 2 +- mapslang/CMakeLists.txt | 19 +++---- 4 files changed, 75 insertions(+), 77 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 462da6f..cdd18be 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,56 +10,53 @@ if( NOT CMAKE_BUILD_TYPE ) set( CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE ) endif() -set( CMAKE_C_STANDARD 99 ) -set( CMAKE_C_STANDARD_REQUIRED ON ) -set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wno-switch -Wno-unused-parameter -Wno-unused-result" ) -set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pedantic" ) -set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wextra" ) -set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror-implicit-function-declaration -Wno-conversion -Wno-traditional-conversion -Wno-sign-compare" ) - -file( GLOB_RECURSE EXAMPLES_PUTGEMS_SOURCES examples/putgems/*.c - examples/putgems/*.h ) -file( GLOB_RECURSE EXAMPLES_PUTTRAIN_SOURCES examples/puttrain/*.c - examples/puttrain/*.h ) -file( GLOB_RECURSE EXAMPLES_VIEWMAP_SOURCES examples/viewmap/*.c - examples/viewmap/*.h ) -file( GLOB_RECURSE EXAMPLES_PUTEMPLE_SOURCES examples/putemple/*.c - examples/putemple/*.h ) - -find_package( SDL REQUIRED SDL::Main ) -include_directories( ${SDL_INCLUDE_DIR} ) - -add_subdirectory( libadikted ) -add_subdirectory( mapslang ) - -add_executable( putgems ${EXAMPLES_PUTGEMS_SOURCES} ) -target_link_libraries( putgems PUBLIC adikted m dl) -set_target_properties( putgems PROPERTIES RUNTIME_OUTPUT_DIRECTORY - ${CMAKE_BINARY_DIR} ) -add_test( putgems putgems) - -add_executable( puttrain ${EXAMPLES_PUTTRAIN_SOURCES} ) -target_link_libraries( puttrain PUBLIC adikted m dl) -set_target_properties( putgems PROPERTIES RUNTIME_OUTPUT_DIRECTORY - ${CMAKE_BINARY_DIR} ) -add_test( puttrain puttrain ) - -add_executable( viewmap ${EXAMPLES_VIEWMAP_SOURCES} ) -target_link_libraries( viewmap PUBLIC adikted m dl ${SDL_LIBRARIES}) -set_target_properties( viewmap PROPERTIES RUNTIME_OUTPUT_DIRECTORY - ${CMAKE_BINARY_DIR} ) -add_test( viewmap viewmap ) +add_subdirectory(libadikted) +add_subdirectory(mapslang) + +function( add_example ARG_NAME ) + list( APPEND ARG_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR}/examples/${ARG_NAME}" ) + set( SOURCES "" ) + set( RESOURCES "" ) + foreach( DIR ${ARG_DIRECTORIES} ) + file( GLOB GLOB_SOURCES ${DIR}/*.c ${DIR}/*.h ) + list( APPEND SOURCES ${GLOB_SOURCES} ) + file( GLOB GLOB_RESOURCES ${DIR}/*.rc ) + list( APPEND RESOURCES ${GLOB_RESOURCES} ) + endforeach() + add_executable( ${ARG_NAME} ${SOURCES} ) + target_link_libraries( ${ARG_NAME} PUBLIC + adikted ${CMAKE_C_STANDARD_LIBRARIES} ) + find_package( SDL REQUIRED ) + target_link_libraries( ${ARG_NAME} PUBLIC ${SDL_LIBRARIES} ) + target_compile_definitions( ${ARG_NAME} PUBLIC ENTRY_CONFIG_USE_SDL ) + target_link_libraries( ${ARG_NAME} PUBLIC X11 ) + target_include_directories(${ARG_NAME} PUBLIC + $ + $ + ${SDL_INCLUDEDIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/.) + + # Directory name + set_target_properties( ${ARG_NAME} PROPERTIES FOLDER + "${CMAKE_CURRENT_SOURCE_DIR}/examples" ) + add_test(${ARG_NAME} ${ARG_NAME}) +endfunction() + +option( ADIKTED_BUILD_EXAMPLES "Build ADiKtEd examples" ON ) +if( ADIKTED_BUILD_EXAMPLES ) + # Add examples + set( + ADIKTED_EXAMPLES + putgems + puttrain + viewmap + putemple + ) -add_executable( putemple ${EXAMPLES_PUTEMPLE_SOURCES} ) -target_link_libraries( putemple PRIVATE adikted m dl ${SDL_LIBRARIES}) -set_target_properties( putemple PROPERTIES RUNTIME_OUTPUT_DIRECTORY - ${CMAKE_BINARY_DIR} ) -add_test( putemple putemple ) +foreach( EXAMPLE ${ADIKTED_EXAMPLES} ) + add_example( ${EXAMPLE} ) + endforeach() +endif() -install(TARGETS putgems puttrain viewmap putemple EXPORT ${PROJECT_NAME}Config - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} - RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} - PUBLIC_HEADER DESTINATION - ${CMAKE_INSTALL_INCLUDEDIR} - ) +install( TARGETS ${ADIKTED_EXAMPLES} RUNTIME + DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT binaries) diff --git a/libadikted/CMakeLists.txt b/libadikted/CMakeLists.txt index 0472a65..e5496af 100644 --- a/libadikted/CMakeLists.txt +++ b/libadikted/CMakeLists.txt @@ -1,6 +1,7 @@ cmake_minimum_required( VERSION 3.1 ) -project( libadikted LANGUAGES C ) +set( TARGET_NAME adikted ) +project( lib${TARGET_NAME} LANGUAGES C ) set( PROJECT_DESCRIPTION "Dungeon Keeper 1 ADiKtEd map editor C library" ) include(GNUInstallDirs) @@ -14,7 +15,9 @@ set(CMAKE_DEBUG_POSTFIX _d) set( CMAKE_C_STANDARD 99 ) set( CMAKE_C_STANDARD_REQUIRED ON ) -set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall" ) +set( CMAKE_C_STANDARD_LIBRARIES_INIT "-lm ${CMAKE_DL_LIBS}" ) + +set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wno-switch" ) set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pedantic" ) set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wextra" ) set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror-implicit-function-declaration -Wno-conversion -Wno-traditional-conversion -Wno-sign-compare" ) @@ -29,49 +32,46 @@ if( USE_RNG_MT ) endif() -set( TARGET_NAME adikted ) if( NOT ${TARGET_NAME}_TYPE ) ## build library as shared by default set( ${TARGET_NAME}_TYPE SHARED ) endif() +file( GLOB c_files ${CMAKE_CURRENT_SOURCE_DIR}/*.c) +file( GLOB h_files ${CMAKE_CURRENT_SOURCE_DIR}/*.h) -file( GLOB_RECURSE c_files *.c ) -file( GLOB_RECURSE h_files *.h ) - -if( NOT USE_RNG_MT ) - list(REMOVE_ITEM h_files "${CMAKE_CURRENT_SOURCE_DIR}/mtwist/mtwist.h" ) - list(REMOVE_ITEM c_files "${CMAKE_CURRENT_SOURCE_DIR}/mtwist/mtwist.c" ) +if( USE_RNG_MT ) + list(APPEND h_files "${CMAKE_CURRENT_SOURCE_DIR}/mtwist/mtwist.h" ) + list(APPEND c_files "${CMAKE_CURRENT_SOURCE_DIR}/mtwist/mtwist.c" ) endif() -add_library( ${TARGET_NAME} ${${TARGET_NAME}_TYPE} ${c_files} ) +add_library( ${TARGET_NAME} ${${TARGET_NAME}_TYPE} ${c_files} ) +set_target_properties( ${TARGET_NAME} PROPERTIES PUBLIC_HEADER "${h_files}" ) target_include_directories(${TARGET_NAME} PUBLIC - ".." $ $ PRIVATE "." ) -set_target_properties( ${TARGET_NAME} PROPERTIES PUBLIC_HEADER "${h_files}" ) - # pkg-config variables set(target_name "${TARGET_NAME}") +set(stdclibs "${CMAKE_C_STANDARD_LIBRARIES}") set(install_prefix "${CMAKE_INSTALL_PREFIX}") set(install_libdir "${CMAKE_INSTALL_LIBDIR}") set(install_includedir "${CMAKE_INSTALL_INCLUDEDIR}") - configure_file(lib${TARGET_NAME}.pc.in ${PROJECT_BINARY_DIR}/lib${TARGET_NAME}.pc @ONLY) set(ENV{PKG_CONFIG_PATH} "${PROJECT_BINARY_DIR}:$ENV{PKG_CONFIG_PATH}") install( TARGETS ${TARGET_NAME} EXPORT lib${TARGET_NAME}Config - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT binaries + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT libraries ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} - RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT binaries PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/lib${TARGET_NAME} COMPONENT headers ) install(FILES ${PROJECT_BINARY_DIR}/lib${TARGET_NAME}.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig/) + diff --git a/libadikted/libadikted.pc.in b/libadikted/libadikted.pc.in index e1750c0..44b2849 100644 --- a/libadikted/libadikted.pc.in +++ b/libadikted/libadikted.pc.in @@ -8,5 +8,5 @@ Description: @PROJECT_DESCRIPTION@ Version: @PROJECT_VERSION@ Requires: -Libs: -L${libdir} -l@target_name@ +Libs: -L${libdir} -l@target_name@ @stdclib@ Cflags: -I${includedir} -I${includedir}/@target_name@ diff --git a/mapslang/CMakeLists.txt b/mapslang/CMakeLists.txt index 43b9291..59ebde9 100644 --- a/mapslang/CMakeLists.txt +++ b/mapslang/CMakeLists.txt @@ -8,6 +8,7 @@ set_property( GLOBAL PROPERTY USE_FOLDERS ON ) set( CMAKE_C_STANDARD 99 ) set( CMAKE_C_STANDARD_REQUIRED ON ) set( CMAKE_C_EXTENSIONS ON ) +set( CMAKE_C_STANDARD_LIBRARIES_INIT "-lm ${CMAKE_DL_LIBS}" ) set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-discarded-qualifiers -Wno-unused-result -Wno-unused-parameter" ) set( MAPSLANG_LIBRARY_TYPE "STATIC" CACHE STRING "Linking type for library" ) @@ -22,6 +23,9 @@ if(POLICY CMP0072) cmake_policy(SET CMP0072 NEW) endif() +pkg_search_module(SLANG REQUIRED slang) +pkg_search_module(ADIKTED REQUIRED libadikted) + # Grab the keeperfx source files file( GLOB MAPSLANG_SOURCES input_kb.c main.c output_scr.c scr_actn.c scr_clm.c scr_cube.c scr_help.c scr_list.c scr_rwrk.c scr_slab.c scr_thing.c scr_tileset.c scr_txted.c scr_txtgen.c textmenu.c var_utils.c ) @@ -29,15 +33,12 @@ add_executable( map ${MAPSLANG_SOURCES} ) target_include_directories( map PUBLIC $ - $) - -if( UNIX AND NOT APPLE AND NOT EMSCRIPTEN AND NOT ANDROID ) - pkg_search_module(SLANG REQUIRED slang) - pkg_search_module(ADIKTED REQUIRED libadikted) - target_compile_options( map PUBLIC ${ADIKTED_CFLAGS} ${SLANG_CFLAGS}) - target_link_libraries( map PUBLIC ${ADIKTED_LIBRARIES} - ${SLANG_LIBRARIES} -ldl -lm) -endif() + $ + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/..) + +target_compile_options( map PUBLIC ${ADIKTED_CFLAGS} ${SLANG_CFLAGS}) +target_link_libraries( map PUBLIC ${ADIKTED_LIBRARIES} + ${SLANG_LIBRARIES} -lm) # Put in a "mapslang" folder in Visual Studio set_target_properties( map PROPERTIES FOLDER "mapslang" )