Hi all,

I am just getting started with CMake. Here is my question: Is there a
good way to have an external config file that specifies both the
compiler an compile flags?

The program is compiled many times, and it makes sense to have the
compiler and flags in a config file rather than have them in the
command line. I am hoping to use CMake itself as the language of the
config file. For example:

# -----   myprogram.cmake -----
# Local configuration file.

set (CMAKE_Fortran_COMPILER      "mpif90")
set (CMAKE_Fortran_FLAGS         "-fdefault-real-8")
set (CMAKE_Fortran_FLAGS_DEBUG   "-O0 -g -fbounds-check")
set (CMAKE_Fortran_FLAGS_RELEASE "-O3")
set (CMAKE_BUILD_TYPE             RELEASE)


I think this would be a useful config file and I can just "include" it
in CMakeLists.txt. The problem is that the compiler must be specified
before I run project(), while the compile flags must be specified
AFTER project():


cmake_minimum_required (VERSION 2.8)
include ("path/to/myprogram.cmake")
enable_language (Fortran)
project (MyProgram)


At this point all the compile flags have been overwritten by
enable_language() and project().  Can anyone suggest a good solution?
I have a few ideas, but I am not sure about them:

1) I could give up on the idea of using CMake in the config file. The
config file could be a shell script that sets some environment
variables. My understanding is that this will work, but you would lose
the flexibility of CMake.

2) I could load the config file twice. Once before, and once after
project(). I am not sure if this would have any unexpected
side-effects.

3) I could store the flags in the cache. But I am not sure if
overwriting the cache is a good idea or not.

4) I could use a shell script to split the config file into the
compiler part and everything else, and then load them separately. I
think I like this option, but I am not fully aware of the
side-effects.

Does anyone have any words of advice or wisdom to share with me?

Cheers,
Daniel.
--
Lord of the rings calendar in your Linux/Unix/Mac terminal: cat
/usr/share/calendar/calendar.lotr
--

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

Reply via email to