Login Page - Create Account

Support Board


Date/Time: Fri, 29 Mar 2024 08:52:38 +0000



[Programming Help] - CMake and Including the Sierra Chart Header files?

View Count: 1229

[2020-09-20 22:14:28]
mbilyanov - Posts: 62
Hi,

I have successfully built a DLL under Linux following instructions on this board. Now I'm trying to re-create the same process but using CMake.

I got bits and pieces to work (toolchain file, mingw32 etc.), however, I was not able to add the `ACS_Source` file to the include directories.

Has anyone successfully built a SC Custom Study DLL using CMake?

Basically this command works:
/usr/bin/x86_64-w64-mingw32-g++ -march=x86-64 -mtune=x86-64 -O2 -shared -static -static-libgcc -static-libstdc++ -s -fno-rtti -fno-exceptions -I /home/me/.wine/drive_c/SierraChartLinux/ACS_Source/ -w ./src/MySCStudy.cpp -o ./build/MySCStudy.dll

But inside my CMakeLists, I was not able to specify the include directory for some reason.

Any ideas?
[2020-09-21 08:21:53]
mbilyanov - Posts: 62
This is my CMake file so far:


# ;--------------------------------------------------------------------------------
# ; Initials
# ;--------------------------------------------------------------------------------
cmake_minimum_required(VERSION 3.1)
project(MySCStudy)

MESSAGE(STATUS "<${PROJECT_NAME}> CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}")
MESSAGE(STATUS "<${PROJECT_NAME}> CMAKE_BINARY_DIR: ${CMAKE_BINARY_DIR}")

# ;--------------------------------------------------------------------------------
# ; Include Directories
# ;--------------------------------------------------------------------------------
set(SC_INCLUDE_DIR /home/mbilyanov/.wine/drive_c/SierraChartLinux/ACS_Source)
set(MINGW_INCLUDE_DIR /usr/x86_64-w64-mingw32/include)
MESSAGE(STATUS "<${PROJECT_NAME}> SC_INCLUDE_DIR: ${SC_INCLUDE_DIR}")
#MESSAGE(STATUS "<${PROJECT_NAME}> MINGW_INCLUDE_DIR: ${MINGW_INCLUDE_DIR}")

# ;--------------------------------------------------------------------------------
# ; Compiler Flags
# ;--------------------------------------------------------------------------------
set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} "-march=x86-64 -mtune=k8")

add_compile_options(-O2 -shared -static -static-libgcc -static-libstdc++ -s -fno-rtti -fno-exceptions)

# ;--------------------------------------------------------------------------------
# ; Source Files
# ;--------------------------------------------------------------------------------
# file(GLOB SOURCE_FILES
# "./src/*.cpp"
# )
set(SOURCE_FILES ./src/MySCStudy.cpp)
set(SC_HEADER_FILES ${SC_INCLUDE_DIR}/sierrachart.h)

# ;--------------------------------------------------------------------------------
# ; Properties
# ;--------------------------------------------------------------------------------
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_PROJECT_NAME}/${CMAKE_BUILD_TYPE}/lib)
set(CMAKE_SHARED_LIBRARY_PREFIX "")

add_library(${PROJECT_NAME} SHARED ${SOURCE_FILES} ${SC_HEADER_FILES})
target_include_directories(${PROJECT_NAME} PUBLIC ${SC_INCLUDE_DIR})

# ;--------------------------------------------------------------------------------
# ; Generate Compilation Database
# ;--------------------------------------------------------------------------------
set(CMAKE_EXPORT_COMPILE_COMMANDS 1)

ADD_CUSTOM_COMMAND(TARGET ${PROJECT_NAME}
PRE_BUILD
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_BINARY_DIR}/compile_commands.json ${PROJECT_SOURCE_DIR}
)


But I'm not getting any reference to the ACS_Sources location where the sierrachart headers are in the generated Makefile and when I build the dll, it is a malformed dll file reporting:

CreateStudyDLLModuleFunctionObject | Error loading C:\SierraChartLinux\Data\MySCStudy.dll. Windows error code 126: Module not found. Likely missing dependency file. | 2020-09-21 08:18:59.845 *
[2020-09-21 21:07:59]
mbilyanov - Posts: 62
Any ideas? I have been struggling with this for a while now. No matter what I tried I could not get CMake to include the Sierra Chart headers.
Date Time Of Last Edit: 2020-09-21 21:08:09
[2020-09-24 13:36:01]
AlexPereira - Posts: 195
this is part of what i am using for my project: ( i have a symlink to the ACS_Sources dir on /home/alex/.sierracharts_source )


cmake_minimum_required(VERSION 3.13)

SET(CMAKE_CXX_COMPILER "/usr/bin/x86_64-w64-mingw32-g++")

project(ajp_study)

SET(CMAKE_SYSTEM_NAME Win32)
SET(CMAKE_CROSSCOMPILING 1)
SET(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "-fno-exceptions -fpermissive")
SET(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "-fno-exceptions -fpermissive")
SET_PROPERTY(GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS TRUE)
SET(CMAKE_SHARED_LIBRARY_PREFIX "")

MESSAGE( "64 bits compiler detected" )
SET(CMAKE_SYSTEM_PROCESSOR x86_64)
SET(CMAKE_CXX_FLAGS "-march=x86-64 -O2 -shared -static -static-libgcc -static-libstdc++ -s -fno-rtti -fno-exceptions -fpermissive -std=gnu++11")
SET(CMAKE_SHARED_LIBRARY_SUFFIX "_64.dll")

add_subdirectory(src)
#subdirs(src)

#gentoo linux
target_include_directories(ajp_study PUBLIC /home/alex/.sierracharts_source /usr/x86_64-w64-mingw32/mingw/include/)
#opensuse
#target_include_directories(ajp_study PUBLIC /home/alex/.sierracharts_source /usr/x86_64-w64-mingw32/sys-root/x86_64-w64-mingw32/include)


target_compile_options(ajp_study PUBLIC -fpermissive -Wno-deprecated -Wno-ignored-attributes -fms-extensions)


install(TARGETS ajp_study RUNTIME DESTINATION "specified path to install XYZ" LIBRARY  DESTINATION "specified path to install XYZ")

[2020-09-24 17:45:28]
mbilyanov - Posts: 62
Thanks! I got my CMake setup working.

It was quite difficult to figure that stuff up honestly :)

Do you find that the DLLs you build with CMake are larger than the command line build or the Remote build?

Also did you have to build a cmake toolchain file to make Cmake find the mingw compiler?

Thank you very much for the help! Much appreciated.
[2020-09-27 19:30:50]
AlexPereira - Posts: 195
Do you find that the DLLs you build with CMake are larger than the command line build or the Remote build?

yes, they are larger than when I build them on VS

Also did you have to build a cmake toolchain file to make Cmake find the mingw compiler?

I just reference the mingw compiler and header files in the cmake.

Apart from that, I don't see any differences between compiling on VS or mingw, in terms of instability.

note: that I then reference the "src" subdirectory, and its in there that I add the source files ( which I didn't post :P )
[2020-09-28 13:03:49]
mbilyanov - Posts: 62
Thanks for the info, very helpful.

To post a message in this thread, you need to log in with your Sierra Chart account:

Login

Login Page - Create Account