Allowing inline assembly on cmake build - c++

I'm trying to build an exe using cmake and no IDE for this project https://github.com/cyberquarks/fubi
This is the cmake file:
cmake_minimum_required(VERSION 3.10)
project(Fubi)
set(SOURCES DbgHelpDll.cpp Fubi.cpp SysExports.cpp fubimain.cpp stdafx.cpp)
add_executable(Fubi ${SOURCES})
target_link_libraries(Fubi PRIVATE DbgHelp)
set_property(TARGET Fubi PROPERTY ENTRY_POINT "fubimain.cpp")
include_directories("C:/local/boost_1_73_0")
link_directories(C:/local/boost_1_73_0/lib64-msvc-14.2)
set(CMAKE_SYSTEM_VERSION 6.0)
While I build it with:
$ mkdir build
$ cd build
$ cmake -G "Visual Studio 16 2019" ..
$ cmake --build .
During the build process it throws this error:
Fubi.cpp
C:\fubi\Fubi.cpp(40,5): error C4235: nonstandard extension used: '__asm' keyword not supported on this architecture [C:\fubi\build\Fubi.vcxproj]
Which is this code:
DWORD Fubi::Call_cdecl( const void* args, size_t sz, DWORD func )
{
DWORD rc;
__asm
{
// ...
}
return ( rc );
}
How can I use cmake to build the executable and allow the inline assembly code to compile also?
Update:
The same project works when using CLion IDE to build and run it.
Toolchains:
Debug config:
Cmake settings:
Run config:

Related

Setting up stdlib path while compiling with mingw on linux

I am trying to build my c++ CMake project on linux with mingw. CMakeLists.txt consists of (for understanding):
Setting up project info:
project(<project name> LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
Setting up TRY_COMPILE target type:
set(CMAKE_TRY_COMPILE_TARGET_TYPE "STATIC_LIBRARY")
Setting up boost:
set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME OFF)
find_package(Boost COMPONENTS system program_options REQUIRED)
Including subdirectories in which there is nothing about mingw:
add_subdirectory(<some_subdirectory>)
...
At the time of build process I see the following compilation command in the log:
/usr/bin/x86_64-w64-mingw32-g++ -I/usr/include -I<user include 1> -I<user include 2> -O3 -DNDEBUG -std=gnu++20 -MD -MT CMakeFiles/common.dir/<source>.cpp.o -MF <source>.cpp.o.d -o <source>.cpp.o -c <project path>/<source>.cpp
After that goes a compiler error message with the following beginning:
[build] In file included from /usr/x86_64-w64-mingw32/include/c++/12.2.0/cstdint:41,
[build] from /usr/x86_64-w64-mingw32/include/c++/12.2.0/bits/char_traits.h:731,
[build] from /usr/x86_64-w64-mingw32/include/c++/12.2.0/ios:40,
[build] from /usr/x86_64-w64-mingw32/include/c++/12.2.0/ostream:38,
[build] from <project path>/<source>.hpp:5,
[build] from <project path>/<source>.cpp:1:
[build] /usr/include/stdint.h:90:33: error: conflicting declaration «typedef long unsigned int uintptr_t»
[build] 90 | typedef unsigned long int uintptr_t;
[build] | ^~~~~~~~~
...
According to the internet this error message is connected with the different mingw standard library implementation.
I guess in a compile command there should somehow be -I/usr/x86_64-w64-mingw32/include on a place of -I/usr/include in a compilation command. If I am right there, the question is "How to change standard include directory for mingw build spicifically?". If I am not right there, then how to solve the problem with project building?
PS: The project builds using both clang++ and g++.
You probably need a toolchain file for your cross-compiler.
But I'd suggest using quasi-msys2, which takes care of this, and also gives you access to prebuilt libraries for MinGW (Boost in your case).
Install dependencies (this assumes Ubuntu, for other distributions adjust as needed)
# Install Clang and LLD
bash -c "$(wget -O - https://apt.llvm.org/llvm.sh)"
# Install other dependencies
sudo apt install make wget tar zstd gpg wine
Install and run quasi-msys2:
git clone https://github.com/holyblackcat/quasi-msys2
cd quasi-msys2/
make install _gcc _boost
env/shell.sh
cd ..
Now build your repo:
git clone https://github.com/gogagum/archiever
cd archiever/
git checkout dev
git submodule update --init --recursive
cmake -B build/
cmake --build build/ -j4
I tried running the test app too:
cd build/numerical/
./numerical_encoder.exe --input-file Makefile # This uses Wine automatically

