使用 Cmake & 一键构建我的项目Msbuild(vs2010)与批处理文件

发布于 2025-01-07 01:51:44 字数 1397 浏览 1 评论 0原文

我必须使用一个批处理文件来一键构建一个为 Cmake 制作的项目(已经可以在 Linux 上运行),该批处理文件下载所有第 3 方库并编译它们。 (win64)

  1. 如果可能的话我不想更改项目CMakeLists.txt。
  2. 我已经在 VS2010 GUI 中构建了该项目。我必须更改以下内容: 一个。必须更改配置属性-C++-命令行:添加/DWNT /D“CAD_STATIC” b.必须在配置属性-链接器输入-附加依赖项中添加一长串库。 c.为这些库添加库目录 d.添加包含目录。
  3. 该项目编译并运行正常。

现在我需要仅使用批处理命令进行相同的操作。 我已经使用 cmake 构建了项目文件:

cmake ..\projectsource -G "Visual Studio 10 Win64" -DGLEW_LIBRARY:FILEPATH=%myroot%\glew\trunk\lib\Release\glew.lib -DGLUT_glut_LIBRARY:FILEPATH=%myroot%\freeglut\trunk\lib\Release\freeglut.lib -DMKL_LIBRARIES:FILEPATH=%myroot%\mkl\em64t\lib\mkl_core.lib -DOpenCascade_INCLUDE_DIR:PATH=%myroot%\OpenCascade

现在我需要一个像“devenv project.sln /useenv”这样的命令,它的作用与我在 #2 下所做的相同。

我尝试使用 env include & lib like:

set "include=%myroot%\glew\trunk\include;%myroot%\freeglut\trunk\include;%myroot%\mkl\include;%myroot%\qt\include;%myroot%\OpenCascade\include\oce;%myroot%\trimo\src\CadModel;%include%"
set "lib=%myroot%\glew\trunk\lib\Release\*.lib;%myroot%\freeglut\trunk\lib\Release\*.lib;%myroot%\mkl\em64t\lib\*.lib;%myroot%"\qt\lib\*.lib;%myroot%\OpenCascade\Win64\lib\*.lib;%lib%"

非常感谢所有帮助。我被困住了。谢谢

编辑: 我遇到了另一个问题:

  1. 如何取消链接由 cmake 自动链接到 project.sln 中的库?
  2. 将“lib=%myroot%\glew\trunk\lib\Release*.lib;链接所有.lib文件,就像你将所有库放入vs2010 gui -链接器输入-附加依赖项中一样?

I have to make a one click build of a projet made for Cmake ( already works on Linux) with a batch file that downloads all the 3rd party libraries and compiles them. (win64)

  1. If posible i dont want to change projets CMakeLists.txt.
  2. I already build the project in VS2010 GUI. and i had to change the folowing:
    a. had to change Configuration properties-C++-Command line: added /DWNT /D "CAD_STATIC"
    b. had to add a long list of libraries in Configuration properties- Linker input- additional dependencies.
    c. add library directories for those libraries
    d. add include directories.
  3. The project compiled and worked ok.

Now i need to make the same with only batch commands.
I already build the project file with cmake with:

cmake ..\projectsource -G "Visual Studio 10 Win64" -DGLEW_LIBRARY:FILEPATH=%myroot%\glew\trunk\lib\Release\glew.lib -DGLUT_glut_LIBRARY:FILEPATH=%myroot%\freeglut\trunk\lib\Release\freeglut.lib -DMKL_LIBRARIES:FILEPATH=%myroot%\mkl\em64t\lib\mkl_core.lib -DOpenCascade_INCLUDE_DIR:PATH=%myroot%\OpenCascade

Now i need a command like "devenv project.sln /useenv " that does the same as the stuff i did under #2.

I tried with a env include & lib like:

set "include=%myroot%\glew\trunk\include;%myroot%\freeglut\trunk\include;%myroot%\mkl\include;%myroot%\qt\include;%myroot%\OpenCascade\include\oce;%myroot%\trimo\src\CadModel;%include%"
set "lib=%myroot%\glew\trunk\lib\Release\*.lib;%myroot%\freeglut\trunk\lib\Release\*.lib;%myroot%\mkl\em64t\lib\*.lib;%myroot%"\qt\lib\*.lib;%myroot%\OpenCascade\Win64\lib\*.lib;%lib%"

