How to compile modules inside directories (aka with dots in its name) - module

I would like to import a module as
Require Import Foo.Bar.
Given that I have a file Bar.v inside directory Foo.
I am currently compiling this module with:
$ coqc Foo/Bar.v
When I try to Require Import Foo.Bar. I get this error:
Error: The file Foo/Bar.vo contains library Bar
and not library Foo.Bar

You can do this by using the -R option. Compile your file using coqc -R Foo Foo Foo/Bar.v. The -R flag takes two options: (1) the directory you want to add to your include path, and (2) the name you want to give in in the module namespace.
Later on, if you have some other file Baz.v that uses Foo.Bar, compile it using coqc -R Foo Foo Baz.v.
If you have one big project with many subdirectories, you can use coq_makefile, you can also use the -R in the toplevel to make the names consistent for all subdirectories once and for all. Have a look for instance at the Makefile for our project, with its corresponding coq_makefile source.

Related

changing the project name on every build

I have a custom makefile used for versioning.
It basically sets the version according to some predefined rules and fetching info from git repo
I want to intergrate it with the esp32 cmake project.
Till now i managed to run the makefile from the cmakelist.txt file using
add_custom_target(versioning ALL
COMMAND ${CMAKE_COMMAND} -P "sometext.cmake"
)
and in the sometext.cmake i am calling the makefile which sets a FirmwareVersion variable.
I use this variable in the root cmakelist.txt to set the project(${FirmwareVersion})
But i want the project name to be changed every time firmwareVersion is changed.
But project command is only if there is some changes in cmakelist.txt
Any help to accomplish it is highly apreciated.
Thanks
The project() command also has VERSION named keyword. That is what you actually want. You can store the actual version in some extra CMake file (like version.cmake)
set(VERSION_FROM_GIT "1.2.3+9a6b075")
and use like
include("${CMAKE_CURRENT_SOURCE_DIR}/version.cmake")
project(MyProject VERSION ${VERSION_FROM_GIT} ...)
...
It's up to you how you going to update this file... There are plenty of ways to do that.
You can tell cmake to do a reconfiguration if a file changes. Since the .git directory contains a HEAD file either denoting the commit hash of the detached head or a reference to the file containing the commit hash, you could these files as configuration dependencies.
# assume the .git directory is in the same directory as this CMakeLists.txt
set(GIT_HEAD_FILE "${CMAKE_CURRENT_SOURCE_DIR}/.git/HEAD")
# add dependency to the head itself
set_property(DIRECTORY . APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS "${GIT_HEAD_FILE}")
file(READ "${GIT_HEAD_FILE}" GIT_HEAD_CONTENT)
if (GIT_HEAD_CONTENT MATCHES "ref: +([^ ]+)")
# add file referenced in HEAD for non detached head state
set_property(DIRECTORY . APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/.git/${CMAKE_MATCH_1}")
endif()
... your logic depending on the git version goes here ...
This gets a bit more complicated if you intend on using your repository as submodule of another repo, since the .git directory is not necessarily located in the submodule.

Meson build: Add dependency path for executable manually

What I'd like to do, is rather easy: Compile a project using the Meson build system + manually including a dependency.
However, there's one dependency, which I do not want to install to /usr/lib, due to System Integrity Protection on Mac. (I know I can turn this off; I don't want to.)
So basically I wanna do:
g++ -L[path_to_lib] [files...] but use meson instead of g++.
However, this seems to be super complicated. After doing some research and unsuccessfully adding
cc = meson.get_compiler('c')
dep = cc.find_library('granite' dirs: [ [path_to_dep] ])
to my meson.build file (which doesn't work, as it handles libraries, not dependencies)
I'm left feeling rather dumb.
Please help!
I know I could just add the relevant path to $PATH, but that is more than overkill and I refuse to believe that there isn't another nice quick way to do so. (As is with the ancient c compiler...)
You should be able to solve your problem without modifying meson.build file (I mean leave granite as ordinary dependency). meson uses pkg-config to search for dependencies, so if you add your non-standard path containing granite package config file to PKG_CONFIG_PATH it will find it. And in this case granite package config file should be correct, of course, i.e. contain correct library and header paths, which should be correct if you configure installation of granite with something like:
# Configure:
$ cmake -DCMAKE_INSTALL_PREFIX=/some/path...
# Build:
$ make
# Install (need sudo?):
$ make install
$ export PKG_CONFIG_PATH=/some/path...:$PKG_CONFIG_PATH
granite_dep = dependency('granite')
my_app = executable('my_app',
dependencies : [granite_dep]
...
However, note that in case of find_library() according to reference manual:
The result object can be used just like the return value of dependency
So, it should work:
granite_dep = cc.find_library('granite', dirs : [path])
executable(..., dependencies : granite_dep)
But, I recommend standard way that utilizes pkg-config, because granite can also have dependencies that you will not be able to automatically pick up this way.

Cmake add_definition to compute absolute path of a file

I have a project where compilation and test running is managed by cmake. The test involves reading a special test file, which is located in different directory from the test file and would need an absolute path. I define the path to the testfile in my tests.cpp like this:
#define ARPA_TESTFILEPATH "/path/to/project/root/arpa/toy_lm.arpa"
I want to pass that define via cmake so that other people can checkout the project and run the tests without modifying anything. I know I can add defines in cmake via:
add_definitions(-DARPA_TESTFILE="/path/to/project/root/arpa/toy_lm.arpa")
However how can I add a variable to the define so that it automatically resolves the path? I am looking for something like:
add_definitions(-DARPA_TESTFILE="$(PROJECTROOT)/arpa/toy_lm.arpa")
Is that possible?
EDIT:
Basically say the project is checked out in a directory
/home/pesho/project
the project directory contains CMakeLists.txt. How could I get the absolute path to the projects directory so that I can include it in a variable and then define it during compilation.
Put the path in a CACHE variable. It make it accessible through ccmake command :
set(PATH_TO_ARPA "${DEFAULT_PATH_TO_ARPA}" CACHE FILEPATH "Description of the option")
See documentation : http://www.cmake.org/cmake/help/v3.0/command/set.html

How to get the list of files that will be installed when installing a CMake component

Is there any way to know programmatically (in CMake) what files will be installed if a COMPONENT is installed (something like a get_property of component)?
Currently, I am installing a COMPONENT to a temporary location for packaging (not using CPack for packaging) and then packaging using custom commands. I'm invoking the following command during packaging in CMake.
cmake -DCOMPONENT=my_test_component
-DCMAKE_INSTALL_PREFIX=${TMP_PACKAGING_ROOT}
-P ${CMAKE_BINARY_DIR}/cmake_install.cmake
I wanted to know if it is possible to get the list of files so that I can only include those files explicitly in the package? Or possibly add them as outputs to the custom command?
The only way to know it seems to be by reading the install_manifest_${component}.txt which will have all the list of files that will be installed when we install a CMake component.
CMake does not have a get_property() function (or similar equivalent) for the COMPONENT descriptor; CMake properties are reserved for targets, directories, source files, etc. (full list here). However, there are ways to programmatically list the files associated with a COMPONENT.
In general, the COMPONENT option is often specified with install() to essentially categorize targets into specific install groups. These "component" groupings are typically used with CPack:
For certain kinds of binary installers (including the graphical installers on macOS and Windows), CPack generates installers that allow users to select individual application components to install. The contents of each of the components are identified by the COMPONENT argument of CMake’s INSTALL command.
However, if you're not using CPack, CMake still honors the COMPONENT groupings; they are just harder to manage. You can iterate through each install rule in the cmake_install.cmake file, and filter out those that pertain a specific COMPONENT. This must be done after the CMake generate stage (after the cmake_install.cmake file is generated), as the full path to each target is not known at configure time. As the question above suggests, you can create a custom target to call the generated CMake install script yourself, filtering based on COMPONENT:
# Define install rule for MyExecutable target (grouping it in MyComponent).
install(TARGETS MyExecutable
DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/installation
CONFIGURATIONS Release
COMPONENT MyComponent
)
# Add custom target to filter and install MyComponent files.
add_custom_target(MyInstallTarget
COMMAND "${CMAKE_COMMAND}" -DCOMPONENT=MyComponent -P cmake_install.cmake
DEPENDS MyExecutable
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)
After building this custom target (e.g. make MyInstallTarget), the manifest file install_manifest_MyComponent.txt will be created, containing a list of all the files associated with that COMPONENT. (It is not necessarily created by building the CMake-predefined INSTALL target.)
However, this manifest file is not very useful by itself. To use it programmatically, we can expand our custom target to read these component-specific files into a CMake variable.
add_custom_target(MyInstallTarget
COMMAND "${CMAKE_COMMAND}" -DCOMPONENT=MyComponent -P cmake_install.cmake
COMMAND "${CMAKE_COMMAND}" -DCOMPONENT=MyComponent -P ../my_install_script.cmake
DEPENDS MyExecutable
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)
Inside my_install_script.cmake, the logic is largely dependent on what you want to do with the list of files. The script below will read the files into a CMake list variable, then copies them to an install destination using configure_file():
# Check if an install COMPONENT was provided.
if(COMPONENT)
# Read the manifest file.
file(READ "install_manifest_${COMPONENT}.txt" MY_INSTALL_FILES)
# Create a list from the component files.
string(REPLACE "\n" ";" MY_INSTALL_FILES ${MY_INSTALL_FILES})
# Loop through each file, placing it in the installation directory.
foreach(curFile ${MY_INSTALL_FILES})
message("Installing file: " ${curFile})
configure_file(${curFile} /your/final/install/folder COPYONLY)
endforeach()
endif(COMPONENT)

linking 3rd party libraries

I have created a simple application that works ok. However, now I need to link with some libraries in the following directory.
/opt/norton/lib
In my make file I have the following with works, but I need to use cmake
LIBS_PATH = -L/opt/norton/lib
INC_PATH = -I/opt/norton/inc
LIBS = -lntctrl
In my CMakeList.txt I have this but doesn't work I keep gettng the following error:
undefined reference to `nt_init'
This is my CMakeList.txt
# Includes files
INCLUDE_DIRECTORIES(/opt/norton/inc)
# Link libraries
LINK_DIRECTORIES(/opt/norton/lib)
# Add the library that is used by nt_init
TARGET_LINK_LIBRARIES(-lntctrl)
ADD_LIBRARY(application initialize_nw)
Many thanks for any advice,
Try out TARGET_LINK_LIBRARIES(ntctrl), the -l flag should not be used there (guess from what I have in mind)
This is how I would write the cmake file:
include_directories(/opt/norton/inc)
link_directories(/opt/norton/lib)
add_executable(application initialize_nw)
target_link_libraries(application ntctrl)
To show what are the actual command lines run during a make, use:
make VERBOSE=1
Maybe this shows you the difference between what you ran manually and the cmake generated commands.