install CMake package on windows visual studio problem (find_package)

I made a simple program using glfw in Linux. and I want to build it in windows now.
when I install glfw in Linux, I did the following steps.
install CMake.
download glfw source code.
create a build folder in the source code folder.
do "cmake ../" in the build folder
do "make"
do "make install"
Then in CMakeLists.txt file:
find_package( glfw3 3.3 REQUIRED )
add_executable(main main.cpp)
target_link_libraries(main glfw)
in source code:
#define GLFW_INCLUDE_NONE
#include <GLFW/glfw3.h>
//use glfw
So I want to do the same thing in windows visual studio.
I did the following steps.
install CMake
download glfw source file.
create a build folder in the source code folder.
do "cmake ../" in the build folder
go to build folder, open GLFW project in visual studio using Administrator rights.
build ALL_BUILD in visual studio.
As a result, I got C:\Program Files (x86)\GLFW folder. there is include, lib, config files.
And then I created a new CMake project.
CMake File:
cmake_minimum_required (VERSION 3.8)
set (CMAKE_PREFIX_PATH "C:\Program Files (x86)\GLFW\lib\cmake\glfw3")
find_package( glfw3 3.3 REQUIRED )
include_directories( "C:\Program Files (x86)\GLFW" )
project ("glfw_test")
add_executable (glfw_test "glfw_test.cpp" "glfw_test.h")
And error message saying:
CMake Error at C:\Users\home\source\repos\glfw_test\CMakeLists.txt:3 (set):
Syntax error in CMake code at
C:/Users/home/source/repos/glfw_test/CMakeLists.txt:3
when parsing string
C:\Program Files (x86)\GLFW\lib\cmake\glfw3
Invalid character escape '\P'. glfw_test C:\Users\home\source\repos\glfw_test\CMakeLists.txt 3
Questions.
Why does include, lib files are installed directly in program files (x86)?
How can I do "make install" in windows?
TL;DR answers:
Because you did not specified an installation prefix.
Add CMAKE_INSTALL_PREFIX to your GLFW CMake command, e.g.
cmake -S <sourcedir> -B <builddir> -DCMAKE_INSTALL_PRFIX=<yourinstalldir>
cmake --build <builddir> --target install --config Release
If you do not specify an installation prefix to your cmake command on Windows it is set to C:\Program Files (x86) for 32bit builds and to C:\Program Files for 64bit builds.
Do not hardcode CMAKE_PREFIX_PATH into your CMakeLists.txt. Explicitly specify what generator and architecture you want to use for your build. Add it to your CMake command line as argument, e.g.
cmake -S <sourcedir> -B <builddir> -G "Visual Studio 16 2019" -A Win32 -DCMAKE_PREFIX_PATH=<yourglfwrootinstalldir>
And your CMakeLists.txt file should look as follows:
cmake_minimum_required (VERSION 3.8)
project ("glfw_test")
find_package( glfw3 3.3 REQUIRED )
add_executable (glfw_test glfw_test.cpp glfw_test.h)
target_link_libraries(glfw_test PRIVATE glfw)

gtest installed with conan: undefined reference to `testing::internal::GetBoolAssertionFailureMessage`

