使用 Cmake & 一键构建我的项目Msbuild(vs2010)与批处理文件
我必须使用一个批处理文件来一键构建一个为 Cmake 制作的项目(已经可以在 Linux 上运行),该批处理文件下载所有第 3 方库并编译它们。 (win64)
- 如果可能的话我不想更改项目CMakeLists.txt。
- 我已经在 VS2010 GUI 中构建了该项目。我必须更改以下内容: 一个。必须更改配置属性-C++-命令行:添加/DWNT /D“CAD_STATIC” b.必须在配置属性-链接器输入-附加依赖项中添加一长串库。 c.为这些库添加库目录 d.添加包含目录。
- 该项目编译并运行正常。
现在我需要仅使用批处理命令进行相同的操作。 我已经使用 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%"
非常感谢所有帮助。我被困住了。谢谢
编辑: 我遇到了另一个问题:
- 如何取消链接由 cmake 自动链接到 project.sln 中的库?
- 将“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)
- If posible i dont want to change projets CMakeLists.txt.
- 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. - 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:
- How can i unlink a library that gets linked in a project.sln automaticly by cmake?
- 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您已经设置了所需的
include
和lib
变量,那么可能缺少的是:那么您应该能够使用
注意,您还拥有
libpath
可用于根据需要设置库的搜索路径。进一步问题的答案
您想要实现的正是 CMake 擅长的场景。你在这里与 CMake 作斗争,而它可能是问题的解决方案:-)
如果我是你,我会编辑 CMakeLists.txt 以包含以下内容:
这都是 Windows 特定的,并且是特定于版本的。您也可以调整 FIND_LIBRARY 调用来满足 Unix/OSX 选项,或者可以将其包装在 IF(WIN32) ... ENDIF() 块中。
如果需要,您还可以对调试版本进行 FIND_LIBRARY 调用(为它们提供不同的变量名称)并添加它们,如下所示:
您还可以通过以下方式从您想要的任何目标中删除您想要的任何库修改
TARGET_LINK_LIBRARIES
调用中传递的库列表。如果您想获取目录中的所有 *.lib 文件,请添加如下内容:
如果您确实使用 GLOB 调用,并且还需要 Debug 和 Release,请确保在每个列表项前加上适当的
debug
或optimized
前缀,例如,如果所有这些都由 CMake 满足,则无需在批处理脚本;你只需这样做:
If you're already setting the required
include
andlib
variables, then probably all that's missing is:then you should be able to use
Note, you've also got
libpath
available to set search paths for the libraries if required.Answers to further questions
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:
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 inIF(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: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:
If you do use the
GLOB
call, and you also need Debug and Release, be sure to prefix each list item withdebug
oroptimized
as appropriate, e.g.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: