dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
14.96k stars 4.65k forks source link

CMake commandline #52511

Open maxild opened 3 years ago

maxild commented 3 years ago

I am trying to build src/corelcr using CLion IDE (CLion need cmake options to build). And I need a bit of help with the correct commandline.

I have succesfully run the build on the commandline, so the toolchain/requirements for my debian based Linux dev box are in place.

I am kind of guessing the correct options for CMake. This is what I am trying to execute (in the repo root)

$ cmake -DCMAKE_C_COMPILER=/usr/bin/clang-9 \
  -DCMAKE_CXX_COMPILER=/usr/bin/clang++-9 \
  -G "Unix Makefiles" \
  -DCMAKE_BUILD_TYPE=DEBUG \
  -DCMAKE_INSTALL_PREFIX=/home/maxfire/repos/github.com/dotnet/runtime/artifacts/bin/coreclr/Linux.x64.Debug \
  -DCMAKE_USER_MAKE_RULES_OVERRIDE= \
  -DCLR_ENG_NATIVE_DIR="/home/maxfire/repos/github.com/dotnet/runtime/eng/native" \
  -DCLR_CMAKE_PGO_INSTRUMENT=0 \
  -DCLR_CMAKE_OPTDATA_PATH=/home/maxfire/.nuget/packages/optimization.linux-x64.pgo.coreclr/99.99.99-master-20200806.6 \
  -DCLR_CMAKE_PGO_OPTIMIZE=1 \
  -DCLR_REPO_ROOT_DIR="/home/maxfire/repos/github.com/dotnet/runtime" \
  -S /home/maxfire/repos/github.com/dotnet/runtime/src/coreclr \
  -B /home/maxfire/repos/github.com/dotnet/runtime/artifacts/obj/coreclr/Linux.x64.Debug src/coreclr

I get this error

Detected Linux x86_64
-- Configuring done
CMake Error at src/pal/src/eventprovider/lttngprovider/CMakeLists.txt:55 (add_library):
  Cannot find source file:

    /home/maxfire/repos/github.com/dotnet/runtime/src/coreclr/version.c

  Tried extensions .c .C .c++ .cc .cpp .cxx .cu .mpp .m .M .mm .h .hh .h++
  .hm .hpp .hxx .in .txx .f .F .for .f77 .f90 .f95 .f03 .ispc

CMake Error at /home/maxfire/repos/github.com/dotnet/runtime/eng/native/functions.cmake:430 (add_executable):
  Cannot find source file:

    /home/maxfire/repos/github.com/dotnet/runtime/src/coreclr/version.c

  Tried extensions .c .C .c++ .cc .cpp .cxx .cu .mpp .m .M .mm .h .hh .h++
  .hm .hpp .hxx .in .txx .f .F .for .f77 .f90 .f95 .f03 .ispc
Call Stack (most recent call first):
  src/hosts/unixcorerun/CMakeLists.txt:9 (_add_executable)

CMake Error at /home/maxfire/repos/github.com/dotnet/runtime/eng/native/functions.cmake:430 (add_executable):
  Cannot find source file:

    /home/maxfire/repos/github.com/dotnet/runtime/src/coreclr/version.c

  Tried extensions .c .C .c++ .cc .cpp .cxx .cu .mpp .m .M .mm .h .hh .h++
  .hm .hpp .hxx .in .txx .f .F .for .f77 .f90 .f95 .f03 .ispc
Call Stack (most recent call first):
  src/hosts/unixcoreconsole/CMakeLists.txt:9 (_add_executable)

CMake Error at /home/maxfire/repos/github.com/dotnet/runtime/eng/native/functions.cmake:443 (add_library):
  Cannot find source file:

    /home/maxfire/repos/github.com/dotnet/runtime/src/coreclr/version.c

.
.
.
.
.
.

CMake Error at /home/maxfire/repos/github.com/dotnet/runtime/eng/native/functions.cmake:443 (add_library):
  No SOURCES given to target: clrgc
