cmake cxx flags only at compile time - cmake

I wanted to know if there is a way to pass some flags to the compiler (g++) only at compile time and not at the linking.
Let me explain with an example: I would like to build my program this way:
g++ -c source1.cpp -o source1.o
g++ -c source2.cpp -o source2.o
g++ source2.o source1.o -o myProgram.c
to do this I have created a CMakeLists.txt file that contains:
PROJECT(myProgram)
include_directories("${CMAKE_SOURCE_DIR}/inc")
aux_source_directory("${CMAKE_SOURCE_DIR}/src" SRC_FILES)
add_executable(${PROJECT_NAME} ${SRC_FILES})
then add this line to put the "-c" flag to the compiler:
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -c")
But in this way, cmake add the "-c" flag always, even when g++ is doing the linking, ie:
g++ -c source1.cpp -o source1.o
g++ -c source2.cpp -o source2.o
g++ -c source2.o source1.o -o myProgram.c
and logically myProgram will not be created because the g++ does not run linking (-c in the last instruction).
How do I use the flag "-c" (or any other flag) only at compile?

Instead of
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -c")
try
add_compile_options(-c)
No clue why though. You can use multiple space separated options in the same add_compile_options.

I am using this "CMakeLists.txt"
PROJECT(prima_prova)
cmake_minimum_required(VERSION 2.8)
set(CMAKE_VERBOSE_MAKEFILE 1)
include_directories("${CMAKE_SOURCE_DIR}/inc")
aux_source_directory("${CMAKE_SOURCE_DIR}/src" SRC_FILES)
add_executable(${PROJECT_NAME} ${SRC_FILES})
when I run cmake .. and make, I get this:
make[2]: uscita dalla directory "/home/massimi/Scrivania/test/build"
make -f CMakeFiles/prima_prova.dir/build.make CMakeFiles/prima_prova.dir/build
make[2]: ingresso nella directory "/home/massimi/Scrivania/test/build"
[ 25%] Building CXX object CMakeFiles/prima_prova.dir/src/f1.cpp.o
/usr/bin/c++ -I/home/massimi/Scrivania/test/inc -o CMakeFiles/prima_prova.dir/src/f1.cpp.o -c /home/massimi/Scrivania/test/src/f1.cpp
[ 50%] Building CXX object CMakeFiles/prima_prova.dir/src/main.cpp.o
/usr/bin/c++ -I/home/massimi/Scrivania/test/inc -o CMakeFiles/prima_prova.dir/src/main.cpp.o -c /home/massimi/Scrivania/test/src/main.cpp
[ 75%] Building CXX object CMakeFiles/prima_prova.dir/src/f2.cpp.o
/usr/bin/c++ -I/home/massimi/Scrivania/test/inc -o CMakeFiles/prima_prova.dir/src/f2.cpp.o -c /home/massimi/Scrivania/test/src/f2.cpp
[100%] Linking CXX executable prima_prova
/usr/bin/cmake -E cmake_link_script CMakeFiles/prima_prova.dir/link.txt -- verbose=1
/usr/bin/c++ CMakeFiles/prima_prova.dir/src/f1.cpp.o CMakeFiles/prima_prova.dir/src/main.cpp.o CMakeFiles/prima_prova.dir/src/f2.cpp.o -o prima_prova -rdynamic
make[2]: uscita dalla directory "/home/massimi/Scrivania/test/build"
when I add this line in the file "CMakeLists.txt":
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -c")
when I run cmake .. and make, I get this:
make[2]: uscita dalla directory "/home/massimi/Scrivania/test/build"
make -f CMakeFiles/prima_prova.dir/build.make CMakeFiles/prima_prova.dir/build
make[2]: ingresso nella directory "/home/massimi/Scrivania/test/build"
[ 25%] Building CXX object CMakeFiles/prima_prova.dir/src/f1.cpp.o
/usr/bin/c++ -c -I/home/massimi/Scrivania/test/inc -o CMakeFiles/prima_prova.dir/src/f1.cpp.o -c /home/massimi/Scrivania/test/src/f1.cpp
[ 50%] Building CXX object CMakeFiles/prima_prova.dir/src/main.cpp.o
/usr/bin/c++ -c -I/home/massimi/Scrivania/test/inc -o CMakeFiles/prima_prova.dir/src/main.cpp.o -c /home/massimi/Scrivania/test/src/main.cpp
[ 75%] Building CXX object CMakeFiles/prima_prova.dir/src/f2.cpp.o
/usr/bin/c++ -c -I/home/massimi/Scrivania/test/inc -o CMakeFiles/prima_prova.dir/src/f2.cpp.o -c /home/massimi/Scrivania/test/src/f2.cpp
[100%] Linking CXX executable prima_prova
/usr/bin/cmake -E cmake_link_script CMakeFiles/prima_prova.dir/link.txt --verbose=1
/usr/bin/c++ -c CMakeFiles/prima_prova.dir/src/f1.cpp.o CMakeFiles/prima_prova.dir/src/main.cpp.o CMakeFiles/prima_prova.dir/src/f2.cpp.o -o prima_prova -rdynamic
c++: warning: CMakeFiles/prima_prova.dir/src/f1.cpp.o: linker input file unused because linking not done
The flag "-c" or any iother flag in the variable CMAKE_CXX_FLAGS has been added always, even during linking, not only when is compiling sources.

