English 中文(简体)
Generate Makefile that builds the same executable with different flags depending on build target
原标题:
  • 时间:2023-05-23 02:57:28
  •  标签:
  • cmake

How do I write a CMakeLists.txt file so that cmake generates a Makefile with functionality equivalent to

all: proj

debug: CXXFLAGS += -DDEBUG -g -Og
debug: proj

proj: 
    $(CXX) $(CXXFLAGS) main.cpp -o proj

In other words, I want to be able to build the same executable in the same folder with make [build_target], but depending on the build target, with different flags.

Currently I have

cmake_minimum_required(VERSION 3.12)

set(PROJ_NAME "proj")

project(${PROJ_NAME} CXX)
add_executable(${PROJ_NAME} main.cpp)

add_custom_target(debug)
target_compile_definitions(debug PUBLIC -DDEBUG -g -Og)

But when I m calling cmake, I get an error saying target_compile_definitions called with non-compilable target type, and I don t know how to make it "compilable".

问题回答

暂无回答




相关问题
Why can t CLion see header files, WSL2 toolchain?

My setup: Windows 10 Pro 22H2 (19045.2965) CLion 2020.1.3 (JetBrains) WSL2 with Ubuntu 22.04.2 LTS gcc 11.3.0 cmake 3.22.1 gdb 12.1 gmake 4.3 CMakeLists.txt cmake_minimum_required(VERSION 3.22)...

CMake linking problem

I am trying to use CMake to compile a C++ application that uses the C library GStreamer. My main.cpp file looks like this: extern "C" { #include <gst/gst.h> #include <glib.h> } int main(...

How to add an extra plist property using CMake?

I m trying to add the item <key>UIStatusBarHidden</key><true/> to my plist that s auto-generated by CMake. For certain keys, it appears there are pre-defined ways to add an item; ...

(c)make - resursive compile

Let s assume I have directories like: dir1 main.cpp dir2 abc.cpp dir3 def.cpp dir4 ghi.cpp jkl.cpp And let s assume that main.cpp ...

Reading registry values with cmake

On a Windows 7 machine I cannot read any registry values that contain a semicolon. For example if you have 7-zip, running the following SET(MYPATH [HKEY_LOCAL_MACHINE\SOFTWARE\7-Zip;Path]) ...

Finding the correct Python framework with cmake

I am using the macports version of python on a Snow Leopard computer, and using cmake to build a cross-platform extension to it. I search for the python interpreter and libraries on the system using ...

热门标签