Specify Fortran module compile order with CMake - cmake

My Fortran project has a target comprised of a module containing helper functions and a few generated source files for tests. The test modules all use the helper module (i.e. use test_tools). I'm building with CMake, so the source list looks like
add_custom_command(
# here's where I'm doing the stuff to generate test_SR#.F90
GENERATED
)
set(SOURCES
test_tools.F90
test_SR1.F90 # contains `use test_tools`
test_SR2.F90 # contains `use test_tools`
...
test_SR20.F90 # contains `use test_tools`
)
This compiles fine on macOS and Linux, but on Windows with the Visual Studio 15 2017 generator test_tools.F90 is not compiled before test_SR#.F90 so on the first attempt the compile fails.
6> ... Done. Results in C:/Users/rmudafor/Desktop/openfast453/build/unit_tests/tests/beamdyn/test_BD_CrvMatrixH.F90
6>Generating ../tests/beamdyn/test_BD_InputGlobalLocal.F90
6>Processing file C:/Users/rmudafor/Desktop/openfast453/unit_tests/../modules/beamdyn/tests/test_BD_InputGlobalLocal.F90
6> ... Done. Results in C:/Users/rmudafor/Desktop/openfast453/build/unit_tests/tests/beamdyn/test_BD_InputGlobalLocal.F90
6>Compiling with Intel(R) Visual Fortran Compiler 19.1.1.216 [Intel(R) 64]...
6>test_BD_InputGlobalLocal.F90
6>C:\Users\rmudafor\Desktop\openfast453\build\unit_tests\tests\beamdyn\test_BD_InputGlobalLocal.F90(19): error #7002: Error in opening the compiled module file. Check INCLUDE paths. [TEST_TOOLS]
6>C:\Users\rmudafor\Desktop\openfast453\build\unit_tests\tests\beamdyn\test_BD_InputGlobalLocal.F90(47): error #6404: This name does not have a type, and must have an explicit type. [CALCROTATIONMATRIX]
6>compilation aborted for C:\Users\rmudafor\Desktop\openfast453\build\unit_tests\tests\beamdyn\test_BD_InputGlobalLocal.F90 (code 1)
6>test_BD_InitShpDerJaco.F90
6>C:\Users\rmudafor\Desktop\openfast453\build\unit_tests\tests\beamdyn\test_BD_InitShpDerJaco.F90(9): error #7002: Error in opening the compiled module file. Check INCLUDE paths. [TEST_TOOLS]
6>C:\Users\rmudafor\Desktop\openfast453\build\unit_tests\tests\beamdyn\test_BD_InitShpDerJaco.F90(54): error #6404: This name does not have a type, and must have an explicit type. [SIMPLEPARAMETERTYPE]
6>compilation aborted for C:\Users\rmudafor\Desktop\openfast453\build\unit_tests\tests\beamdyn\test_BD_InitShpDerJaco.F90 (code 1)
6>test_BD_DistrLoadCopy.F90
6>C:\Users\rmudafor\Desktop\openfast453\build\unit_tests\tests\beamdyn\test_BD_DistrLoadCopy.F90(9): error #7002: Error in opening the compiled module file. Check INCLUDE paths. [TEST_TOOLS]
6>C:\Users\rmudafor\Desktop\openfast453\build\unit_tests\tests\beamdyn\test_BD_DistrLoadCopy.F90(32): error #6404: This name does not have a type, and must have an explicit type. [SIMPLEPARAMETERTYPE]
6>C:\Users\rmudafor\Desktop\openfast453\build\unit_tests\tests\beamdyn\test_BD_DistrLoadCopy.F90(33): error #6404: This name does not have a type, and must have an explicit type. [SIMPLEMISCVARTYPE]
6>C:\Users\rmudafor\Desktop\openfast453\build\unit_tests\tests\beamdyn\test_BD_DistrLoadCopy.F90(34): error #6404: This name does not have a type, and must have an explicit type. [SIMPLEINPUTTYPE]
6>compilation aborted for C:\Users\rmudafor\Desktop\openfast453\build\unit_tests\tests\beamdyn\test_BD_DistrLoadCopy.F90 (code 1)
6>test_BD_CrvCompose.F90
6>C:\Users\rmudafor\Desktop\openfast453\build\unit_tests\tests\beamdyn\test_BD_CrvCompose.F90(14): error #7002: Error in opening the compiled module file. Check INCLUDE paths. [TEST_TOOLS]
6>C:\Users\rmudafor\Desktop\openfast453\build\unit_tests\tests\beamdyn\test_BD_CrvCompose.F90(48): error #6404: This name does not have a type, and must have an explicit type. [CALCROTATIONMATRIX]
6>compilation aborted for C:\Users\rmudafor\Desktop\openfast453\build\unit_tests\tests\beamdyn\test_BD_CrvCompose.F90 (code 1)
6>test_BD_GaussPointWeight.F90
6>C:\Users\rmudafor\Desktop\openfast453\build\unit_tests\tests\beamdyn\test_BD_GaussPointWeight.F90(13): error #7002: Error in opening the compiled module file. Check INCLUDE paths. [TEST_TOOLS]
6>compilation aborted for C:\Users\rmudafor\Desktop\openfast453\build\unit_tests\tests\beamdyn\test_BD_GaussPointWeight.F90 (code 1)
6>test_tools.F90 <---- HERE: this one should be compiled before the ones above
6>test_BD_diffmtc.F90
6>test_ExtractRelativeRotation.F90
6>test_BD_CrvMatrixH.F90
6>test_BD_QPData_mEta_rho.F90
6>test_BD_CrvMatrixR.F90
6>test_BD_GenerateGLL.F90
6>test_BD_CrvExtractCrv.F90
6>test_BD_GravityForce.F90
6>test_BD_CheckRotMat.F90
6>driver.F90
6>
6>Build log written to "file://C:\Users\rmudafor\Desktop\openfast453\build\unit_tests\beamdyn\beamdyn_utest.dir\Release\BuildLog.htm"
6>beamdyn_utest - 16 error(s), 0 warning(s)
========== Build: 5 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
If I let the build continue to the end, then test_tools will have been compiled and it will succeed the second time. This isn't an issue when I'm doing this manually, but it does prevent automating the build and test sequence.
I'd like to somehow indicate to CMake that it must compile test_tools before any of the test_SR#.F90 modules.
I'm using CMake 3.17 on Windows, Visual Studio 15 2017, and Intel 2020 tools.

Related

Building Chromium's unit tests: generate_fontconfig_caches failed

I have been able to build Chromium from source, for Ubuntu using this guide.
Subsequently, I want to build the unit tests for it. And specifically, I want to build vaapi_unittest.
I have not been able to do so. First it failed on missing TTF fonts, but after adding a whole bunch of fonts to third_party/test_fonts/test_fonts/ I now get this failure: generate_fontconfig_caches failed with exit code 1
$ autoninja vaapi_unittest
[25/1011] CXX obj/ui/base/x/x/x11_util.o
...
[789/1009] ACTION //third_party/test_fonts/fontconfig:do_generate_fontconfig_caches(//build/toolchain/linux:clang_x64)
FAILED: fontconfig_caches/fb5c91b2895aa445d23aebf7f9e2189c-le64.cache-7
python3 ../../build/gn_run_binary.py generate_fontconfig_caches
generate_fontconfig_caches failed with exit code 1
[802/1009] CXX obj/media/gpu/chromeos/chromeos/video_decoder_pipeline.o
ninja: build stopped: subcommand failed.
How can I avoid this error?
Or alternatively: I'm sure vaapi_unittest does not depend on fonts, so how can I prevent it from depending on that font and its font cache?
This is caused by the following entry in my out/Default/args.gn file:
use_bundled_fontconfig = false
When I set it to true instead, the unit test will compile and link.

vs2019 wxwidgets sample hello world -> "wxstrcoll not found"

