Raised This Month: $32 Target: $400
 8% 

[Help] How to compile with cmake


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Ndrs24
Junior Member
Join Date: Jan 2019
Old 02-07-2023 , 12:09   [Help] How to compile with cmake
Reply With Quote #1

My modifications made in moduleconfig.h:
PHP Code:
#define MODULE_NAME "TestName"
#define MODULE_VERSION "0.0.1"
#define MODULE_AUTHOR "TestAAuthor"
#define MODULE_URL "TestUrl"
#define MODULE_LOGTAG "TestLogTag"
#define MODULE_LIBRARY "testlib"
#define MODULE_LIBCLASS ""

#define USE_METAMOD

#define FN_AMXX_PLUGINSLOADED OnPluginsLoaded 
My file main.cpp
PHP Code:
#include "sdk/amxxmodule.h"

void OnPluginsLoaded()
{
    
MF_Log("Hello World");

My file CMakeLists.txt
PHP Code:
cmake_minimum_required(VERSION 3.18)
project(mylib)

set(TARGET_NAME ${PROJECT_NAME})

add_library(${TARGET_NAMESHARED main.cpp sdk/amxxmodule.cpp)

set(DEP_DIR c:/msdk)
target_include_directories(${TARGET_NAME} PRIVATE
  
# https://github.com/alliedmodders/amxmodx.git
  
${DEP_DIR}/amxmodx/public 

  
# https://github.com/alliedmodders/hlsdk.git
  
${DEP_DIR}/hlsdk/dlls
  
${DEP_DIR}/hlsdk/public
  ${
DEP_DIR}/hlsdk/common
  
${DEP_DIR}/hlsdk/engine

  
# https://github.com/alliedmodders/metamod-hl1.git
  
${DEP_DIR}/metamod-hl1/metamod
  sdk
)

set_target_properties(${TARGET_NAMEPROPERTIES PREFIX "")
set_target_properties(${TARGET_NAMEPROPERTIES SUFFIX "_amxx.dll")

set(LIBRARY_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/build/lib
I'm trying to compile on windows and it gives me this error when compiling:
Code:
[build] In file included from C:/cpp_proyects/cmakemodule/sdk/amxxmodule.cpp:2953:
[build] c:/msdk/hlsdk/dlls/cbase.h:57:34: error: expected constructor, destructor, or type conversion before '(' token
[build]    57 | #define CBASE_DLLEXPORT _declspec( dllexport )
[build]       |                                  ^
[build] c:/msdk/hlsdk/dlls/cbase.h:65:12: note: in expansion of macro 'CBASE_DLLEXPORT'
[build]    65 | extern "C" CBASE_DLLEXPORT int GetEntityAPI( DLL_FUNCTIONS *pFunctionTable, int interfaceVersion );
[build]       |            ^~~~~~~~~~~~~~~
[build] c:/msdk/hlsdk/dlls/cbase.h:57:34: error: expected constructor, destructor, or type conversion before '(' token
[build]    57 | #define CBASE_DLLEXPORT _declspec( dllexport )
[build]       |                                  ^
[build] c:/msdk/hlsdk/dlls/cbase.h:66:12: note: in expansion of macro 'CBASE_DLLEXPORT'
[build]    66 | extern "C" CBASE_DLLEXPORT int GetEntityAPI2( DLL_FUNCTIONS *pFunctionTable, int *interfaceVersion );
[build]       |            ^~~~~~~~~~~~~~~
[build] c:/msdk/hlsdk/dlls/cbase.h:57:36: error: 'dllexport' has not been declared
[build]    57 | #define CBASE_DLLEXPORT _declspec( dllexport )
[build]       |                                    ^~~~~~~~~
[build] c:/msdk/hlsdk/dlls/cbase.h:63:16: note: in expansion of macro 'CBASE_DLLEXPORT'
[build]    63 | #define EXPORT CBASE_DLLEXPORT
[build]       |                ^~~~~~~~~~~~~~~
[build] c:/msdk/hlsdk/dlls/cbase.h:241:14: note: in expansion of macro 'EXPORT'
[build]   241 |         void EXPORT SUB_Remove( void );
[build]       |              ^~~~~~
[build] c:/msdk/hlsdk/dlls/cbase.h:57:46: error: expected ';' at end of member declaration
[build]    57 | #define CBASE_DLLEXPORT _declspec( dllexport )
[build]       |                                              ^
[build] c:/msdk/hlsdk/dlls/cbase.h:63:16: note: in expansion of macro 'CBASE_DLLEXPORT'
[build]    63 | #define EXPORT CBASE_DLLEXPORT
[build]       |                ^~~~~~~~~~~~~~~
[build] c:/msdk/hlsdk/dlls/cbase.h:241:14: note: in expansion of macro 'EXPORT'
[build]   241 |         void EXPORT SUB_Remove( void );
[build]       |              ^~~~~~
All the mistakes
https://pastebin.com/mpU31bah

For more details I have all the files here
https://github.com/Ndrs24/amxx-module-cmake

Last edited by Ndrs24; 02-07-2023 at 12:13.
Ndrs24 is offline
rtxa
Senior Member
Join Date: Mar 2018
Location: Argentina
Old 02-10-2023 , 14:06   Re: [Help] How to compile with cmake
Reply With Quote #2

If I'm not wrong, if you're gonna use CMake in your project, you can't use it lightly, you need to include every source file and create several CMakeLists.txt in hlsdk and amxx containing the files manually. I know is annoying to include every file but that's the way CMake works, it's a build script generator more than a build system.

There's something in CMake called globbing which can help you to point out a directory and include every file in it automatically, but it will give you problems when updating your CMake project in real-time and you need to rebuild the project from time to time.
__________________
rtxa is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 02:39.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode