Usgage O-LLVM with cmake failed - cmake

I tried to compile simple Hello World program with O-LLVM
C:\msys64\mingw64\bin\clang++.exe -mllvm -bcf -mllvm -bcf_loop=4 -mllvm -bcf_prob=100 -mllvm -sub -mllvm -sub_loop=2 -mllvm -fla -mllvm -split main.cpp -o test.exe
That command works fine and test.exe is obfuscated
But after i tried to obfuscate the same file main.cpp with CMake project, it's not obfuscated. My CMake file
cmake_minimum_required(VERSION 3.23)
project(exampleClang)
set(CMAKE_VERBOSE_MAKEFILE on)
set(CMAKE_CXX_STANDARD 17)
add_executable(exampleClang main.cpp)
#-mllvm -bcf -mllvm -bcf_prob=100 -mllvm -sub -mllvm -sub_loop=2 -mllvm -fla -mllvm
target_compile_options(exampleClang PUBLIC
"SHELL:-mllvm -bcf"
"SHELL:-mllvm -bcf_prob=100"
"SHELL:-mllvm -sub"
"SHELL:-mllvm -sub_loop=2"
"SHELL:-mllvm -fla"
"SHELL:-mllvm -split")
Verbose:
[ 50%] Building CXX object CMakeFiles/exampleClang.dir/main.cpp.obj
C:\msys64\mingw64\bin\clang++.exe -Os -DNDEBUG -D_DLL -D_MT -Xclang --dependent-lib=msvcrt -mllvm -bcf -mllvm -bcf_prob=100 -mllvm -sub -mllvm -sub_loop=2 -mllvm -fla -mllvm -split -std=gnu++17 -MD -MT CMakeFiles/exampleClang.dir/main.cpp.obj -MF CMakeFiles\exampleClang.dir\main.cpp.obj.d -o CMakeFiles\exampleClang.dir\main.cpp.obj -c C:\Users\Administrator\CLionProjects\exampleClang\main.cpp
[100%] Linking CXX executable exampleClang.exe
"C:\Program Files\JetBrains\CLion 2022.2.1\bin\cmake\win\bin\cmake.exe" -E cmake_link_script CMakeFiles\exampleClang.dir\link.txt --verbose=1
C:\msys64\mingw64\bin\clang++.exe -fuse-ld=lld-link -nostartfiles -nostdlib -Os -DNDEBUG -D_DLL -D_MT -Xclang --dependent-lib=msvcrt -Xlinker /subsystem:console #CMakeFiles\exampleClang.dir\objects1.rsp -o exampleClang.exe -Xlinker /MANIFEST:EMBED -Xlinker /implib:exampleClang.lib -Xlinker /pdb:C:\Users\Administrator\CLionProjects\exampleClang\cmake-build-minsizerel\exampleClang.pdb -Xlinker /version:0.0 #CMakeFiles\exampleClang.dir\linklibs.rsp
mingw32-make[3]: Leaving directory 'C:/Users/Administrator/CLionProjects/exampleClang/cmake-build-minsizerel'
[100%] Built target exampleClang
mingw32-make[2]: Leaving directory 'C:/Users/Administrator/CLionProjects/exampleClang/cmake-build-minsizerel'
"C:\Program Files\JetBrains\CLion 2022.2.1\bin\cmake\win\bin\cmake.exe" -E cmake_progress_start C:\Users\Administrator\CLionProjects\exampleClang\cmake-build-minsizerel\CMakeFiles 0
mingw32-make[1]: Leaving directory 'C:/Users/Administrator/CLionProjects/exampleClang/cmake-build-minsizerel'
Any ideas what may be wrong here?

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)

From makefile to Cmake - stm32

I would like to test CLion for my stm32 project since it now support remote debugging! To do so I need to setup Cmake for my project and it is my issue.
I tried using this link which seems to be depreciated so I made some changes. It almost builds but there is a problem with the .elf .bin .hex.
CMakeLists.txt:
project(F466cmake)
cmake_minimum_required(VERSION 3.10)
add_definitions(-DSTM32F446xx)
file(GLOB_RECURSE USER_SOURCES "Src/*.c")
file(GLOB_RECURSE HAL_SOURCES "Drivers/STM32F4xx_HAL_Driver/Src/*.c")
add_library(CMSIS
Drivers/CMSIS/Device/Src/system_stm32f4xx.c
Drivers/CMSIS/Device/Src/startup_stm32f446xx.s)
include_directories(Inc)
include_directories(Drivers/STM32F4xx_HAL_Driver/Inc)
include_directories(Drivers/CMSIS/Inc)
include_directories(Drivers/CMSIS/Device/Inc)
set(CMAKE_C_COMPILER arm-none-eabi-gcc)
set(CMAKE_CXX_COMPILER arm-none-eabi-g++)
set(CMAKE_SYSTEM_NAME Generic)
set(CMAKE_SYSTEM_VERSION 1)
set(LINKER_SCRIPT ${CMAKE_SOURCE_DIR}/STM32F446RETx_FLASH.ld)
set(COMMON_FLAGS "-mcpu=cortex-m4 -mthumb -mthumb-interwork -mfloat-abi=hard -mfpu=fpv4-sp-d16 -ffunction-sections -fdata-sections -g -fno-common -fmessage-length=0")
set(CMAKE_CXX_FLAGS "${COMMON_FLAGS} -std=c++11")
set(CMAKE_C_FLAGS "${COMMON_FLAGS} -std=gnu99")
set(CMAKE_EXE_LINKER_FLAGS "-Wl,-gc-sections -T ${LINKER_SCRIPT}")
add_executable(${PROJECT_NAME}.elf ${USER_SOURCES} ${HAL_SOURCES} ${LINKER_SCRIPT})
target_link_libraries(${PROJECT_NAME}.elf CMSIS)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-Map=${PROJECT_SOURCE_DIR}/build/${PROJECT_NAME}.map")
set(HEX_FILE ${PROJECT_SOURCE_DIR}/build/${PROJECT_NAME}.hex)
set(BIN_FILE ${PROJECT_SOURCE_DIR}/build/${PROJECT_NAME}.bin)
add_custom_command(TARGET ${PROJECT_NAME}.elf POST_BUILD
COMMAND ${CMAKE_OBJCOPY} -Oihex $<TARGET_FILE:${PROJECT_NAME}.elf> ${HEX_FILE}
COMMAND ${CMAKE_OBJCOPY} -Obinary $<TARGET_FILE:${PROJECT_NAME}.elf> ${BIN_FILE}
COMMENT "Building ${HEX_FILE} \nBuilding ${BIN_FILE}")
terminal output:
[ 95%] Building C object CMakeFiles/F466cmake.elf.dir/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_uart.c.o
[100%] Linking C executable F466cmake.elf
/home/flo/bin/gcc-arm-none-eabi-7-2018-q2-update/bin/../lib/gcc/arm-none-eabi/7.3.1/../../../../arm-none-eabi/bin/ld: warning: cannot find entry symbol Reset_Handler; defaulting to 0000000008000000
Building /home/flo/STM32Cube/Testing/build/F466cmake.hex
Building /home/flo/STM32Cube/Testing/build/F466cmake.bin
/usr/bin/objcopy: Unable to recognise the format of the input file `/home/flo/STM32Cube/Testing/build/F466cmake.elf'
CMakeFiles/F466cmake.elf.dir/build.make:563: recipe for target 'F466cmake.elf' failed
make[2]: *** [F466cmake.elf] Error 1
make[2]: *** Deleting file 'F466cmake.elf'
CMakeFiles/Makefile2:104: recipe for target 'CMakeFiles/F466cmake.elf.dir/all' failed
make[1]: *** [CMakeFiles/F466cmake.elf.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2
Got it to work, thanks to Chris for the guidance. The issue was the ASM was not build and I had to link arm object copy.
CMakeLists.txt:
project(F466cmake C ASM)
cmake_minimum_required(VERSION 3.10)
add_definitions(-DSTM32F446xx)
file(GLOB_RECURSE USER_SOURCES "Src/*.c")
file(GLOB_RECURSE HAL_SOURCES "Drivers/STM32F4xx_HAL_Driver/Src/*.c")
add_library(CMSIS
Drivers/CMSIS/Device/Src/system_stm32f4xx.c)
add_library(STARTUP
Drivers/CMSIS/Device/Src/startup_stm32f446xx.s)
set_source_files_properties(Drivers/CMSIS/Device/Src/startup_stm32f446xx.s PROPERTIES COMPILE_FLAGS "-x assembler-with-cpp")
set_property(SOURCE Drivers/CMSIS/Device/Src/startup_stm32f446xx.s PROPERTY LANGUAGE C)
include_directories(Inc)
include_directories(Drivers/STM32F4xx_HAL_Driver/Inc)
include_directories(Drivers/CMSIS/Inc)
include_directories(Drivers/CMSIS/Device/Inc)
set(CMAKE_C_COMPILER arm-none-eabi-gcc)
set(CMAKE_CXX_COMPILER arm-none-eabi-g++)
set(OBJCOPY arm-none-eabi-objcopy)
set(CMAKE_SYSTEM_NAME Generic)
set(CMAKE_SYSTEM_VERSION 1)
set(LINKER_SCRIPT ${CMAKE_SOURCE_DIR}/STM32F446RETx_FLASH.ld)
set(COMMON_FLAGS "-mcpu=cortex-m4 -mthumb -mthumb-interwork -mfloat-abi=hard -mfpu=fpv4-sp-d16 -ffunction-sections -fdata-sections -g -fno-common -fmessage-length=0")
set(CMAKE_CXX_FLAGS "${COMMON_FLAGS} -std=c++11")
set(CMAKE_C_FLAGS "${COMMON_FLAGS} -std=gnu99")
set(CMAKE_EXE_LINKER_FLAGS "-Wl,-gc-sections -T ${LINKER_SCRIPT}")
add_executable(${PROJECT_NAME}.elf ${USER_SOURCES} ${HAL_SOURCES} ${LINKER_SCRIPT})
target_link_libraries(${PROJECT_NAME}.elf CMSIS STARTUP)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-Map=${PROJECT_SOURCE_DIR}/build/${PROJECT_NAME}.map")
set(HEX_FILE ${PROJECT_SOURCE_DIR}/build/${PROJECT_NAME}.hex)
set(BIN_FILE ${PROJECT_SOURCE_DIR}/build/${PROJECT_NAME}.bin)
add_custom_command(TARGET ${PROJECT_NAME}.elf POST_BUILD
COMMAND ${OBJCOPY} -Oihex $<TARGET_FILE:${PROJECT_NAME}.elf> ${HEX_FILE}
COMMAND ${OBJCOPY} -Obinary $<TARGET_FILE:${PROJECT_NAME}.elf> ${BIN_FILE}
COMMENT "Building ${HEX_FILE} \nBuilding ${BIN_FILE}")

cmake package_search_module for glfw3 finds package, doesn't supply full lib path

This seems pretty straightforward but I'm wasting enormous amounts of time getting it working. I just want to build and link a main.cpp file that includes glfw3.h, but cmake is not seeing the lib path for GLFW. the call to package_search_module is providing the right include dir, but the resulting GLFW_LIBRARIES value only has the lib name 'glfw3' in it and its dir is not being given on the command line for the build.
What am I missing here?
Here is my very simple CMakeFiles.txt:
cmake_minimum_required(VERSION 3.3)
project(gltest)
set(CMAKE_VERBOSE_MAKEFILE true)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(SOURCE_FILES main.cpp)
add_executable(gltest ${SOURCE_FILES})
find_package(PkgConfig REQUIRED)
pkg_search_module(GLFW REQUIRED glfw3)
include_directories(${GLFW_INCLUDE_DIRS})
target_link_libraries(gltest ${GLFW_LIBRARIES})
message("GLFW_LIBRARIES=${GLFW_LIBRARIES}")
And here is the build output, where you can see at the top there that GLFW_LIBRARIES contains 'glfw3':
/Applications/CLion.app/Contents/bin/cmake/bin/cmake --build /Users/dave/Library/Caches/CLion12/cmake/generated/7a31a53e/7a31a53e/Debug --target all -- -j 8
/Applications/CLion.app/Contents/bin/cmake/bin/cmake -H/Users/dave/dev/gltest -B/Users/dave/Library/Caches/CLion12/cmake/generated/7a31a53e/7a31a53e/Debug --check-build-system CMakeFiles/Makefile.cmake 0
GLFW_LIBRARIES=glfw3
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/dave/Library/Caches/CLion12/cmake/generated/7a31a53e/7a31a53e/Debug
/Applications/CLion.app/Contents/bin/cmake/bin/cmake -E cmake_progress_start /Users/dave/Library/Caches/CLion12/cmake/generated/7a31a53e/7a31a53e/Debug/CMakeFiles /Users/dave/Library/Caches/CLion12/cmake/generated/7a31a53e/7a31a53e/Debug/CMakeFiles/progress.marks
/Applications/Xcode.app/Contents/Developer/usr/bin/make -f CMakeFiles/Makefile2 all
/Applications/Xcode.app/Contents/Developer/usr/bin/make -f CMakeFiles/gltest.dir/build.make CMakeFiles/gltest.dir/depend
cd /Users/dave/Library/Caches/CLion12/cmake/generated/7a31a53e/7a31a53e/Debug && /Applications/CLion.app/Contents/bin/cmake/bin/cmake -E cmake_depends "Unix Makefiles" /Users/dave/dev/gltest /Users/dave/dev/gltest /Users/dave/Library/Caches/CLion12/cmake/generated/7a31a53e/7a31a53e/Debug /Users/dave/Library/Caches/CLion12/cmake/generated/7a31a53e/7a31a53e/Debug /Users/dave/Library/Caches/CLion12/cmake/generated/7a31a53e/7a31a53e/Debug/CMakeFiles/gltest.dir/DependInfo.cmake --color=
/Applications/Xcode.app/Contents/Developer/usr/bin/make -f CMakeFiles/gltest.dir/build.make CMakeFiles/gltest.dir/build
[ 50%] Linking CXX executable gltest
/Applications/CLion.app/Contents/bin/cmake/bin/cmake -E cmake_link_script CMakeFiles/gltest.dir/link.txt --verbose=1
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -std=c++11 -g -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk -Wl,-search_paths_first -Wl,-headerpad_max_install_names CMakeFiles/gltest.dir/main.cpp.o -o gltest -lglfw3
ld: library not found for -lglfw3
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [gltest] Error 1
make[1]: *** [CMakeFiles/gltest.dir/all] Error 2
make: *** [all] Error 2
And, finally, here is the glfw3.pc pkg-config that is used for the pkg_search_module call:
prefix=/usr/local/Cellar/glfw3/3.2.1
exec_prefix=${prefix}
includedir=${prefix}/include
libdir=${exec_prefix}/lib
Name: GLFW
Description: A multi-platform library for OpenGL, window and input
Version: 3.2.1
URL: http://www.glfw.org/
Requires.private:
Libs: -L${libdir} -lglfw3
Libs.private: -framework Cocoa -framework IOKit -framework CoreFoundation -framework CoreVideo
Cflags: -I${includedir}
~
Update: I got it working with this, but it still feels wrong
cmake docs recommend against using link_directories, but I am able to make this work by using that and building up a list of link libraries:
set(LINK_LIBRARIES )
# GLFW lib
find_package(PkgConfig REQUIRED)
pkg_search_module(GLFW REQUIRED glfw3)
include_directories(${GLFW_INCLUDE_DIRS})
link_directories(${GLFW_LIBRARY_DIRS})
set(LINK_LIBRARIES ${LINK_LIBRARIES} ${GLFW_LIBRARIES})
add_executable(gltest ${SOURCE_FILES})
target_link_libraries(gltest ${LINK_LIBRARIES})
You need <XPREFIX>_LDFLAGS (all required linker flag) and maybe <XPREFIX>_LDFLAGS_OTHER (all other linker flags) with <XPREFIX> = GLFW, acccording to the documentation https://cmake.org/cmake/help/v3.6/module/FindPkgConfig.html

cmake cxx flags only at compile time

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.