All the help is very much appreciated. I'm stuck. Thanks

Edit:
I got another problem:

  1. How can i unlink a library that gets linked in a project.sln automaticly by cmake?
  2. will "lib=%myroot%\glew\trunk\lib\Release*.lib; link all the .lib files like u would get if u put all the libs in a vs2010 gui -Linker input- additional dependencies?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

江南月 2025-01-14 01:51:44

如果您已经设置了所需的 includelib 变量,那么可能缺少的是:

set "cl=/DWNT /DCAD_STATIC"

那么您应该能够使用

devenv project.sln /useenv /build

注意,您还拥有 libpath 可用于根据需要设置库的搜索路径。

进一步问题的答案

  1. 我不知道有什么办法可以做到这一点。
  2. 不,我没有注意到您在最初的问题中这样做了 - 抱歉! LIB 环境变量设置可以找到库的搜索路径,而不是实际库本身的完整路径。

您想要实现的正是 CMake 擅长的场景。你在这里与 CMake 作斗争,而它可能是问题的解决方案:-)

如果我是你,我会编辑 CMakeLists.txt 以包含以下内容:

SET(MY_ROOT <path to %myroot%>)

FIND_LIBRARY(GLEW_LIBRARY glew ${MY_ROOT}/glew/trunk/lib/Release)
IF(NOT GLEW_LIBRARY)
  MESSAGE(FATAL_ERROR "glew.lib not found in ${MY_ROOT}/glew/trunk/lib/Release")
ENDIF()

FIND_LIBRARY(GLUT_glut_LIBRARY freeglut ${MY_ROOT}/freeglut/trunk/lib/Release)
IF(NOT GLUT_glut_LIBRARY)
  MESSAGE(FATAL_ERROR "freeglut.lib not found in ${MY_ROOT}/freeglut/trunk/lib/Release")
ENDIF()

FIND_LIBRARY(MKL_LIBRARIES mkl_core ${MY_ROOT}/mkl/em64t/Release)
IF(NOT MKL_LIBRARIES)
  MESSAGE(FATAL_ERROR "mkl_core.lib not found in ${MY_ROOT}/mkl/em64t/Release")
ENDIF()

INCLUDE_DIRECTORIES(${MY_ROOT}/OpenCascad)

ADD_DEFINITIONS(-DWNT -DCAD_STATIC)

TARGET_LINK_LIBRARIES(<your target>
                      ${GLEW_LIBRARY}
                      ${GLUT_glut_LIBRARY}
                      ${MKL_LIBRARIES}
                      <any other libs...>
                      )

这都是 Windows 特定的,并且是特定于版本的。您也可以调整 FIND_LIBRARY 调用来满足 Unix/OSX 选项,或者可以将其包装在 IF(WIN32) ... ENDIF() 块中。

如果需要,您还可以对调试版本进行 FIND_LIBRARY 调用(为它们提供不同的变量名称)并添加它们,如下所示:

TARGET_LINK_LIBRARIES(<your target>
                      optimized ${GLEW_LIBRARY}
                      optimized ${GLUT_glut_LIBRARY}
                      optimized ${MKL_LIBRARIES}
                      debug ${GLEW_LIBRARY_DEBUG}
                      debug ${GLUT_glut_LIBRARY_DEBUG}
                      debug ${MKL_LIBRARIES_DEBUG}
                      <any other libs...>
                      )

您还可以通过以下方式从您想要的任何目标中删除您想要的任何库修改 TARGET_LINK_LIBRARIES 调用中传递的库列表。

如果您想获取目录中的所有 *.lib 文件,请添加如下内容:

FILE(GLOB ALL_GLEW_LIBS "${MY_ROOT}/glew/trunk/lib/Release/*.lib")
TARGET_LINK_LIBRARIES(<your target> ${ALL_GLEW_LIBS})

如果您确实使用 GLOB 调用,并且还需要 Debug 和 Release,请确保在每个列表项前加上适当的 debugoptimized 前缀,例如,

FOREACH(GLEW_ITR ${ALL_GLEW_LIBS_RELEASE})
  SET(ALL_GLEW_LIBS ${ALL_GLEW_LIBS} optimized ${GLEW_ITR})
ENDFOREACH()

FOREACH(GLEW_ITR ${ALL_GLEW_LIBS_DEBUG})
  SET(ALL_GLEW_LIBS ${ALL_GLEW_LIBS} debug ${GLEW_ITR})
