I've noticed that when I try to build a c++ project with some flags, e.g., "-Wall -Wmissing-include-dirs", bazel gives a missing include directory.
The project structure is the following
root
├── src
│ ├── CMakeLists.txt
│ ├── BUILD.bazel
│ └── main.cpp
├── CMakeLists.txt
├── README.md
└── WORKSPACE
src/main.cpp
#include<iostream>
int main()
{
std::cout << "Compiled\n";
return 0;
}
src/CMakeLists.txt
cmake_minimum_required(VERSION 3.10)
project(main)
set(CMAKE_CXX_FLAGS "-Wall -Wmissing-include-dirs -Ipath/that/doesnt/exist")
set(SOURCES main.cpp)
add_executable( main ${SOURCES})
src/BUILD.bazel
cc_binary(
name = "main",
srcs = ["main.cpp"],
copts = ["-Ipath/that/doesnt/exist -Wall -Wmissing-include-dirs"],
)
When compiling main.cpp with cmake (mkdir build && cd build && cmake .. && make), I see an expected warning for path/that/doesnt/exist (since it doesn't exist), e.g.,
cc1plus: warning: path/that/doesnt/exist: No such file or directory [-Wmissing-include-dirs]
but when I compile with bazel (bazel build //src:main) I get an additional missing include
cc1plus: warning: path/that/doesnt/exist: No such file or directory [-Wmissing-include-dirs]
cc1plus: warning: bazel-out/k8-fastbuild/bin/external/bazel_tools: No such file or directory [-Wmissing-include-dirs]
Question 1: Where does bazel-out/k8-fastbuild/bin/external/bazel_tools come from and why is it missing?
Question 2: How do I write my bazel build so that this warning doesn't appear?
If I were to remove the inclusion of path/that/doesnt/exist from the cmake and bazel builds, and compile with flags -Wall -Werror -Wmissing-include-dirs, then the cmake build succeeds, but the bazel one fails.
Minimum working example found here: https://github.com/btk-learning/learn-to-build-cmake-bazel
Related
I have tbb downloaded and placed in my repository directory:
> tree deps/tbb/ -d
deps/tbb/
├── bin
├── cmake
│ └── templates
├── include
│ ├── serial
│ │ └── tbb
│ └── tbb
│ ├── compat
│ ├── internal
│ └── machine
└── lib
├── ia32
│ └── gcc4.8
└── intel64
└── gcc4.8
In my CMakeLists.txt I have tried this:
include_directories("deps/tbb/include")
find_library(TBB_LIB
NAMES
tbbbind_debug
tbbbind
tbb_debug
tbbmalloc_debug
tbbmalloc_proxy_debug
tbbmalloc_proxy
tbbmalloc
tbb_preview_debug
tbb_preview
tbb
HINTS "${CMAKE_PREFIX_PATH}/deps/tbb/lib/intel64/gcc4.8"
)
add_executable(${PROJECT_NAME}
src/main.cpp
)
target_link_libraries(${PROJECT_NAME} PUBLIC ${TBB_LIB})
But building with cmake, linker throws this error:
/usr/lib64/gcc/x86_64-suse-linux/7/../../../../x86_64-suse-linux/bin/ld: cannot find -lTBB_LIB-NOTFOUND
collect2: error: ld returned 1 exit status
I couldn't figure out what is missing. Thanks.
Update
This commit resolves the previous error:
- HINTS "${CMAKE_PREFIX_PATH}/deps/tbb/lib/intel64/gcc4.8"
+ HINTS "deps/tbb/lib/intel64/gcc4.8"
But, new errors are thrown:
undefined reference to `tbb::interface7::internal::task_arena_base::internal_current_slot()'
Update
Other than find_library, what CMake tools are available to link to TBB shared libraries?
I have tried some CMake tools, but I cannot figure out how to link to TBB *.so files correctly!
TBB has native CMake support. On my system with the Intel oneAPI installed, the config package is installed here:
/opt/intel/oneapi/tbb/latest/lib/cmake/tbb/TBBConfig.cmake
Therefore, I just need to add /opt/intel/oneapi/tbb/latest to my CMAKE_PREFIX_PATH. In my CMakeLists.txt, I wrote this:
cmake_minimum_required(VERSION 3.21)
project(test-tbb)
find_package(TBB REQUIRED)
add_library(main main.cpp)
target_link_libraries(main PRIVATE TBB::tbb)
target_compile_features(main PRIVATE cxx_std_11)
TBB provides the IMPORTED target TBB::tbb, which is what you should link to.
main.cpp is just the source from here: https://stackoverflow.com/a/36782794/2137996
Build like so:
$ cmake -G Ninja -S . -B build -DCMAKE_PREFIX_PATH=/opt/intel/oneapi/tbb/latest
$ cmake --build build --verbose
[1/2] /usr/bin/c++ -isystem /opt/intel/oneapi/tbb/2021.3.0/include -MD -MT CMakeFiles/main.dir/main.cpp.o -MF CMakeFiles/main.dir/main.cpp.o.d -o CMakeFiles/main.dir/main.cpp.o -c /home/alex/test2/main.cpp
[2/2] : && /usr/bin/cmake -E rm -f libmain.a && /usr/bin/ar qc libmain.a CMakeFiles/main.dir/main.cpp.o && /usr/bin/ranlib libmain.a && :
Inspired by #AlexReinking answer, here is the final implementation:
project(my-cpp-service VERSION 0.1.0)
# Equivalent to command-line option of `-DCMAKE_PREFIX_PATH=...`
list(APPEND CMAKE_MODULE_PATH "deps/tbb/cmake/")
find_package(TBB REQUIRED)
add_executable(${PROJECT_NAME}
src/main.cpp
)
target_link_libraries(${PROJECT_NAME} PUBLIC
TBB::tbb
)
This post helped me solved the problem:
https://stackoverflow.com/a/41909627/3405291
The errors got resolved by:
include_directories("deps/tbb/include")
# https://stackoverflow.com/a/41909627/3405291
find_library(LIB_TBB NAMES tbb HINTS "deps/tbb/lib/intel64/gcc4.8")
find_library(LIB_TBBbind NAMES tbbbind HINTS "deps/tbb/lib/intel64/gcc4.8")
find_library(LIB_TBBmalloc_proxy NAMES tbbmalloc_proxy HINTS "deps/tbb/lib/intel64/gcc4.8")
find_library(LIB_TBBmalloc NAMES tbbmalloc HINTS "deps/tbb/lib/intel64/gcc4.8")
find_library(LIB_TBB_preview NAMES tbb_preview HINTS "deps/tbb/lib/intel64/gcc4.8")
add_executable(${PROJECT_NAME}
src/main.cpp
)
target_link_libraries(${PROJECT_NAME} PUBLIC
${LIB_TBB}
${LIB_TBBbind}
${LIB_TBBmalloc_proxy}
${LIB_TBBmalloc}
${LIB_TBB_preview}
)
I am compiling an application using CMake 3.16.3 and G++ 9.3 on Ubuntu 20.04. This is the current source directory:
. (this is called MyApp)
├── src
│ ├── /* source files */
│ └── CMakeLists.txt
├── tests
│ ├── /* source files */
│ └── CMakeLists.txt
├── build-release
│ └── pgo /* folder for .gcda files */
├── build_release.sh
└── CMakeLists.txt*
I am setting the flags in CMakeLists.txt (the root one also marked with asterisk) as follows:
set(MYAPP_PGO "-fprofile-dir=${MYAPP_PGO} -fprofile-generate=${MYAPP_PGO}")
// apply flags
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DNDEBUG -O3 -march=native -flto ${MYAPP_PGO}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${MYAPP_PGO}")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${MYAPP_PGO}")
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} ${MYAPP_PGO}")
add_subdirectory(src)
add_subdirectory(tests)
No flags are being set in src/CMakeLists.txt and tests/CMakeLists.txt.
MYAPP_PGO is set in bash and is the absolute path of build-release/pgo. I have a script (build_release.sh) that builds the program:
# excluded other lines and flags for brevity
cd build-release
cmake -DMYAPP_PGO="$(pwd)/pgo/" ..
make -j1
After the profile run, I see that there are multiple files in build-release/pgo, one for each cpp file in src and test, such as
#home#johndoe#MyApp#build-release#src#CMakeFiles#MYAPPLICATION_myapp.dir#sample_source.cpp.gcda
However, when compiling again with
// this is a multithreaded program
set(MYAPP_PGO "-fprofile-dir=${MYAPP_PGO} -fprofile-use=${MYAPP_PGO} -fprofile-correction")
// apply flags
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DNDEBUG -O3 -march=native -flto ${MYAPP_PGO}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${MYAPP_PGO}")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${MYAPP_PGO}")
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} ${MYAPP_PGO}")
add_subdirectory(src)
add_subdirectory(tests)
I get a warning stating that there are missing profile files:
/home/johndoe/MyApp/src/sample_source.cpp: In function ‘_GLOBAL__sub_I_sample_source.cpp’:
/home/johndoe/MyApp/src/sample_source.cpp:215:1: warning: ‘/home/johndoe/MyApp/src/sample_source.cpp/build-release/pgo//#home#johndoe#MyApp#build-release#src#CMakeFiles#MYAPPLICATION_myapp.dir#sample_source.cpp.gcda’ profile count data file not found [-Wmissing-profile]
215:1 refers to the last character in this source file.
I have tested the speed of the program with and without PGO and have seen no improvement. Although PGO is not guaranteed to bring any speed ups, I tend to believe that PGO did not work as expected here. Am I doing something wrong?
For anyone wondering...
I did not write the original build system of the project. I discovered that it compiled one executable and one library from the same source. Whilst the executable was profiled and recompiled successfully (PGO was done flawlessly), the library was not used anywhere. Hence the missing profile files. Because the profiler outputs extremely long names, I thought the error came from the executable. Thank you all for the help.
I'm trying to print coverage with lcov on a C++ project that is using Catch2 for tests. I'm able to run my tests and get results. However, I'm unable to get any coverage. This is the error that is shown.
Capturing coverage data from .
Found gcov version: 9.3.0
Using intermediate gcov format
Scanning . for .gcda files ...
geninfo: WARNING: no .gcda files found in . - skipping!
Finished .info-file creation
Combining tracefiles.
Reading tracefile coverage.base
lcov: ERROR: no valid records found in tracefile coverage.base
My current toolchain is WSL. I'm using Conan for dependency management. The solution has the following structure:
my project/
├─ build/
│ ├─ build files
├─ core/
│ ├─ library files
├─ main/
│ ├─ main runtime
├─ tests/
│ ├─ test runtime/
├─ CMakeLists.txt
Each folder has it's CMakeLists.txt file and is identified as a target. I'm also using this CMake Module to register a target for coverage.
My root CMakeLists.txt looks like this:
cmake_minimum_required(VERSION 3.16)
project(my-project)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_FLAGS "-O0")
include(build/conanbuildinfo.cmake)
conan_basic_setup()
add_subdirectory(core)
option(BUILD_TESTING "Builds only the test executable." OFF)
option(CODE_COVERAGE "Collect coverage from test library" OFF)
if(BUILD_TESTING)
enable_testing()
add_subdirectory(tests)
add_test(NAME project-tests COMMAND ./bin/tests)
if(CODE_COVERAGE)
include(CodeCoverage.cmake)
append_coverage_compiler_flags()
setup_target_for_coverage_lcov(NAME coverage EXECUTABLE ./bin/tests BASE_DIRECTORY ../coverage)
endif()
else()
add_subdirectory(main)
endif()
To get my coverage, I'm using the following commands (on build/).
cmake .. -DCODE_COVERAGE=ON -DBUILD_TESTING=ON -DCMAKE_BUILD_TYPE=Debug
make
make coverage
From what I understand, it seems to be missing some files necessary for coverage information, but I don't know how to make them. From what I've looked online, I have all the necessary compiler flags. I can't see what is wrong/missing in here.
I believe you forgot to add appropriate flags
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage")
set(CMAKE_CXX_FLAGS " ${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage")
This question already has an answer here:
LNK2019 - unresolved external symbol - C++ - SDL2 Library [duplicate]
(1 answer)
Closed 2 years ago.
I'm having problems linking SDL2 to my project, which probably are because I'm new to CMake, and I don't fully know how to create new projects with it. Every time and method I've tried to fix this problem has resulted in one of the following problems:
"Cannot locate WinMain#16"
Multiple undefined reference errors
undefined reference to `SDL_main`
I have attempted to use find_package, linking directly to files, linking to library files, following tutorials (for example https://trenki2.github.io/blog/2017/06/02/using-sdl2-with-cmake/), searching for answers (most of them talk about using find_package which I can't get to work) (for example Using SDL2 with CMake).
Project dependencies
SDL 2.0.12, CMake 3.17.0, 7-Zip, mingw32-make, wget
The project is supposed to be cross-platform, but the main devenv is Windows 10. All scripts are run from the root folder "vivaria".
Project structure
vivaria/
├── build/
│ └── [cmake build files]
├── buildtools/
│ └── SDL2/SDL2-2.0.12/lib/x86 (and x64)
│ ├── SDL2.lib
│ └── SDL2main.libs
├── deploy/
├── resources/
├── scripts/
│ ├── build_windows_debug_x86.bat
│ └── install_buildtools_windows.bat
└── src/
├── CMakeLists.txt
└── vivaria.cpp
build_windows_debug_x86.bat
cmake -G "MinGW Makefiles" -S .\src\ -B .\build\ -DCMAKE_BUILD_TYPE=Debug
cd .\build\
mingw32-make
vivaria.cpp
#include <iostream>
#include "SDL.h"
int main() {
if (SDL_Init(SDL_INIT_VIDEO) != 0){
std::cout << "Hello world" << std::endl;
return 1;
}
SDL_Quit();
return 0;
}
CMakeLists.txt: undefined reference to SDL_main
cmake_minimum_required(VERSION 3.17)
project(Vivaria VERSION 1.0.0)
set(CMAKE_CXX_GLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -lmingw32")
# set(CMAKE_EXE_LINKER_FLAGS "-static-libgcc -static-libstdc++")
set(INCLUDE_DIR "${CMAKE_SOURCE_DIR}/../buildtools")
set(SDL2_DIR "${INCLUDE_DIR}/SDL2/SDL2-2.0.12")
set(SDL2_INCLUDE_DIRS "${SDL2_DIR}/include")
set(CMAKE_BINARY_DIR "${CMAKE_SOURCE_DIR}/../deploy")
# Support both 32 and 64 bit builds
if (${CMAKE_SIZEOF_VOID_P} MATCHES 8)
set(SDL2_LIBRARIES "${SDL2_DIR}/lib/x64/SDL2main.lib;${SDL2_DIR}/lib/x64/SDL2.lib")
else ()
set(SDL2_LIBRARIES "${SDL2_DIR}/lib/x86/SDL2main.lib;${SDL2_DIR}/lib/x86/SDL2.lib")
endif ()
# link dependencies
include_directories(${SDL2_INCLUDE_DIRS})
link_directories(${SDL2_LIBRARIES})
# Project files and linking
set(SOURCES vivaria.cpp)
add_executable(${PROJECT_NAME} vivaria.cpp)
target_link_libraries(${PROJECT_NAME} ${SDL2_LIBRARIES})
Console output
F:\Koodit\Vivaria\build>mingw32-make
[ 50%] Linking CXX executable Vivaria.exe
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: F:/Koodit/Vivaria/src/../buildtools/SDL2/SDL2-2.0.12/lib/x86/SDL2main.lib(Win32/Release/SDL_windows_main.obj):(.text[_main_getcmdline]+0xd1): undefined reference to `SDL_main'
collect2.exe: error: ld returned 1 exit status
CMakeFiles\Vivaria.dir\build.make:104: recipe for target 'Vivaria.exe' failed
mingw32-make[2]: *** [Vivaria.exe] Error 1
CMakeFiles\Makefile2:91: recipe for target 'CMakeFiles/Vivaria.dir/all' failed
mingw32-make[1]: *** [CMakeFiles/Vivaria.dir/all] Error 2
Makefile:99: recipe for target 'all' failed
mingw32-make: *** [all] Error 2
install_buildtools_windows.bat
set SDL2=SDL2-devel-2.0.12-VC.zip
set DOWNLOAD_DIR=%cd%\buildtools
set OUTPUT_DIR=%cd%\buildtools\SDL2
wget "https://libsdl.org/release/%SDL2%" -P "%DOWNLOAD_DIR%"
7z x "%DOWNLOAD_DIR%\%SDL2%" -y -o%OUTPUT_DIR%
del /F /Q %DOWNLOAD_DIR%\%SDL2%
As you can see I'm still "a bit" new to CMake, but I'm trying to learn.
Oof. Everything about your CMakeLists is wrong.
Never set CMAKE_CXX_FLAGS in your CMakeLists.txt
Never use include_directories or link_directories
Never use target_link_libraries without a visibility specifier.
Never set paths to libs manually.
Don't set your target names equal to the project name. It's pointless complexity and bad style.
This is all you need:
cmake_minimum_required(VERSION 3.16)
project(Vivaria VERSION 1.0.0)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED YES)
set(CMAKE_CXX_EXTENSIONS OFF)
find_package(SDL2 REQUIRED)
add_executable(Vivaria vivaria.cpp)
target_link_libraries(Vivaria PRIVATE SDL2::SDL2)
Your code also has an error. You need to add this line to the top of your file
#define SDL_MAIN_HANDLED
First, use vcpkg to install SDL2. Then, with the above changes, this compiles and runs for me using the commands:
> mkdir build
> cd build
> cmake -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=X:/path/to/vcpkg.cmake ..
Thanks to Tsyvarev!
Setting the macro SDL_MAIN_HANDLED in the source file fixed the problem.
#define SDL_MAIN_HANDLED // insert this
#include <iostream>
#include "SDL.h"
int main() {
if (SDL_Init(SDL_INIT_VIDEO) != 0){
std::cout << "Hello world" << std::endl;
return 1;
}
std::cout << "Hello world 2" << std::endl;
SDL_Quit();
return 0;
}
I have a simple c++ project which includes eigen. I'm able to compile the project on my own machine but having trouble to compile it to webassembly with emscripten.
Project structure:
.
├── CMakeLists.txt
├── include
│ └── HelloWasm
│ └── my_lib.h
└── src
├── main.cpp
└── my_lib.cpp
File contents:
CMakeLists.txt
cmake_minimum_required( VERSION 3.0 )
project( HelloWasm )
# flags
# include files
include_directories( ./include .include/HelloWasm ./src )
# target
add_executable( HelloWasm ./src/main.cpp ./src/my_lib.cpp )
# 3rd party libs
find_package(Eigen3 REQUIRED NO_MODULE)
include_directories(${EIGEN3_INCLUDE_DIR})
include/HelloWasm/my_lib.h
#include <iostream>
#include <Eigen/Dense>
using namespace std;
using Eigen::MatrixXd;
class MyLib
{
private:
protected:
public:
MyLib()
{
}
~MyLib()
{
}
void eigen_test();
};
src/main.cpp
#include <iostream>
#include "HelloWasm/my_lib.h"
using namespace std;
int main()
{
MyLib my_lib;
my_lib.eigen_test();
}
src/my_lib.cpp
#include "HelloWasm/my_lib.h"
void MyLib::eigen_test()
{
MatrixXd m(2, 2);
m(0, 0) = 3;
m(1, 0) = 2.5;
m(0, 1) = -1;
m(1, 1) = m(1, 0) + m(0, 1);
cout << '\n'
<< m << endl;
}
Compiling the project successfully locally:
mkdir build && cd build
cmake ..
make
➜ ./HelloWasm
3 -1
2.5 1.5
Errors when trying to compile to webassemply
(I tried following the steps provided in the emscripten docs)
mkdir build && cd build
cmake ..
emcmake cmake ..
output:
configure: cmake .. -DCMAKE_TOOLCHAIN_FILE=/Users/me/programming/emsdk/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake -DCMAKE_CROSSCOMPILING_EMULATOR="/Users/me/programming/emsdk/node/12.9.1_64bit/bin/node"
-- Configuring done
-- Generating done
CMake Warning:
Manually-specified variables were not used by the project:
CMAKE_TOOLCHAIN_FILE
-- Build files have been written to: /Users/me/programming/sandbox/cpp_sandbox/so_question_project/build
Now running make:
➜ emmake make
make: make
Scanning dependencies of target HelloWasm
[ 33%] Building CXX object CMakeFiles/HelloWasm.dir/src/main.cpp.o
[ 66%] Building CXX object CMakeFiles/HelloWasm.dir/src/my_lib.cpp.o
[100%] Linking CXX executable HelloWasm
[100%] Built target HelloWasm
Obviously that did not create a .wasm file...
Doing the following:
em++ CMakeFiles/HelloWasm.dir/src/main.cpp.o CMakeFiles/HelloWasm.dir/src/my_lib.cpp.o -o helloWasm.js
output:
em++: warning: CMakeFiles/HelloWasm.dir/src/main.cpp.o is not a valid input file [-Winvalid-input]
em++: warning: CMakeFiles/HelloWasm.dir/src/my_lib.cpp.o is not a valid input file [-Winvalid-input]
em++: error: no input files
note that input files without a known suffix are ignored, make sure your input files end with one of: ('.c', '.i', '.cpp', '.cxx', '.cc', '.c++', '.CPP', '.CXX', '.C', '.CC', '.C++', '.ii', '.m', '.mi', '.mm', '.mii', '/dev/null', '.bc', '.o', '.obj', '.lo', '.dylib', '.so', '.a', '.ll', '.h', '.hxx', '.hpp', '.hh', '.H', '.HXX', '.HPP', '.HH')
What am I missing here...?
Change:
em++ CMakeFiles/HelloWasm.dir/src/main.cpp.o CMakeFiles/HelloWasm.dir/src/my_lib.cpp.o -o helloWasm.js
To:
em++ CMakeFiles/HelloWasm.dir/src/main.cpp.o CMakeFiles/HelloWasm.dir/src/my_lib.cpp -o helloWasm.js
Emscripten can't compile my_lib.cpp.o because it's already compiled to machine code (it's an object file). You have to use a .cpp file, not .cpp.o.
I have a suggestion for you.
First, you can put your lib files (my_lib.h and my_lib.cpp) on same directory.
Second, you can create a folder for your applications (HelloWasm) and put your executable codes (main.cpp) in this folder.
Finally, you can create CMakeLists.txt file for each folder.
This is your new directory tree:
.
├── CMakeLists.txt
├── Applications
│ └── HelloWasm
│ ├── CMakeLists.txt
│ └── main.cpp
└── Libraries
├── CMakeLists.txt
├── my_lib.h
└── my_lib.cpp
CMakeLists.txt (the first one) :
cmake_minimum_required(VERSION 3.0)
project(LIBRARYANDAPPS)
#This function is starting build and looking all folders.
function( start_build )
file( GLOB_RECURSE components "${CMAKE_SOURCE_DIR}/*/CMakeLists.txt" )
foreach( component ${components} )
get_filename_component( path ${component} PATH )
add_subdirectory( ${path} )
endforeach( )
endfunction( )
start_build()
CMakeLists.txt (for HelloWasm):
#You can add Emscripten flags like this.
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} \
-std=c++11 --bind \
-s USE_WEBGL2=1 -s FULL_ES3=1 --memory-init-file 0")
find_package(Eigen3 REQUIRED NO_MODULE)
include_directories(${EIGEN3_INCLUDE_DIR})
include_directories("${CMAKE_SOURCE_DIR}/Libraries")
ADD_EXECUTABLE(HelloWasm main.cpp)
TARGET_LINK_LIBRARIES(HelloWasm MyLib Eigen)
CMakeLists.txt (for Library):
find_package(Eigen3 REQUIRED NO_MODULE)
include_directories(${EIGEN3_INCLUDE_DIR})
ADD_LIBRARY(MyLib STATIC my_lib.cpp my_lib.h)
TARGET_LINK_LIBRARIES(MyLib Eigen)
With these edits, you can create bigger projects, libraries. And I think more useful like this.