On 11/06/2010 05:26 PM, luxInteg wrote: > Greetings, > > I am learning cmake. > > I have a question on using add_library. in my project(learnCMAKE). The > latter has:- > > ---a) 2 source files file1.c file2.c > ---b) the envar {CFLAGS} set > ---c) need to generate libLearnCMAKE.so and libLearnCMAKE.a
ADD_LIBRARY(LearnCMAKE-shared SHARED file1.c file2.c) ADD_LIBRARY(LearnCMAKE-static STATIC file1.c file2.c) SET_TARGET_PROPERTIES(LearnCMAKE-shared LearnCMAKE-static PROPERTIES OUTPUT_NAME LearnCMAKE) > ---d) need to add preprocessor agruments -DXXX to CFLAGS in the compilation > of the source files before liberies are archived like so:- > > gcc ${CFLAGS} -DDINT /path/to/file1.c > gcc ${CFLAGS} -DDINT /path/to/file2.c > > gcc ${CFLAGS} -DDLONG /path/to/file1.c > gcc ${CFLAGS} -DDLONG /path/to/file2.c SET_TARGET_PROPERTIES(LearnCMAKE-shared LearnCMAKE-static PROPERTIES COMPILE_DEFINITIONS DINT) or SET_SOURCE_FILES_PROPERTIES(/path/to/file1.c /path/to/file2.c PROPERTIES COMPILE_DEFINITIONS DINT) or SET_DIRECTORY_PROPERTIES( PROPERTIES COMPILE_DEFINITIONS DINT) or ADD_DEFINITIONS(-DDINT) or SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DDINT") If the CFLAGS environment variable is defined when CMake runs the first time on the project the flags are taken for CMAKE_C_FLAGS, but consider to set the latter in the CMakeLists.txt or from the command line or the GUI, so you don't need to have a properly set up environment to succeed. > How can this be achived in a marco or whatever with add_library ? > Help would be appreciated Regards, Michael _______________________________________________ Powered by www.kitware.com Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Follow this link to subscribe/unsubscribe: http://www.cmake.org/mailman/listinfo/cmake