ENDFOREACH()

TARGET_LINK_LIBRARIES(<your target> ${ALL_GLEW_LIBS})

如果所有这些都由 CMake 满足,则无需在批处理脚本;你只需这样做:

devenv project.sln /build

If you're already setting the required include and lib variables, then probably all that's missing is:

set "cl=/DWNT /DCAD_STATIC"

then you should be able to use

devenv project.sln /useenv /build

Note, you've also got libpath available to set search paths for the libraries if required.

Answers to further questions

  1. I don't know of a way to do that.
  2. No. I hadn't noticed you were doing that in your original question - sorry! The LIB env var sets search paths in which libs could be found, it's not for the full path to the actual lib itself.

What you're trying to achieve is exactly the sort of scenario at which CMake excels. You're fighting CMake here when it's probably the solution to the problems :-)

If I were you, I'd edit the CMakeLists.txt to include things like:

SET(MY_ROOT <path to %myroot%>)

FIND_LIBRARY(GLEW_LIBRARY glew ${MY_ROOT}/glew/trunk/lib/Release)
IF(NOT GLEW_LIBRARY)
  MESSAGE(FATAL_ERROR "glew.lib not found in ${MY_ROOT}/glew/trunk/lib/Release")
ENDIF()

FIND_LIBRARY(GLUT_glut_LIBRARY freeglut ${MY_ROOT}/freeglut/trunk/lib/Release)
IF(NOT GLUT_glut_LIBRARY)
  MESSAGE(FATAL_ERROR "freeglut.lib not found in ${MY_ROOT}/freeglut/trunk/lib/Release")
ENDIF()

FIND_LIBRARY(MKL_LIBRARIES mkl_core ${MY_ROOT}/mkl/em64t/Release)
IF(NOT MKL_LIBRARIES)
  MESSAGE(FATAL_ERROR "mkl_core.lib not found in ${MY_ROOT}/mkl/em64t/Release")
ENDIF()

INCLUDE_DIRECTORIES(${MY_ROOT}/OpenCascad)

ADD_DEFINITIONS(-DWNT -DCAD_STATIC)

TARGET_LINK_LIBRARIES(<your target>
                      ${GLEW_LIBRARY}
                      ${GLUT_glut_LIBRARY}
                      ${MKL_LIBRARIES}
                      <any other libs...>
                      )

This is all Windows-specific, and Release-specific. You could adapt the FIND_LIBRARY calls to cater for Unix/OSX options too, or you could wrap this in IF(WIN32) ... ENDIF() blocks.

You could also do FIND_LIBRARY calls for the Debug versions too if required (giving them different variable names) and adding them like:

TARGET_LINK_LIBRARIES(<your target>
                      optimized ${GLEW_LIBRARY}
                      optimized ${GLUT_glut_LIBRARY}
                      optimized ${MKL_LIBRARIES}
                      debug ${GLEW_LIBRARY_DEBUG}
                      debug ${GLUT_glut_LIBRARY_DEBUG}
                      debug ${MKL_LIBRARIES_DEBUG}
                      <any other libs...>
                      )

You'll also be able to remove whatever libraries you want from whatever targets you want by modifying the list of libs passed in the TARGET_LINK_LIBRARIES call(s).

If you want to grab all *.lib files in a directory, add something like this:

FILE(GLOB ALL_GLEW_LIBS "${MY_ROOT}/glew/trunk/lib/Release/*.lib")
TARGET_LINK_LIBRARIES(<your target> ${ALL_GLEW_LIBS})

If you do use the GLOB call, and you also need Debug and Release, be sure to prefix each list item with debug or optimized as appropriate, e.g.

FOREACH(GLEW_ITR ${ALL_GLEW_LIBS_RELEASE})
  SET(ALL_GLEW_LIBS ${ALL_GLEW_LIBS} optimized ${GLEW_ITR})
ENDFOREACH()

FOREACH(GLEW_ITR ${ALL_GLEW_LIBS_DEBUG})
  SET(ALL_GLEW_LIBS ${ALL_GLEW_LIBS} debug ${GLEW_ITR})
ENDFOREACH()

TARGET_LINK_LIBRARIES(<your target> ${ALL_GLEW_LIBS})

If all this is then catered for by CMake, you don't need to set any env vars in the batch script; you just do:

devenv project.sln /build
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文