-1

I created a static library with cmake. I have a library.h, library.cpp and main.cpp. all my functions declared in library.h and implemented in library.cpp. I make the project using default make file (make all). now I declare some macro (e.g. #ifndef MEM ... #else ...). if macro used, the flags: -DMEM -DPREP=20 -DM=1200 should be added.I added following to my make file:

swtest: CPPFLAGS += -DM=1200 -DMEM -DPREP=20 -g

and then I make project using:

make swtest

and then compile main.cpp with:

g++ main.cpp -o main lib.a -DMEM -DPREP=20 -DM=1200 -g

but it does not work. I think I should add some code to my cmakelists file but I don't know how! I emphasize that my macros added to library.cpp not main.cpp. note that I'm using clion.

  • 1
    Why do you show snippets from a makefile, but claim to be using CMake? – fabian May 31 '21 at 20:25
  • If you want to use different compiler flags for different source files, then use `set_source_files_properties` command as described in [that answer](https://stackoverflow.com/questions/44635314/how-to-compile-with-different-compile-options-for-different-files-in-cmake). – Tsyvarev May 31 '21 at 23:04

1 Answers1

0

You need to make sure you specify the defines when compiling library.cpp.

Buddy
  • 10,874
  • 5
  • 41
  • 58