I use cmake to build my project and conan to install Google Test as dependency:
conanfile.txt
[requires]
gtest/1.7.0#lasote/stable
[generators]
cmake
[imports]
bin, *.dll -> ./build/bin
lib, *.dylib* -> ./build/bin
CMakeLists.txt
PROJECT(MyTestingExample)
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
INCLUDE(conanbuildinfo.cmake)
CONAN_BASIC_SETUP()
ADD_EXECUTABLE(my_test test/my_test.cpp)
TARGET_LINK_LIBRARIES(my_test ${CONAN_LIBS})
test/my_test.cpp
#include <gtest/gtest.h>
#include <string>
TEST(MyTest, foobar) {
std::string foo("foobar");
std::string bar("foobar");
ASSERT_STREQ(foo.c_str(), bar.c_str()); // working
EXPECT_FALSE(false); // error
}
Build
$ conan install --build=missing
$ mkdir build && cd build
$ cmake .. && cmake --build .
I can use ASSERT_STREQ, but if I use EXPECT_FALSE I get an unexpected error:
my_test.cpp:(.text+0x1e1): undefined reference to `testing::internal::GetBoolAssertionFailureMessage[abi:cxx11](testing::AssertionResult const&, char const*, char const*, char const*)'
collect2: error: ld returned 1 exit status
What's wrong with my configuration?
The issue is that you are installing conan dependencies using the default settings (which is build type Release):
$ conan install --build=missing
# equivalent to
$ conan install -s build_type=Release ... --build=missing
The default settings can be seen in your conan.conf file
Then, you are using cmake in a nix system with the default build type which is Debug, which is a single-conf environment (opposed to multi-configuration Debug/Release environments, as Visual Studio), so when you are doing:
$ cmake .. && cmake --build .
# equivalent to
$ cmake .. -DCMAKE_BUILD_TYPE=Debug && cmake --build .
The incompatibility of Debug/Release build leads to that unresolved issue. So the solution would be to use the same build type that matches your installed dependencies:
$ cmake .. -DCMAKE_BUILD_TYPE=Release && cmake --build .
If using multi-configuration environments like Visual Studio, the correct way would be:
$ cmake .. && cmake --build . --config Release
On my side, I get this issue because being on Redhat 7 then with an old libstdc++.
Too old for conan default packages binaries/libraries.
I have fixed that by rebuilding gtest with '--build gtest' arg.

Cmake:build YASM source files

I am using CMake 3.4.1 to generate and build Visual Studio 2013 64bit C++ solution.One of the project also contains .asm files which we compile in VisualStudio with yasm assembler as lib.How do I configure CMake to use yasm for those files?I haven't found any documentation with example of how to set it up.
Have a look a the following example:
cmake_minimum_required(VERSION 3.0)
project(YasmCmake)
find_program(YASM_EXE NAMES yasm)
add_custom_command(OUTPUT hello.o COMMAND ${YASM_EXE}
ARGS -f elf64 -o hello.o ${CMAKE_CURRENT_SOURCE_DIR}/hello.asm)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
add_library(Hello hello.o)
set_target_properties(Hello PROPERTIES LINKER_LANGUAGE CXX)
Of course you need to specify the flags for yasm depending on your platform.

c++ compile multiple cpp files using cmakefile.txt in linux

I am quite new to linux and c++.. i have couple of cpp file and cmakefile.txt in my source folder. how can i compile in ubuntu with g++ (multiple cpp files)
I have this CMakeList.txt
project(Test)
# link_libraries($Nest_LIBRARIES})
subdirs(
#
engine
options
ui
# jni
)
#build the Test library
add_library(test STATIC
options/command_line_options.cpp
options/options_map.cpp
utility/timer.cpp
utility/generics/any.cpp
util/hdfs.cpp
logger/logger.cpp
logger/backtrace.cpp
)
requires_core_deps(test)
INSTALL(TARGETS
test ARCHIVE DESTINATION lib)
This is CMake (tutorial). Some say it simplifies build process.
Create makefiles from CMake metafiles: cmake . -G "Unix
Makefiles"
Run make: make -j2 install