I'm trying to build libc++ with LLVM/Clang. I'm running onto a couple of problems. First, though LLVM/Clang supports both Makefiles and Cmake, the libc++ project abandoned Makefile support. So I'm stuck with Cmake for this particular component. Second, LLVM/Clang build infrastructure does not configure libc++, so its not à la carte like I thought. So I need to turn some knobs to make things work.
Here's what the tree looks like I'm working with. Sources are under llvm (in-tree), while artifacts are under build (out-of-tree).
Working directory
|
+- build (artifacts and staging)
|
+- llvm (source tree)
|
+- tools
| |
| +- Compiler Front End (Clang)
|
+- projects
|
+- Compiler RT
|
+- libcxx
|
+- libcxx ABI
I need to run Cmake and tell it to configure what's in llvm/projects/libcxx, and tell Cmake to generate Makefiles that build and stage into the appropriate directory under build. Everything else can use Makefiles. (Its unclear to me what the "appropriate directory" is since the project's documentation does not tell me. I'll cross that bridge next, but I'd like to start with build).
I looked at the Cmake man pages, and I can't find a way to specify those simple requirements. For example, I can find ARCHIVE_OUTPUT_DIRECTORY and CMAKE_Fortran_MODDIR_FLAG, but I don't see where I can specify that everything goes to build. (Configure and Makefiles are pretty easy - I cd into the directory and run configure; or I just say make -f llvm/projects/libcxx/Makefile and things just work).
How do I tell Cmake to configure what's in llvm/projects/libcxx, and how do I tell it to generate Makefiles that specify build as the build and output directory?
You can't configure subdirectory because parent CMakeLists.txt might contain necessary configuration code for subdirectory CMakeLists.txt.
What you can do is to configure everything, but run make only for libcxx:
cd build/projects/libcxx && make
This would build libcxx and all it's dependencies, but stuff from tools, for instance, wouldn't be built.
Related
We have multiple libraries in different folder, The main application needs to build those libraries in other folders and install them to output folder and then the main application needs to link to libraries to build executable.
I am able to build the libraries present in other folders using add_subdirectory() in a loop, but I am not able to install them to output folder by main cmake file. Could anyone help me out on this.
The main application needs to build those libraries in other folders and install them to output folder and then the main application needs to link to libraries to build executable.
It is not necessary in CMake to install libraries in order to link to them. You can build the libraries and have your main executable link to them without installing the libraries. When you need to install your application as a whole, you can install libraries along with the executable if needed i.e. if the libraries are shared ones and not static ones.
One example of how you can organize things: assume you have the following structure in your project:
CMakeLists.txt # root of project
|
|--lib
| |--CMakeLists.txt # library subproject
|
|--app
|--CMakeLists.txt # app subproject
Then your root CMakeLists.txt can look like this:
project(MyProject)
add_subdirectory(lib)
add_subdirectory(app)
The lib subproject's CMakeLists.txt can look like this:
project(MyLib)
set(SOURCES <...>) # specify library's sources
add_library(${PROJECT_NAME} ${SOURCES})
set(MyLib ${PROJECT_NAME} CACHE INTERNAL "")
The last line in the snippet above is aimed to make MyLib variable available everywhere within the project. I found this trick here and used it successfully in my projects. Maybe there are better options here, if anyone knows them, feel free to suggest.
The app's CMakeLists.txt can then look like this:
project(MyApp)
set(SOURCES <...>) # specify app's sources
add_executable(${PROJECT_NAME} ${SOURCES})
target_link_libraries(${PROJECT_NAME} ${MyLib})
I haven't covered the installation here but it's actually straightforward: if your libraries are static ones, you only need to install the executable using install TARGETS. If your libraries are shared ones, you need to install them along with the executable.
I have a project that uses SCons to generate platform dependent source files which are compiled together with other shipped source files into static libraries and linked into the final executable, and that's it, no project files are generated for my IDE (Xcode)
I managed to add SCons as an external build system in a new Xcode project to build and debug the executable
What I want now is to customize the source code and add a few libraries removing Scons altogether as external build system. Scons is not practical in my case, too slow, and I don't want to mess with the scripts.
So the question is whether there is a feature in SCons to skip the build process but just generate the platform dependent source files?
Edit:
I would like to make some customizations to the project and not mess with SCons at least until I need to do pull requests, that was my workfow with a previous project that used CMake to generate the Xcode project, SCons would require to modify the scripts.
Yes, you can specify the targets that you want to get built on the command-line explicitly:
scons lib1/source1.cpp sourceb.cpp
would be an example.
Since you mentioned that SCons would be "too slow" for you, how exactly did you measure that (see http://scons.org/wiki/WhySconsIsNotSlow and http://scons.org/wiki/GoFastButton )?
Overriding Export() in SConstruct like the the code from below and adding the parameter skip_build to the script, which sets the value of __SkipBuild, I was able to skip the build process altogether (i.e. compiling and linking), generating only the platform dependent sources
SConstruct
__Export = Export
__CommandsList = ['CC','CXX','AR','RANLIB','AS','LINK'] # The commands to skip from the build process
__SkipBuild = False
def Export(*vars, **kw):
for var in vars:
locals()[var] = call_stack[-1].globals[var]
if (call_stack[-1].globals['__SkipBuild']):
for command in __CommandsList:
if locals()[var].has_key(command):
locals()[var][command] = 'echo ' + locals()[var][command]
call_stack[-1].globals.update(kw)
__Export(locals(), kw)
I would like to create a HDF5 dataset from a fortran90 program compiled with intel fortran 2011 on Windows 7 using Visual Studio 2010
Can I use prebuilt binaries or how do I build new ones
I build from source, the available built binaries use the MS C/C++ compiler while I want to build with the Intel compiler, and they are built with Intel Fortran v12.x while I'm using v14.x. I won't say that you can't use the binaries, but I've had enough of a struggle in the past to persuade me to build my own.
I've also had struggles with trying to build them directly from VS and now use CMake. Your first step ought to be to install CMake and figure out how to use it. You don't need much knowledge of the tool and the effort will be repaid several times over. You can, for example, also use CMake to build Szip and Zlib, if you want them. An increasing amount of this sort of software is made available with CMake support so you won't necessarily only use it for HDF5. For example, I use CMake to build VTK for Windows too.
Once you've done that and generated the solution/project files with CMake you can load up the solution in VS and build ALL_BUILD. This generally works smoothly, though I have found that some projects need to have their linkages adjusted and sometimes I get spurious flags in the command-lines sent to the compilers. Then, running VS in administrator mode, you can build the pseudo-target INSTALL.
I see that HDF5 1.8.12 is now available, I'll download and build it, let you know how I get on.
Compiling and Linking
If you just want to use HDF5 include the line
USE, NON_INTRINSIC :: hdf5
at the appropriate place in your source file(s). Then, under Project Properties | Fortran | General | Additional Include Directories insert the path to the location of hdf5.mod. That should get you compiling.
To link, under Project | Properties | Linker | General | Additional Library Directories insert the path the location of the .lib files. Then, under Project | Properties | Linker | Input | Additional Dependencies insert hdf5_fortran.lib.
You should then be able to compile and link your program. If you want to use additional facilities, such as the HDF5 Table Interface, then use h5tb and figure out the linkages.
And consult the documentation. See, for example, ../HDF5-1.8.12/release_docs/USING_HDF5_VS.txt
I succeeded thanks to High Performance Mark:
Here was what I did (not sure that everything is necessary):
Download and install cmake
Download and install HDF5 [Windows (32-bit), Compilers: CMake VS 2010 C, C++, IVF 12, RWDI]
Set environment variable: HDF5_DIR=C:/Program Files/HDF_Group/HDF5/1.8.x/cmake/hdf5
Download HDF5 source
Make empty build folder
Run CMake(cmake-gui) from start menu
Set source (HDF5 source) and destination (empty build folder)
Configure
Set generator to Visual Studio 10
Specify native compilers [C:"", C++:"", Fortran: "<..>\ifort.exe"]
Check: BUILD_SHARED_LIBS and HDF5_BUILD_FORTRAN
Configure
Configure
Generate
Open <..>\build\HDF5.sln in Visual Studio 2010
build project ALL_BUILD
And finally
Create new project with a Fortran example
Linked the generated libs exactly as High Performance Mark describes
I hope some else can use the reciepe.
Thanks again
I would like to have a tools repository structured like so:
tools
|-- gnu
| `-- gcc
| |-- 4.6.0
| `-- 4.6.2
|-- microsoft
| `-- stylecop
| `-- 4.6.2.0
...
So that every developer across the company has the same tools during the build process.
Is it possible to create a 'build jail' in this way?
I don't know how to get the GNU tool-chain into a repository this way?
Does anyone have any experience with this? I've heard of chroot build jails.
I have a requirement to build on Windows and Linux.
The Debian (and thereby Ubuntu) people have developed the excellent pbuilder package for such issues. It originally creates a tarball with a minimal Debian environment that is unpacked into a chroot, but can easily be adapted for your requirements.
I was using classic Unix Makefile generator until I found a webpage explaining CMake could produce a nice xcode project file using "cmake -G Xcode" so I ran that command in my source directory and I get a nice xcode project. This is great but I'm facing some drawback and was wondering if there are solutions to these :
now I can't build out of tree using unix makefiles (I use to run cmake ../myproj in a build dir and then make command) this doesn't work anymore (I suppose temp files in the project dir are responsible)
some of my headers are generated by cmake (myproj.h.in became myproj.h and is include in some tests for example) but I can't find those files in the xcode project I get.
Thanks in advance for any good advice on how I can combine xcode project and unix makefile to be able to use both.
I found the answer by myself (I mean asking the good person) :
Use 2 separate build directories for each type of build files. This will ensure each build directory has the correct build files and generated files for its use.
In the add_executable() command, in addition to the source files also include the headers and generated headers for those to show up in Xcode.
You can use xcodebuild to still have a proper Xcode project and build it from the command line/shell script/Makefile, e.g.
xcodebuild -project MyProject.xcodeproj -target MyTarget -configuration Release