Seems like many people hit this and there seems to be no solution that I can find.
Follow exact instructions, downloaded precompiled libs, v 3.0.5 - latest stable build
set wxwin env var
make new 32bit empty project
copy the hello world app into new source file
set additional include
set preproc defintions -> UNICODE & _UNICODE on
set linker libs
build ->
1>------ Build started: Project: wxtest, Configuration: Debug Win32 ------
1>Source.cpp
1>c:\work\wxwin\include\wx\wxcrt.h(487): error C3861: 'wxStrcoll': identifier not found
1>c:\work\wxwin\include\wx\wxcrt.h(487): message : 'wxStrcoll': function was not declared in the template definition context and can be found only via argument-dependent lookup in the instantiation context
1>c:\work\wxwin\include\wx\wxcrt.h(496): message : see reference to function template instantiation 'int wxStrcoll_String<const wchar_t*>(const wxString &,const T &)' being compiled
1> with
1> [
1> T=const wchar_t *
1> ]
1>Done building project "wxtest.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Unfortunately you need to manually modify the header to fix the build with MSVS 2019 in 3.0.5 and remove defined(__VISUALC__) || part of the check before wxNEEDS_DECL_BEFORE_TEMPLATE definition in wx/wxcrt.h.
FWIW this problem was fixed since a long time (~6 years) in wx 3.1 and you can compile 3.1.3 or the soon to be released 3.1.4 out of the box with MSVS 2019.

MSBuild: 'error MSB6006: "cmd.exe" exited with code 1.'

When attempting to build TensorFlow with CMake and MSBuild on Windows 10, I get the following error when running MSBuild:
"C:\work\tensorflow\tensorflow\contrib\cmake\build\tf_tutorials_example_trainer.vcxproj" (default target) (1) ->
"C:\work\tensorflow\tensorflow\contrib\cmake\build\tf_core_gpu_kernels.vcxproj" (default target) (90) ->
(CustomBuild target) ->
C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.CppCommon.targets(171,5): error MSB6006: "cmd.exe" exited with code 1. [C:\work\tensorflow\tensorflow\contrib\cmake\build\tf_core_gpu_kernels.vcxproj]
351 Warning(s)
1 Error(s)
So I only get one error message, and that just tells me that cmd.exe was closed with an error code indicating that there was a problem, but not what the problem was. So how can I find out what caused this problem so I can solve it?
This error commonly happens because the default cmake install location requires admin privileges (normally C:/Program Files/).
There are two simple ways around this:
Run visual studio as Administrator
Override the CMAKE_INSTALL_PREFIX variable to point somewhere not requiring admin privileges
Personally, I'd recommend the second option (When configuring cmake, the command would be something like: cmake . -DCMAKE_INSTALL_PREFIX=D:/Some/Path)

How to use GMP library in case of nested makefiles in c++

I have a source code of a tool written in c++. The tool is compose of several modules that compiles perfectly using a set of nested makefiles. I wanted to add a certain feature to a specific module in that tool that requires using the gmplib library. However, it gives me this error:
### Module sdf - sdf3cost
Creating executable sdf3cost-sdf
/sdf3/build/work/Linux/lib/libsdf3-sdf.so: undefined reference to `__gmpz_clear'
/sdf3/build/work/Linux/lib/libsdf3-sdf.so: undefined reference to `__gmpz_init_set_ui'
collect2: error: ld returned 1 exit status
make[3]: *** [sdf3cost-sdf] Error 1
make[2]: *** [sdf3cost] Error 2
make[1]: *** [tools] Error 2
make: *** [sdf] Error 2
I think that I know the reason behind that error is related to the usage of -lgmp flag. However, I don't know where to add it in the makefiles since they are nested. Or maybe it is a different problem, I don't know. Can any body help me please?

Build Linux Kernel module with warning i2c_register_board_info undefined

I follow an example in kernel.org to write an i2c driver but unfortunately when i compile i got this warning
WARNING: "i2c_register_board_info" [/home/pi/builddriver/samplei2c/pn535.ko] undefined!
Although compile with 1 warning and no error, I cannot insmod module. this is error when insmod
insmod: ERROR: could not insert module pn535.ko: Invalid module format
My question is how to solve the warning above?, I think it make .ko file to be invalid. Here is my source code on
pastebin
thank for your help!
That is not possible in a kernel module simply because the function i2c_register_board_info is not exported from the kernel source tree to the kernel modules (built using obj-m targets). You can achieve this by building your driver within the kernel source tree using (obj-y targets).