Call Stack (most recent call first):
  /home/maxfire/repos/github.com/dotnet/runtime/eng/native/functions.cmake:460 (_add_library)
  src/gc/CMakeLists.txt:110 (add_library_clr)

CMake Generate step failed.  Build files cannot be regenerated correctly.

I am new to CMake, and therefore sorry if the question is unclear in any way.

dotnet-issue-labeler[bot] commented 3 years ago

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

ghost commented 3 years ago

Tagging subscribers to this area: @hoyosjs See info in area-owners.md if you want to be subscribed.

Issue Details
I am trying to build `src/corelcr` using CLion IDE (CLion need cmake options to build). And I need a bit of help with the correct commandline. I have succesfully run the build on the commandline, so the toolchain/requirements for my debian based Linux dev box are in place. I am kind of guessing the correct options for CMake. This is what I am trying to execute (in the repo root) ```bash $ cmake -DCMAKE_C_COMPILER=/usr/bin/clang-9 \ -DCMAKE_CXX_COMPILER=/usr/bin/clang++-9 \ -G "Unix Makefiles" \ -DCMAKE_BUILD_TYPE=DEBUG \ -DCMAKE_INSTALL_PREFIX=/home/maxfire/repos/github.com/dotnet/runtime/artifacts/bin/coreclr/Linux.x64.Debug \ -DCMAKE_USER_MAKE_RULES_OVERRIDE= \ -DCLR_ENG_NATIVE_DIR="/home/maxfire/repos/github.com/dotnet/runtime/eng/native" \ -DCLR_CMAKE_PGO_INSTRUMENT=0 \ -DCLR_CMAKE_OPTDATA_PATH=/home/maxfire/.nuget/packages/optimization.linux-x64.pgo.coreclr/99.99.99-master-20200806.6 \ -DCLR_CMAKE_PGO_OPTIMIZE=1 \ -DCLR_REPO_ROOT_DIR="/home/maxfire/repos/github.com/dotnet/runtime" \ -S /home/maxfire/repos/github.com/dotnet/runtime/src/coreclr \ -B /home/maxfire/repos/github.com/dotnet/runtime/artifacts/obj/coreclr/Linux.x64.Debug src/coreclr ``` I get this error ``` Detected Linux x86_64 -- Configuring done CMake Error at src/pal/src/eventprovider/lttngprovider/CMakeLists.txt:55 (add_library): Cannot find source file: /home/maxfire/repos/github.com/dotnet/runtime/src/coreclr/version.c Tried extensions .c .C .c++ .cc .cpp .cxx .cu .mpp .m .M .mm .h .hh .h++ .hm .hpp .hxx .in .txx .f .F .for .f77 .f90 .f95 .f03 .ispc CMake Error at /home/maxfire/repos/github.com/dotnet/runtime/eng/native/functions.cmake:430 (add_executable): Cannot find source file: /home/maxfire/repos/github.com/dotnet/runtime/src/coreclr/version.c Tried extensions .c .C .c++ .cc .cpp .cxx .cu .mpp .m .M .mm .h .hh .h++ .hm .hpp .hxx .in .txx .f .F .for .f77 .f90 .f95 .f03 .ispc Call Stack (most recent call first): src/hosts/unixcorerun/CMakeLists.txt:9 (_add_executable) CMake Error at /home/maxfire/repos/github.com/dotnet/runtime/eng/native/functions.cmake:430 (add_executable): Cannot find source file: /home/maxfire/repos/github.com/dotnet/runtime/src/coreclr/version.c Tried extensions .c .C .c++ .cc .cpp .cxx .cu .mpp .m .M .mm .h .hh .h++ .hm .hpp .hxx .in .txx .f .F .for .f77 .f90 .f95 .f03 .ispc Call Stack (most recent call first): src/hosts/unixcoreconsole/CMakeLists.txt:9 (_add_executable) CMake Error at /home/maxfire/repos/github.com/dotnet/runtime/eng/native/functions.cmake:443 (add_library): Cannot find source file: /home/maxfire/repos/github.com/dotnet/runtime/src/coreclr/version.c . . . . . . CMake Error at /home/maxfire/repos/github.com/dotnet/runtime/eng/native/functions.cmake:443 (add_library): No SOURCES given to target: clrgc Call Stack (most recent call first): /home/maxfire/repos/github.com/dotnet/runtime/eng/native/functions.cmake:460 (_add_library) src/gc/CMakeLists.txt:110 (add_library_clr) CMake Generate step failed. Build files cannot be regenerated correctly. ``` I am new to CMake, and therefore sorry if the question is unclear in any way.
Author: maxild
Assignees: -
Labels: `area-Infrastructure-coreclr`, `untriaged`
Milestone: -
am11 commented 3 years ago
  Cannot find source file:

   /home/maxfire/repos/github.com/dotnet/runtime/src/coreclr/version.c