CMAKE_CXX_FLAGS variable is used in command line only when CMake is compiling sources. During linking CMAKE_EXE_LINKER_FLAGS (and flags set by modifying target properties) are used, even if g++ is used as linker executable.

Related

CMake Assembler error "No such instruction"

I am moving an already existing project from Atmel Studio 7.0 with arm-gnu toolchain to CMake with MinGW generator.
I have configured the CXX and C compiler flags as follows:
set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} "-D__SAMD21G18A__ -DARM_MATH_CM0 -DF_CPU=48000000L -DARDUINO=10808 -DARDUINO_SAMD_ZERO -DARDUINO_ARCH_SAMD -DUSB_VID=0x239A -DUSB_PID=0x800B -DUSB_PRODUCT="\"Feather M0\"" -DUSB_MANUFACTURER="\"Adafruit\"" -DUSBCON -DDEBUG -DDEBUG_PRINT -DADAFRUIT_FONA_DEBUG -DMQTT_DEBUG -DMQTT_ERROR -ffunction-sections -fno-rtti -fno-exceptions -mlong-calls -Wall -Wa -mcpu=cortex-m0plus -std=gnu99")
set(CMAKE_C_FLAGS ${CMAKE_C_FLAGS} "-x c D__SAMD21G18A__ -DARM_MATH_CM0 -DF_CPU=48000000L -DARDUINO=10808 -DARDUINO_SAMD_ZERO -DARDUINO_ARCH_SAMD -DUSB_VID=0x239A -DUSB_PID=0x800B -DUSB_PRODUCT="\"Feather M0\"" -DUSB_MANUFACTURER="\"Adafruit\"" -DUSBCON -DDEBUG -DDEBUG_PRINT -DADAFRUIT_FONA_DEBUG -DMQTT_DEBUG -DMQTT_ERROR -ffunction-sections -mlong-calls -Wall -mcpu=cortex-m0plus -Wa-c -std=gnu99")
Here is the exact verbose command that generates the error.
:\svn\ATSAMD21_FLowTube_CMAKE\uart2lte\build --check-build-system CMakeFiles\Makefile.cmake 0
"C:\Program Files\CMake\bin\cmake.exe" -E cmake_progress_start C:\svn\ATSAMD21_FLowTube_CMAKE\uart2lte\build\CMakeFiles C:\svn\ATSAMD21_FLowTube_CMAKE\uart2lte\build\\CMakeFiles\progress.marks
C:/ProgramData/chocolatey/lib/make/tools/install/bin/make.exe -f CMakeFiles\Makefile2 all
make[1]: Entering directory 'C:/svn/ATSAMD21_FLowTube_CMAKE/uart2lte/build'
C:/ProgramData/chocolatey/lib/make/tools/install/bin/make.exe -f Library\CMakeFiles\Library.dir\build.make Library/CMakeFiles/Library.dir/depend
make[2]: Entering directory 'C:/svn/ATSAMD21_FLowTube_CMAKE/uart2lte/build'
"C:\Program Files\CMake\bin\cmake.exe" -E cmake_depends "MinGW Makefiles" C:\svn\ATSAMD21_FLowTube_CMAKE\uart2lte C:\svn\ATSAMD21_FLowTube_CMAKE\uart2lte\Library C:\svn\ATSAMD21_FLowTube_CMAKE\uart2lte\build C:\svn\ATSAMD21_FLowTube_CMAKE\uart2lte\build\Library C:\svn\ATSAMD21_FLowTube_CMAKE\uart2lte\build\Library\CMakeFiles\Library.dir\DependInfo.cmake --color=
make[2]: Leaving directory 'C:/svn/ATSAMD21_FLowTube_CMAKE/uart2lte/build'
C:/ProgramData/chocolatey/lib/make/tools/install/bin/make.exe -f Library\CMakeFiles\Library.dir\build.make Library/CMakeFiles/Library.dir/build
make[2]: Entering directory 'C:/svn/ATSAMD21_FLowTube_CMAKE/uart2lte/build'
[ 1%] Building CXX object Library/CMakeFiles/Library.dir/src/Adafruit_SleepyDog/utility/WatchdogSAMD.cpp.obj
cd /d C:\svn\ATSAMD21_FLowTube_CMAKE\uart2lte\build\Library && C:\MinGW\bin\g++.exe #CMakeFiles/Library.dir/includes_CXX.rsp -march=native -mno-avx -D__SAMD21G18A__ -DARM_MATH_CM0 -DF_CPU=48000000L -DARDUINO=10808 -DARDUINO_SAMD_ZERO -DARDUINO_ARCH_SAMD -DUSB_VID=0x239A -DUSB_PID=0x800B -DUSB_PRODUCT=;"Feather;M0"" -DUSB_MANUFACTURER=""Adafruit"" -DUSBCON -DDEBUG -DDEBUG_PRINT -DADAFRUIT_FONA_DEBUG -DMQTT_DEBUG -DMQTT_ERROR -ffunction-sections -fno-rtti -fno-exceptions -mlong-calls -Wall -Wa -mcpu=cortex-m0plus -std=gnu99" -o CMakeFiles\Library.dir\src\Adafruit_SleepyDog\utility\WatchdogSAMD.cpp.obj -c C:\svn\ATSAMD21_FLowTube_CMAKE\uart2lte\Library\src\Adafruit_SleepyDog\utility\WatchdogSAMD.cpp
C:\Users\rajusa\AppData\Local\Temp\ccAWF2FJ.s: Assembler messages:
C:\Users\rajusa\AppData\Local\Temp\ccAWF2FJ.s:47: Error: number of operands mismatch for `ds'
C:\Users\rajusa\AppData\Local\Temp\ccAWF2FJ.s:53: Error: no such instruction: `isb 0xF'
C:\Users\rajusa\AppData\Local\Temp\ccAWF2FJ.s:527: Error: number of operands mismatch for `ds'
C:\Users\rajusa\AppData\Local\Temp\ccAWF2FJ.s:533: Error: no such instruction: `wfi'
Any idea what might be the reason - in terms of toolchain - assembler ? Is there any way to specify assembler flags in CMake?
You're using MinGW GCC, which essentially targets Windows.
So I don't believe you can target other platforms..
What you need is a GCC compiler that runs on windows that supports the target platform(s) you need.
For Atmel ARM you can try something like this: http://winavr.sourceforge.net/ (though maybe something more recent may exist).

MinGW+cmake on Windows 10 produce error: '__MINGW_EXTENSION' does not name a type

I have spent long time developing C/C++ under Linux, now I'm trying to port/compile my project under windows where I have no experinece. I want to keep the workflow as close to Linux as possible so I go with g++/MinGW and cmake.
When I do standard approach
cd Build
cmake .. -G "MinGW Makefiles"
make
I got tons of following errors:
PS D:\git\SimpleSimulationEngine\cpp\Build> make VERBOSE=1
"C:\Program Files\CMake\bin\cmake.exe" -SD:\git\SimpleSimulationEngine\cpp -BD:\git\SimpleSimulationEngine\cpp\Build --check-build-system CMakeFiles\Makefile.cmake 0
"C:\Program Files\CMake\bin\cmake.exe" -E cmake_progress_start D:\git\SimpleSimulationEngine\cpp\Build\CMakeFiles D:\git\SimpleSimulationEngine\cpp\Build\\CMakeFiles\progress.marks
C:/MinGW/bin/make -f CMakeFiles\Makefile2 all
make[1]: Entering directory 'D:/git/SimpleSimulationEngine/cpp/Build'
C:/MinGW/bin/make -f common\algorithms\CMakeFiles\algorithms.dir\build.make common/algorithms/CMakeFiles/algorithms.dir/depend
make[2]: Entering directory 'D:/git/SimpleSimulationEngine/cpp/Build'
"C:\Program Files\CMake\bin\cmake.exe" -E cmake_depends "MinGW Makefiles" D:\git\SimpleSimulationEngine\cpp D:\git\SimpleSimulationEngine\cpp\common\algorithms D:\git\SimpleSimulationEngine\cpp\Build D:\git\SimpleSimulationEngine\cpp\Build\common\algorithms D:\git\SimpleSimulationEngine\cpp\Build\common\algorithms\CMakeFiles\algorithms.dir\DependInfo.cmake --color=
make[2]: Leaving directory 'D:/git/SimpleSimulationEngine/cpp/Build'
C:/MinGW/bin/make -f common\algorithms\CMakeFiles\algorithms.dir\build.make common/algorithms/CMakeFiles/algorithms.dir/build
make[2]: Entering directory 'D:/git/SimpleSimulationEngine/cpp/Build'
[ 1%] Building CXX object common/algorithms/CMakeFiles/algorithms.dir/main.cpp.obj
cd /d D:\git\SimpleSimulationEngine\cpp\Build\common\algorithms && C:\MinGW\bin\g++.exe #CMakeFiles/algorithms.dir/includes_CXX.rsp -Wall -std=c++17 -g -Og -fPIC -fno-strict-aliasing -Wno-maybe-uninitialized -Wno-char-subscripts -Wno-write-strings -Wno-format -Wno-parentheses -Wno-unused-but-set-variable -Wno-narrowing -Wno-unused-result -Wno-sign-compare -Wno-strict-aliasing -Wno-unused-variable -Wno-unused-value -Wno-comment -Wno-misleading-indentation -Werror=return-type -o CMakeFiles\algorithms.dir\main.cpp.obj -c D:\git\SimpleSimulationEngine\cpp\common\algorithms\main.cpp
In file included from c:\mingw\x86_64-w64-mingw32\include\stdlib.h:9:0,
from c:\mingw\include\c++\6.1.0\cstdlib:75,
from D:/git/SimpleSimulationEngine/cpp/common/utils/testUtils.h:6,
from D:\git\SimpleSimulationEngine\cpp\common\algorithms\main.cpp:2:
c:\mingw\x86_64-w64-mingw32\include\crtdefs.h:35:1: error: '__MINGW_EXTENSION' does not name a type
__MINGW_EXTENSION typedef unsigned __int64 size_t;
^~~~~~~~~~~~~~~~~
c:\mingw\x86_64-w64-mingw32\include\crtdefs.h:45:1: error: '__MINGW_EXTENSION' does not name a type
__MINGW_EXTENSION typedef __int64 ssize_t;
^~~~~~~~~~~~~~~~~
c:\mingw\x86_64-w64-mingw32\include\crtdefs.h:52:9: error: 'size_t' does not name a type
typedef size_t rsize_t;
^~~~~~
c:\mingw\x86_64-w64-mingw32\include\crtdefs.h:62:1: error: '__MINGW_EXTENSION' does not name a type
__MINGW_EXTENSION typedef __int64 intptr_t;
^~~~~~~~~~~~~~~~~
c:\mingw\x86_64-w64-mingw32\include\crtdefs.h:75:1: error: '__MINGW_EXTENSION' does not name a type
__MINGW_EXTENSION typedef unsigned __int64 uintptr_t;
I'm not sure my MinGW environment and libraries are setup properly, since I tried some older minGW version before, than I reinstalled it. Also I have installed MSYS2 in an atempt to install GLEW. But I do not use MSYS2 now, I use some stand alone instalation of MinGW and cmake.
There is nothing special in my CMakeLists.txt
cmake_minimum_required ( VERSION 2.8 )
project ( SimpleSimulationEngine )
set(default_build_type Release)
SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -std=c++17" )
SET( IGNORE_WARRNING_FLAGS "-Wno-maybe-uninitialized -Wno-char-subscripts -Wno-write-strings -Wno-format -Wno-parentheses -Wno-unused-but-set-variable -Wno-narrowing -Wno-unused-result -Wno-sign-compare -Wno-strict-aliasing -Wno-unused-variable -Wno-unused-value -Wno-comment -Wno-misleading-indentation " )
SET( WARRNING_TO_ERROR "-Werror=return-type")
SET( AXULIARY_COMPILE_FLAGS "-g -Og -fPIC -fno-strict-aliasing ")
SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${AXULIARY_COMPILE_FLAGS} ${IGNORE_WARRNING_FLAGS}
message ( "CMAKE_CXX_FLAGS " ${CMAKE_CXX_FLAGS} )
When I check my environment variables/path there does not seem to be anything fishy (like two versions of MinGW)

Compile order with TARGET_LINK_LIBRARIES in three CMakeLists.txt

I have a problem with CMake: A static library and an executable are made but the build process is out of order. Thus, the library does not exist when the executable tries to link. I have read similar questions but did not find a solution. My project uses one root-CMakelists.txt that includes the other two:
Root: dev/CMakeLists.txt:
# Library project
include(${CMAKE_CURRENT_SOURCE_DIR}/src_lib/CMakeLists.txt)
# Client project
include(${CMAKE_CURRENT_SOURCE_DIR}/src_client/CMakeLists.txt)
Library: dev/src_lib/CMakeLists.txt
add_library(wof_static STATIC ${LIB_SRC})
TARGET_LINK_LIBRARIES(wof_static ${CMAKE_CURRENT_SOURCE_DIR}/3rdParty/lex/libs/amd64/libLexActivator.a pthread libnss3.so /usr/lib/x86_64-linux-gnu/libssl3.so /usr/lib/x86_64-linux-gnu/libnspr4.so )
Executable: dev/src_client/CMakeLists.txt
add_executable(wof ${CLIENT_SRC})
TARGET_LINK_LIBRARIES( wof
${CMAKE_CURRENT_SOURCE_DIR}/build/libwof_static.a
${CMAKE_CURRENT_SOURCE_DIR}/src_lib/3rdParty/lex/libs/amd64/libLexActivator.a
gmp
pthread
libnss3.so
/usr/lib/x86_64-linux-gnu/libssl3.so
/usr/lib/x86_64-linux-gnu/libnspr4.so
)
The above TARGET_LINK_LIBRARIES command uses the filename libwof_static.a, and thus, the build is out of order (i.e., it works only when I call make twice). Thus, I need to let CMake know that the executable depends on the library-target wof_static, right? I tried to do so:
Executable: dev/src_client/CMakeLists.txt (variant)
link_directories(${CMAKE_CURRENT_SOURCE_DIR}/build/ ${CMAKE_CURRENT_SOURCE_DIR}/src_lib/3rdParty/lex/libs/amd64/)
add_executable(wof ${CLIENT_SRC})
TARGET_LINK_LIBRARIES( wof
wof_static
${CMAKE_CURRENT_SOURCE_DIR}/src_lib/3rdParty/lex/libs/amd64/libLexActivator.a
gmp
pthread
libnss3.so
/usr/lib/x86_64-linux-gnu/libssl3.so
/usr/lib/x86_64-linux-gnu/libnspr4.so
)
The intention of the above is to let CMake know the target name wof_static. That seems to work because the compilation of the executable wof starts when the library is ready. But I assumed that CMake would know and use the output file libwof_static.a of the target wof_static. This does not seem to be true. The error I get is:
[ 94%] Linking CXX static library libwof_static.a
/usr/local/bin/cmake -P CMakeFiles/wof_static.dir/cmake_clean_target.cmake
/usr/local/bin/cmake -E cmake_link_script CMakeFiles/wof_static.dir/link.txt --verbose=1
/usr/bin/ar qc libwof_static.a CMakeFiles/wof_static.dir/src_lib/AngleEntry.cpp.o CMakeFiles/wof_static.dir/src_lib/CEdge.cpp.o CMakeFiles/wof_static.dir/src_lib/CMesh.cpp.o CMakeFiles/wof_static.dir/src_lib/CPatch.cpp.o CMakeFiles/wof_static.dir/src_lib/CTriangle.cpp.o CMakeFiles/wof_static.dir/src_lib/Calc.cpp.o CMakeFiles/wof_static.dir/src_lib/Casx.cpp.o CMakeFiles/wof_static.dir/src_lib/Chain.cpp.o CMakeFiles/wof_static.dir/src_lib/ChainMgr.cpp.o CMakeFiles/wof_static.dir/src_lib/Cloud.cpp.o CMakeFiles/wof_static.dir/src_lib/CloudMgr.cpp.o CMakeFiles/wof_static.dir/src_lib/Hal.cpp.o CMakeFiles/wof_static.dir/src_lib/Histogram.cpp.o CMakeFiles/wof_static.dir/src_lib/HoleFiller.cpp.o CMakeFiles/wof_static.dir/src_lib/HoleToCCD.cpp.o CMakeFiles/wof_static.dir/src_lib/Inspector.cpp.o CMakeFiles/wof_static.dir/src_lib/Iso.cpp.o CMakeFiles/wof_static.dir/src_lib/IsoStore.cpp.o CMakeFiles/wof_static.dir/src_lib/LexSample.cpp.o CMakeFiles/wof_static.dir/src_lib/Loop.cpp.o CMakeFiles/wof_static.dir/src_lib/Performance.cpp.o CMakeFiles/wof_static.dir/src_lib/Pixel.cpp.o CMakeFiles/wof_static.dir/src_lib/Plane.cpp.o CMakeFiles/wof_static.dir/src_lib/Posix.cpp.o CMakeFiles/wof_static.dir/src_lib/Rotx.cpp.o CMakeFiles/wof_static.dir/src_lib/Segment3.cpp.o CMakeFiles/wof_static.dir/src_lib/Smooth.cpp.o CMakeFiles/wof_static.dir/src_lib/Surve.cpp.o CMakeFiles/wof_static.dir/src_lib/Top.cpp.o CMakeFiles/wof_static.dir/src_lib/TopMelt.cpp.o CMakeFiles/wof_static.dir/src_lib/Vector3.cpp.o CMakeFiles/wof_static.dir/src_lib/Visualizer3.cpp.o CMakeFiles/wof_static.dir/src_lib/Voro.cpp.o CMakeFiles/wof_static.dir/src_lib/Wof.cpp.o CMakeFiles/wof_static.dir/src_lib/WofMesh.cpp.o CMakeFiles/wof_static.dir/src_lib/api.cpp.o CMakeFiles/wof_static.dir/src_lib/api_io.cpp.o CMakeFiles/wof_static.dir/src_lib/devStuff.cpp.o CMakeFiles/wof_static.dir/src_lib/freeFunctions.cpp.o CMakeFiles/wof_static.dir/src_lib/geom_locate3/Node.cpp.o CMakeFiles/wof_static.dir/src_lib/geom_locate3/RTree.cpp.o CMakeFiles/wof_static.dir/src_lib/geom_octree/OctNode.cpp.o CMakeFiles/wof_static.dir/src_lib/geom_octree/Octree.cpp.o CMakeFiles/wof_static.dir/src_lib/geom_tools/GSS_HC2.cpp.o CMakeFiles/wof_static.dir/src_lib/geom_tools/GSS_HC3.cpp.o CMakeFiles/wof_static.dir/src_lib/testDataGenerators.cpp.o CMakeFiles/wof_static.dir/src_lib/tinyply.cpp.o CMakeFiles/wof_static.dir/src_lib/tools.cpp.o
/usr/bin/ranlib libwof_static.a
make[2]: Leaving directory '/home/geom/repoWOF/dev/build'
[ 94%] Built target wof_static
make -f CMakeFiles/wof.dir/build.make CMakeFiles/wof.dir/depend
make[2]: Entering directory '/home/geom/repoWOF/dev/build'
cd /home/geom/repoWOF/dev/build && /usr/local/bin/cmake -E cmake_depends "Unix Makefiles" /home/geom/repoWOF/dev /home/geom/repoWOF/dev /home/geom/repoWOF/dev/build /home/geom/repoWOF/dev/build /home/geom/repoWOF/dev/build/CMakeFiles/wof.dir/DependInfo.cmake --color=
make[2]: Leaving directory '/home/geom/repoWOF/dev/build'
make -f CMakeFiles/wof.dir/build.make CMakeFiles/wof.dir/build
make[2]: Entering directory '/home/geom/repoWOF/dev/build'
[ 96%] Building CXX object CMakeFiles/wof.dir/src_client/Params.cpp.o
[ 98%] Building CXX object CMakeFiles/wof.dir/src_client/main.cpp.o
make[2]: *** No rule to make target '../3rdParty/lex/libs/amd64/libLexActivator.a', needed by 'wof'. Stop.
make[2]: *** Waiting for unfinished jobs....
/usr/bin/c++ -I/home/geom/repoWOF/dev/include -O3 -DNDEBUG -std=c++11 -fstrict-aliasing -Wno-unused-local-typedefs -Wno-long-long -O3 -Wextra -Wunused -Wall -pedantic-errors -frounding-math -funroll-loops -Wl,-s -o CMakeFiles/wof.dir/src_client/Params.cpp.o -c /home/geom/repoWOF/dev/src_client/Params.cpp
/usr/bin/c++ -I/home/geom/repoWOF/dev/include -O3 -DNDEBUG -std=c++11 -fstrict-aliasing -Wno-unused-local-typedefs -Wno-long-long -O3 -Wextra -Wunused -Wall -pedantic-errors -frounding-math -funroll-loops -Wl,-s -o CMakeFiles/wof.dir/src_client/main.cpp.o -c /home/geom/repoWOF/dev/src_client/main.cpp
make[2]: Leaving directory '/home/geom/repoWOF/dev/build'
CMakeFiles/Makefile2:112: recipe for target 'CMakeFiles/wof.dir/all' failed
make[1]: *** [CMakeFiles/wof.dir/all] Error 2
make[1]: Leaving directory '/home/geom/repoWOF/dev/build'
Makefile:86: recipe for target 'all' failed
make: *** [all] Error 2
In your file dev/src_client/CMakeLists.txt, this line:
${CMAKE_CURRENT_SOURCE_DIR}/src_lib/3rdParty/lex/libs/amd64/libLexActivator.a
evaluates to the path:
dev/src_client/src_lib/3rdParty/lex/libs/amd64/libLexActivator.a
I don't think that is what you intend, as this path is different from the path you use in the dev/src_lib/CMakeLists.txt file.
Instead of CMAKE_CURRENT_SOURCE_DIR, use the CMake variable that points to the root source directory: CMAKE_SOURCE_DIR. Try something like this:
TARGET_LINK_LIBRARIES( wof
wof_static
${CMAKE_SOURCE_DIR}/src_lib/3rdParty/lex/libs/amd64/libLexActivator.a
gmp
pthread
libnss3.so
/usr/lib/x86_64-linux-gnu/libssl3.so
/usr/lib/x86_64-linux-gnu/libnspr4.so
)

CMake with IBMs mpixlf2008

I am trying to compile a Fortran program using CMake on an IBM BlueGene machine. This is my source:
> tree
.
├── CMakeLists.txt
└── src
└── test1.f90
where test1.f90 simply is:
program main
use mpi
integer :: me, ierr
call MPI_Init(ierr)
call MPI_Comm_rank(MPI_COMM_WORLD, me, ierr)
write (*,"(I4,A)") me, ": hello"
call MPI_Finalize(ierr)
end program main
I would like to create a static executable. Therefore I created this CMakeLists.txt:
cmake_minimum_required(VERSION 2.5)
project(STB)
file(GLOB_RECURSE sources src/*.f90)
SET(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
SET(BUILD_SHARED_LIBRARIES OFF)
SET(CMAKE_EXE_LINKER_FLAGS "-static")
add_executable(test.x ${sources})
enable_language(Fortran)
set(CMAKE_Fortran_COMPILER_ID "IBM")
if(CMAKE_Fortran_COMPILER_ID MATCHES "IBM")
MESSAGE(STATUS "IBM")
set(CMAKE_Fortran_COMPILER mpixlf2008)
set(dialect "-O2 -qarch=qp -qtune=qp -ufmt_littleendian={23}")
set(debug "-C")
endif()
set(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG} ${bounds}")
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} ${dialect}")
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
MESSAGE( STATUS "cmake_module_path: " ${CMAKE_MODULE_PATH})
this results in:
make VERBOSE=1
/usr/bin/cmake -H/work/jias12/jias1217/test -B/work/jias12/jias1217/test --check-build-system CMakeFiles/Makefile.cmake 0
/usr/bin/cmake -E cmake_progress_start /work/jias12/jias1217/test/CMakeFiles /work/jias12/jias1217/test/CMakeFiles/progress.marks
make -f CMakeFiles/Makefile2 all
make[1]: Entering directory `/work/jias12/jias1217/test'
make -f CMakeFiles/test.x.dir/build.make CMakeFiles/test.x.dir/depend
make[2]: Entering directory `/work/jias12/jias1217/test'
cd /work/jias12/jias1217/test && /usr/bin/cmake -E cmake_depends "Unix Makefiles" /work/jias12/jias1217/test /work/jias12/jias1217/test /work/jias12/jias1217/test /work/jias12/jias1217/test /work/jias12/jias1217/test/CMakeFiles/test.x.dir/DependInfo.cmake --color=
make[2]: Leaving directory `/work/jias12/jias1217/test'
make -f CMakeFiles/test.x.dir/build.make CMakeFiles/test.x.dir/requires
make[2]: Entering directory `/work/jias12/jias1217/test'
make[2]: Nothing to be done for `CMakeFiles/test.x.dir/requires'.
make[2]: Leaving directory `/work/jias12/jias1217/test'
make -f CMakeFiles/test.x.dir/build.make CMakeFiles/test.x.dir/build
make[2]: Entering directory `/work/jias12/jias1217/test'
/usr/bin/cmake -E cmake_progress_report /work/jias12/jias1217/test/CMakeFiles 1
[100%] Building Fortran object CMakeFiles/test.x.dir/src/test1.o
mpixlf2008 -O2 -qarch=qp -qtune=qp -ufmt_littleendian={23} -c /work/jias12/jias1217/test/src/test1.f90 -o CMakeFiles/test.x.dir/src/test1.o
** main === End of Compilation 1 ===
1501-510 Compilation successful for file test1.f90.
Linking Fortran executable test.x
/usr/bin/cmake -E cmake_link_script CMakeFiles/test.x.dir/link.txt --verbose=1
mpixlf2008 -static -O2 -qarch=qp -qtune=qp -ufmt_littleendian={23} CMakeFiles/test.x.dir/src/test1.o -o test.x -rdynamic
/opt/ibmcmp/xlf/bg/14.1/bin/.orig/bgxlf2008: 1501-210 (S) command option ynamic contains an incorrect subargument
make[2]: *** [test.x] Error 40
make[2]: Leaving directory `/work/jias12/jias1217/test'
make[1]: *** [CMakeFiles/test.x.dir/all] Error 2
make[1]: Leaving directory `/work/jias12/jias1217/test'
make: *** [all] Error 2
If I rerun the last argument without the -rdynamic
mpixlf2008 -static -O2 -qarch=qp -qtune=qp -ufmt_littleendian={23} CMakeFiles/test.x.dir/src/test1.o -o test.x
I get the error:
/bgsys/drivers/ppcfloor/gnu-linux/powerpc64-bgq-linux/bin/ld: -f may not be used without -shared
How can I compile my program using statically using CMake? If I simply run:
mpixlf2008 -c src/test1.f90
mpixlf2008 test1.o -o bla.x
The compilation works fine and the size(45M) suggest, that it's compiled statically.
Edit:
If I remove the little endian flag:
set(dialect "-O2 -qarch=qp -qtune=qp")
I can run the cmake created makefile and then manually remove the -rdynamic
mpixlf2008 -static -O2 -qarch=qp -qtune=qp CMakeFiles/test.x.dir/src/test1.o -o test.x
Which then successfully compiles. How can I remove the -rdynamic from the CMake Makefile?
Try adding -qstaticlink to your link line instead of adding -static / -rdynamic directly. When you use the mpixlf2008 command, the compiler inserts its own -static / -rdynamic options to link in its own libraries, so the options you added are probably interfering with the ones the compiler is using. The -qstaticlink option tells the compiler you want a completely static binary. The option also has suboptions that would allow you to only statically link the gcc libraries.
Also, the specific error you're getting is because you specified "-rdynamic". XLF doesn't know this option, so it assumes it's a grouping of smaller options. So it parses it as: "-r -d -ynamic". -r is for creating a nonexecutable output file, -d is for saving preprocessed output, -y is for specifying compile-time rounding mode. The -y option takes a suboption for the rounding mode, e.g. -yn for nearest. The error you're getting is that namic is not a known suboption of -y. To pass -rdynamic to the linker, put -Wl, before it. i.e. "-Wl,-rdynamic".
Adding
set(CMAKE_SHARED_LIBRARY_LINK_Fortran_FLAGS)
allows me to remove the '-rdynamic'. This might be a bit manual, but for older CMake versions it works.

cmake: c++: error: ${CFLAGS}: No such file or directory

I'm trying to follow this cmake tutorial. But when it comes to calling cmake for the first time I get the following error:
cmake -G "Unix Makefiles" .. --debug-trycompile
debug trycompile on
-- The C compiler identification is GNU 6.3.1
-- The CXX compiler identification is unknown
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- broken
CMake Error at /usr/share/cmake-3.7/Modules/CMakeTestCXXCompiler.cmake:44 (message):
The C++ compiler "/usr/bin/c++" is not able to compile a simple test
program.
It fails with the following output:
Change Dir: /home/user01/code/tests/cmake_tutorial_02/build/CMakeFiles/CMakeTmp
Run Build Command:"/usr/bin/make" "cmTC_7a86e/fast"
/usr/bin/make -f CMakeFiles/cmTC_7a86e.dir/build.make
CMakeFiles/cmTC_7a86e.dir/build
make[1]: Entering directory
'/home/user01/code/tests/cmake_tutorial_02/build/CMakeFiles/CMakeTmp'
Building CXX object CMakeFiles/cmTC_7a86e.dir/testCXXCompiler.cxx.o
/usr/bin/c++ -march=native -O2 -pipe -fstack-protector-strong -o
CMakeFiles/cmTC_7a86e.dir/testCXXCompiler.cxx.o -c
/home/user01/code/tests/cmake_tutorial_02/build/CMakeFiles/CMakeTmp/testCXXCompiler.cxx
Linking CXX executable cmTC_7a86e
/usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_7a86e.dir/link.txt
--verbose=1
/usr/bin/c++ ${CFLAGS} CMakeFiles/cmTC_7a86e.dir/testCXXCompiler.cxx.o -o
cmTC_7a86e
c++: error: ${CFLAGS}: No such file or directory
When I call echo $CFLAGS in bash the value is:
-march=native -O2 -pipe -fstack-protector-strong
But it looks like ${CFLAGS} is not defined while executing cmake_link_script. To verify I changed ${CFLAGS} in link.txt to -march=native -O2 -pipe -fstack-protector-strong and manually called:
/usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_7a86e.dir/link.txt
which works.
Next I tried adding the following line to CMakeLists.txt:
set (CFLAGS -O2)
which didn't help.
Neither did calling:
cmake -DCFLAGS=-O2 -G "Unix Makefiles" ..
So my question is, how to define CFLAGS so it is defined when calling the cmake_link_script in cmake's command mode?
EDIT
It looks like cmake fails withe the "Unix Makefiles" generator and doesn't even get to the code from the Tutorial.
the CMakeLists.txt just looks like this:
project("To Do List")
add_executable(toDo main.cc
ToDo.cc)
EDIT2
I found a workaround.
For some reason the generator sets CMAKE_CXX_FLAGS:STRING='${CFLAGS} ' in CMakeCache.txt.
But when the generator gets invoked with:
cmake -DCMAKE_CXX_FLAGS:STRING="${CFLAGS} " -G "Unix Makefiles" ..
everything works. Even the "The CXX compiler identification is unknown" message is gone.
However, I would still like to know why the generator failed before?