version.c is one of the file the common script generates in pre-configuration steps at the following locations (based on the availability of msbuild):

artifacts/obj/linux-x64.Release/version.c
artifacts/obj/coreclr/Linux.x64.Release/version.c
artifacts/obj/native/Linux-x64-Release/version.c
artifacts/obj/native/net6.0-Linux-Release-x64/version.c

(all these files have same content for a given build and can be consolidated into just one file..)

In your setup for coreclr (only?), you can generate it as:

# shell script
_versionContents="static char sccsid[] __attribute__((used)) = \"@(#)Version 42.42.42.42424 @Commit: $(git -C $HOME/repos/github.com/dotnet/runtime rev-parse HEAD)\";"
printf "%s\n" "$_versionContents" > "$HOME/repos/github.com/dotnet/runtime/artifacts/obj/coreclr/Linux.x64.Release/version.c"
maxild commented 3 years ago

Okay I managed to build coreclr (jit, vm, gc etc) from inside CLion by copying one of (the generated) version.c into ./src/coreclr. I know it is stupid, but it was the only way I could get CLion to build using clang-9 toolchain and below CMake options.

BUT I am in a bad(!) state

$ git status --short
?? src/coreclr/.cmake/
?? src/coreclr/compile_commands.json
?? src/coreclr/src/ToolBox/superpmi/mcs/mcs
?? src/coreclr/src/ToolBox/superpmi/superpmi-shim-collector/libsuperpmi-shim-collector.so
?? src/coreclr/src/ToolBox/superpmi/superpmi-shim-counter/libsuperpmi-shim-counter.so
?? src/coreclr/src/ToolBox/superpmi/superpmi-shim-simple/libsuperpmi-shim-simple.so
?? src/coreclr/src/ToolBox/superpmi/superpmi/superpmi
?? src/coreclr/src/binder/libv3binder_crossgen.a
?? src/coreclr/src/debug/createdump/config.h
?? src/coreclr/src/debug/createdump/createdump
?? src/coreclr/src/debug/createdump/createdump.dbg
?? src/coreclr/src/debug/daccess/libdaccess.a
?? src/coreclr/src/debug/dbgutil/libdbgutil.a
?? src/coreclr/src/debug/di/libcordbdi.a
?? src/coreclr/src/debug/ee/dac/libcordbee_dac.a
?? src/coreclr/src/debug/runtimeinfo/libruntimeinfo.a
?? src/coreclr/src/debug/shim/libdebugshim.a
?? src/coreclr/src/dlls/dbgshim/dbgshim.exports
?? src/coreclr/src/dlls/dbgshim/libdbgshim.so
?? src/coreclr/src/dlls/dbgshim/libdbgshim.so.dbg
?? src/coreclr/src/dlls/mscordac/libmscordaccore.so
?? src/coreclr/src/dlls/mscordac/libmscordaccore.so.dbg
?? src/coreclr/src/dlls/mscordac/mscordac.exports
?? src/coreclr/src/dlls/mscordbi/libmscordbi.so
?? src/coreclr/src/dlls/mscordbi/libmscordbi.so.dbg
?? src/coreclr/src/dlls/mscordbi/mscordbi.exports
?? src/coreclr/src/dlls/mscoree/coreclr/coreclr.exports
?? src/coreclr/src/dlls/mscoree/coreclr/libcoreclr.so
?? src/coreclr/src/dlls/mscoree/coreclr/libcoreclr.so.dbg
?? src/coreclr/src/dlls/mscoree/coreclr/libcoreclr_static.a
?? src/coreclr/src/dlls/mscorpe/libmscorpe.a
?? src/coreclr/src/dlls/mscorrc/mscorrc.cpp
?? src/coreclr/src/dlls/mscorrc/mscorrc.rc.i
?? src/coreclr/src/gc/config.gc.h
?? src/coreclr/src/gc/libclrgc.so
?? src/coreclr/src/gc/libclrgc.so.dbg
?? src/coreclr/src/gcinfo/gcinfo_arm64/libgcinfo_arm64.a
?? src/coreclr/src/gcinfo/libgcinfo_crossgen.a
?? src/coreclr/src/hosts/unixcoreconsole/coreconsole
?? src/coreclr/src/hosts/unixcoreconsole/coreconsole.dbg
?? src/coreclr/src/hosts/unixcorerun/corerun
?? src/coreclr/src/hosts/unixcorerun/corerun.dbg
?? src/coreclr/src/hosts/unixcoreruncommon/config.h
?? src/coreclr/src/hosts/unixcoreruncommon/libunixcoreruncommon.a
?? src/coreclr/src/ilasm/ilasm
?? src/coreclr/src/ilasm/ilasm.dbg
?? src/coreclr/src/ildasm/exe/dasm_rc.cpp
?? src/coreclr/src/ildasm/exe/dasm_rc.rc.i
?? src/coreclr/src/ildasm/exe/ildasm
?? src/coreclr/src/ildasm/exe/ildasm.dbg
?? src/coreclr/src/inc/clretwallmain.h
?? src/coreclr/src/inc/clreventpipewriteevents.h
?? src/coreclr/src/inc/clrproviders.h
?? src/coreclr/src/inc/clrxplatevents.h
?? src/coreclr/src/inc/dacmoduleindex.h
?? src/coreclr/src/inc/dbimoduleindex.h
?? src/coreclr/src/inc/etmdummy.h
?? src/coreclr/src/inc/libredefines.inc
?? src/coreclr/src/inc/palredefines.inc
?? src/coreclr/src/inc/runtimemoduleindex.h
?? src/coreclr/src/jit/clrjit.exports
?? src/coreclr/src/jit/protononjit/libprotononjit.so
?? src/coreclr/src/jit/protononjit/libprotononjit.so.dbg
?? src/coreclr/src/jit/standalone/libclrjit.so
?? src/coreclr/src/jit/standalone/libclrjit.so.dbg
?? src/coreclr/src/libraries-native/System.Globalization.Native/
?? src/coreclr/src/md/compiler/libmdcompiler-dbi.a
?? src/coreclr/src/md/compiler/libmdcompiler_crossgen.a
?? src/coreclr/src/md/compiler/libmdcompiler_dac.a
?? src/coreclr/src/md/compiler/libmdcompiler_ppdb.a
?? src/coreclr/src/md/datasource/libmddatasource_dbi.a
?? src/coreclr/src/md/enc/libmdruntimerw-dbi.a
?? src/coreclr/src/md/enc/libmdruntimerw_crossgen.a
?? src/coreclr/src/md/enc/libmdruntimerw_dac.a
?? src/coreclr/src/md/enc/libmdruntimerw_ppdb.a
?? src/coreclr/src/md/hotdata/libmdhotdata_crossgen.a
?? src/coreclr/src/md/hotdata/libmdhotdata_dac.a
?? src/coreclr/src/md/hotdata/libmdhotdata_ppdb.a
?? src/coreclr/src/md/runtime/libmdruntime-dbi.a
?? src/coreclr/src/md/runtime/libmdruntime_crossgen.a
?? src/coreclr/src/md/runtime/libmdruntime_dac.a
?? src/coreclr/src/md/runtime/libmdruntime_ppdb.a
?? src/coreclr/src/md/staticmd/libmdstaticapi.a
?? src/coreclr/src/md/staticmd/libmdstaticapi_ppdb.a
?? src/coreclr/src/nativeresources/libnativeresourcestring.a
?? src/coreclr/src/pal/src/config.h
?? src/coreclr/src/pal/src/eventprovider/lttngprovider/libcoreclrtraceptprovider.so
?? src/coreclr/src/pal/src/eventprovider/lttngprovider/libcoreclrtraceptprovider.so.dbg
?? src/coreclr/src/pal/src/eventprovider/lttngprovider/libeventprovider.a
?? src/coreclr/src/pal/src/eventprovider/lttngprovider/lttng/
?? src/coreclr/src/pal/src/libcoreclrpal.a
?? src/coreclr/src/palrt/libpalrt.a
?? src/coreclr/src/tools/aot/jitinterface/libjitinterface.so
?? src/coreclr/src/tools/aot/jitinterface/libjitinterface.so.dbg
?? src/coreclr/src/tools/crossgen/crossgen
?? src/coreclr/src/tools/crossgen/crossgen.dbg
?? src/coreclr/src/unwinder/libunwinder_dac.a
?? src/coreclr/src/utilcode/libutilcode_crossgen.a
?? src/coreclr/src/utilcode/libutilcode_dac.a
?? src/coreclr/src/utilcode/libutilcodestaticnohost.a
?? src/coreclr/src/vm/crossgen/libcee_crossgen.a
?? src/coreclr/src/vm/crossgen/libcorelib_crossgen.a
?? src/coreclr/src/vm/eventing/eventpipe/eventpipe/
?? src/coreclr/src/vm/libcee_dac.a
?? src/coreclr/src/zap/libcorzap_crossgen.a
?? src/coreclr/version.c

So please if anybody can tell me how to setup CLion to build coreclr without hacking and polutting the GIT workspace

This is the config

image

where cmake options in the dialog are given by

-G "Unix Makefiles"
-DCMAKE_BUILD_TYPE=DEBUG
-DCMAKE_INSTALL_PREFIX=/home/maxfire/repos/github.com/dotnet/runtime/artifacts/bin/coreclr/Linux.x64.Debug
-DCMAKE_USER_MAKE_RULES_OVERRIDE= 
-DCLR_ENG_NATIVE_DIR="/home/maxfire/repos/github.com/dotnet/runtime/eng/native"
-DCLR_CMAKE_OPTDATA_PATH=/home/maxfire/.nuget/packages/optimization.linux-x64.pgo.coreclr/99.99.99-master-20200806.6
-DCLR_CMAKE_PGO_OPTIMIZE=1
-DCLR_CMAKE_PGO_OPTIMIZE=1
-DCLR_REPO_ROOT_DIR="/home/maxfire/repos/github.com/dotnet/runtime"
-S /home/maxfire/repos/github.com/dotnet/runtime/src/coreclr
-B /home/maxfire/repos/github.com/dotnet/runtime/artifacts/obj/coreclr/Linux.x64.Debug
huoyaoyuan commented 6 months ago

CMakePresets.json is now officially supported by CMake. CLion also claims to support it.

I've added CMakePresets.json for coreclr directory and Visual Studio can successfully build the folder. Can you try if CLion builds well?

Well I only added configuration for Windows. I have uncommited configuration for Linux and WSL in my user presets.