Re: [CMake] How can I create a C executable and C++ library from the same source

2018-01-17 Thread Matthew Keeler
Whether what you want exactly is possible I dont know. If you are just
wanting your C++ test library to be able to test your C source then I would
still let them compile as C and just extern “C” { #include  }.
When it gets linked all together it should be fine. This is how I usually
do testing of my C code with cpputest which is also a C++ library.

-- 
Matt Keeler


On January 17, 2018 at 13:05:36, Jimi Damon (jda...@accesio.com) wrote:

Hi,

I want to use Gtest for some unit tests on a number of the C functions that
comprise my C executable.  However, Gtest ( And gMock ) are C++ testing
frameworks.

What I would like to have is a project for my exe and then a separate
project for my C++ library and be able to change the source properties to
use the language CXX just before compiling.

The problem I'm having is that CMake uses the CXX compiler for the C files.


Here's what I would like to have

project(cexe)
set(SOURCES foo.c bar.c )
add_executable( cexe  ${SOURCES} )

project(cpplib)
set_source_files_properties(${SOURCES} PROPERTIES LANGUAGE CXX )
add_library( cpplib SHARED ${SOURCES} )



Is there a way to do this ?

Can target_compile_options set the compile type for a given target ?


In the past I've had to copy the .C files to some renamed .CPP equivalent
and then compile off of that.

I'm hoping that enough new functionality has been added to Cmake to allow
separation between compiles.


Thanks,




--

Jimi Damon
ACCES I/O Products, Inc. 
Linux Engineer
jda...@accesio.com
(858) 550-7320 x3015
[image: ACCES I/O Logo]
10623 Roselle Street San Diego CA 92121-1506 


WARNING - This e-mail or its attachments may contain controlled technical
data or controlled technology within the definition of the International
Traffic in Arms Regulations (ITAR) or Export Administration Regulations
(EAR), and are subject to the export control laws of the U.S. Government.
Transfer of this data or technology by any means to a foreign person,
whether in the United States or abroad, without an export license or other
approval from the U.S. Government, is prohibited. The information contained
in this document is CONFIDENTIAL and property of ACCES I/O Products, Inc.
Any unauthorized review, use, disclosure or distribution is prohibited
without express written consent of ACCES I/O Products, Inc. If you are not
the intended recipient, please contact the sender and destroy all copies of
the original message and enclosed attachments. --

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at:
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake
-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake


Re: [CMake] Custom target for running tests as part of the build

2016-08-23 Thread Matthew Keeler
One thing I see immediately is this line:

$ > ${TEST_NAME}.output || cat ${TEST_NAME}.output

Unless ${TEST_NAME}.output doesn’t exist cat is going to have a successful
exit status and cause the whole COMMAND to be successful. Something like
“|| (cat ${TEST_NAME}.output && false)” should work in bash. When the test
passes everything in the parens won’t be executed but when it does it will
still force a bad exit status.
For a cross platform solution I would create a cmake script to do the grunt
work of executing the test.

COMMAND ${CMAKE_COMMAND} -DTEST_EXEC=
-DTEST_NAME=${TEST_NAME} -P test-runner.cmake

Then in the script it could do something like the following:

execute_process(COMMAND ${TEST_EXEC} OUTPUT_FILE ${TEST_NAME}.out
ERROR_FILE ${TEST_NAME}.out RESULT_VARIABLE TEST_SUCCESS)
if (NOT TEST_SUCCESS EQUAL 0)
execute_process(COMMAND cat ${TEST_NAME}.out)
message(FATAL_ERROR “Execution of ${TEST_EXEC} exited with a failure
status”)
endif()

execute_process(COMMAND ${CMAKE_COMMAND} -E touch ${TEST_NAME}.passed)


Depending on how much you need the cross platform solution the ugliness of
the extra indirection may not be desirable for you.

-- 
Matt Keeler


On August 23, 2016 at 11:20:48, Steve Lorimer (steve.lori...@gmail.com)
wrote:

We have several unit tests which we would like to be run as part of our
build process.

To achieve this I have a helper script which creates a custom command that
runs the test, and if successful, creates a file "test_name.passed".

I then add a custom target "test_name.run" which depends on
"test_name.passed".

The idea is that if "test_name.passed" doesn't exist or is older than
"test_name", the custom command will be run.

Builds will continue to run the custom command until the test passes.
Subsequent builds won't call the custom command, so the test won't be run
if it doesn't need to.

Here is the script:

# create test.passed command which runs the test and creates a sentinel
file if it passes
add_custom_command(
OUTPUT  ${TEST_NAME}.passed
COMMAND $
COMMAND ${CMAKE_COMMAND} -E touch ${TEST_NAME}.passed
DEPENDS ${TEST_NAME}
)

# create test.run module which depends on test.passed
add_custom_target(${TEST_NAME}.run
ALL
DEPENDS ${TEST_NAME}.passed
)

The problem is that our tests often log a tonne of information to stdout,
and it makes for a very noisy build.

I'm trying to now capture stdout to a file, and only in the event of a
failure, display the test output.

My first attempt was to try a Bash shell scripting syntax - capture stdout
into a file and when the exit status is an error, cat the file.

add_custom_command(
OUTPUT  ${TEST_NAME}.passed
COMMAND $ > ${TEST_NAME}.output || cat
${TEST_NAME}.output
COMMAND ${CMAKE_COMMAND} -E touch ${TEST_NAME}.passed
DEPENDS ${TEST_NAME}
)

This doesn't work, as even if the test fails I am getting the sentinal
"test_name.passed" file created, which means the next time I try to build
it thinks the test passed.

Is there a way to achieve what I want? Bonus points for a cross-platform
method, but if it has to be Linux only, then so be it.

Thanks in advance
Steve

-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at:
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake
-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake

Re: [CMake] cmake install target doesn't run ldconfig after installing library

2016-06-17 Thread Matthew Keeler
So I did some experimenting. It would seem there are a few rules to the
order installs are executed

1 - installs are processed in the order the containing CMakeLists.txt files
are
2 - within a CMakeLists.txt they seem to be ordered based on which comes
first in the file.

So a not so elegant workaround would be to create a post-install directory
in your source tree and have the last line of your main CMakeLists.txt be
to add_subdirectory(post-install). Then all your post-install logic can
live in there.

-- 
Matt Keeler


On June 16, 2016 at 21:01:46, Young Yang (afe.yo...@gmail.com) wrote:

Thanks!
This command really solve my problem.

But I still get a problem about the command order now.

I have some sub directories.
For e.g. One of them is called "src" and there is also a CMakeLists.txt in
it. And the shared library installation instructions are in it.
So I have `ADD_SUBDIRECTORY(src)` in my main CMakeLists.txt.

I put the command `install(CODE "execute_process(COMMAND ldconfig)")`
 after `ADD_SUBDIRECTORY(src)` . But It still  run ldconfig before the
installation of shared libraries in src sub folder.



On Thu, Jun 16, 2016 at 9:02 PM, Matthew Keeler <mkee...@tenable.com> wrote:

> CMake won’t and in my opinion shouldn’t implicitly invoke ldconfig for
> you. There are many scenarios and platforms where this is incorrect
> behavior and some such as running install to prepare for packaging that
> CMake wouldn’t reliably be able to detect.
>
> If you want to provide the functionality for your users you could add
> something like the following to your CMakeLists.txt:
>
> install(CODE “execute_process(COMMAND ldconfig)”)
>
> This will need to run after your other installed targets. I can’t find any
> way in the CMake documentation to force install ordering but it seems like
> as long as CMake processes that install command last it will perform it
> last. So at the very end of your top level CMakeLists.txt file should do
> the trick.
>
> --
> Matt Keeler
>
>
> On June 15, 2016 at 22:12:09, Young Yang (afe.yo...@gmail.com) wrote:
>
> Hi,
> I've encountered some problem when writing install target with cmake.
>
> I use `install (TARGETS  DESTINATION lib)` to install
> my shared_library.
> However, when I run `make install`. It just install the .so to
> /usr/local/lib and didn't run the ldconfig.
>
> I think it is strange and inconvenient to tell the user he should run
> ldconfig by himself or herself.
>
> What is the best way to make the ldconfig run automatically?
>
>
> Thanks in advance :)
>
> --
> Best wishes,
> Young Yang
> --
>
> Powered by www.kitware.com
>
> Please keep messages on-topic and check the CMake FAQ at:
> http://www.cmake.org/Wiki/CMake_FAQ
>
> Kitware offers various services to support the CMake community. For more
> information on each offering, please visit:
>
> CMake Support: http://cmake.org/cmake/help/support.html
> CMake Consulting: http://cmake.org/cmake/help/consulting.html
> CMake Training Courses: http://cmake.org/cmake/help/training.html
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/cmake
>
>


--
Best wishes,
Young Yang
-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake

Re: [CMake] cmake install target doesn't run ldconfig after installing library

2016-06-16 Thread Matthew Keeler
CMake won’t and in my opinion shouldn’t implicitly invoke ldconfig for you.
There are many scenarios and platforms where this is incorrect behavior and
some such as running install to prepare for packaging that CMake wouldn’t
reliably be able to detect.

If you want to provide the functionality for your users you could add
something like the following to your CMakeLists.txt:

install(CODE “execute_process(COMMAND ldconfig)”)

This will need to run after your other installed targets. I can’t find any
way in the CMake documentation to force install ordering but it seems like
as long as CMake processes that install command last it will perform it
last. So at the very end of your top level CMakeLists.txt file should do
the trick.

-- 
Matt Keeler


On June 15, 2016 at 22:12:09, Young Yang (afe.yo...@gmail.com) wrote:

Hi,
I've encountered some problem when writing install target with cmake.

I use `install (TARGETS  DESTINATION lib)` to install my
shared_library.
However, when I run `make install`. It just install the .so to
/usr/local/lib and didn't run the ldconfig.

I think it is strange and inconvenient to tell the user he should run
ldconfig by himself or herself.

What is the best way to make the ldconfig run automatically?


Thanks in advance :)

--
Best wishes,
Young Yang
-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at:
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake
-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake

Re: [CMake] LINK_FLAGS directory property

2016-05-02 Thread Matthew Keeler
I am doing that for some things but it gets quite cumbersome as I have to 
override those for several different configurations. I guess that is the only 
way to do it currently. 

-- 
Matt Keeler


On May 2, 2016 at 03:48:59, Attila Krasznahorkay 
(attila.krasznahor...@gmail.com) wrote:

Hi Matt,  

Have you tried using the  

CMAKE_EXE_LINKER_FLAGS  
CMAKE_SHARED_LINKER_FLAGS  
CMAKE_MODULE_LINKER_FLAGS  

cache variables? These actually set these flags globally, and not just for one 
directory, but on the directory level they are easy to override. You can just 
do something like this in a subdirectory:  

string( REPLACE "-Wl,--as-needed" "" CMAKE_SHARED_LINKER_FLAGS 
"${CMAKE_SHARED_LINKER_FLAGS}" )  

Cheers,  
Attila  

> On 27 Apr 2016, at 17:57, Matthew Keeler <mkee...@tenable.com> wrote:  
>  
> Is there an equivalent directory property for the target level LINK_FLAGS 
> property. I can’t see anything according to the documentation but was hoping 
> there was an oversight and something actually existed.  
>  
> What I am trying to do is pass extra flags to the linker for every target in 
> my project and I didn’t want to have to set it per target. I tried using the 
> link_libraries command but the flags I am adding are msvc specific and start 
> with ‘/‘ and cmake seems to be turning these into ‘\’ when its passed to the 
> linker. Then the linker thinks its trying to link in another file and 
> everything blows up.  
>  
> Also a secondary question is what does the INTERPROCEDURAL_OPTIMIZATIONS 
> property at the directory level do. I assume on Windows it passes /GL to the 
> compiler but will this also add /LCTG to the linker flags and prevent 
> incremental linking. If I turn this property on will it also do it for debug 
> configurations or just optimized configurations?  
>  
> --  
> Matt Keeler  
>  
> --  
>  
> Powered by www.kitware.com  
>  
> Please keep messages on-topic and check the CMake FAQ at: 
> http://www.cmake.org/Wiki/CMake_FAQ  
>  
> Kitware offers various services to support the CMake community. For more 
> information on each offering, please visit:  
>  
> CMake Support: http://cmake.org/cmake/help/support.html  
> CMake Consulting: http://cmake.org/cmake/help/consulting.html  
> CMake Training Courses: http://cmake.org/cmake/help/training.html  
>  
> Visit other Kitware open-source projects at 
> http://www.kitware.com/opensource/opensource.html  
>  
> Follow this link to subscribe/unsubscribe:  
> http://public.kitware.com/mailman/listinfo/cmake  

-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake

[CMake] LINK_FLAGS directory property

2016-04-27 Thread Matthew Keeler
Is there an equivalent directory property for the target level LINK_FLAGS 
property. I can’t see anything according to the documentation but was hoping 
there was an oversight and something actually existed.

What I am trying to do is pass extra flags to the linker for every target in my 
project and I didn’t want to have to set it per target. I tried using the 
link_libraries command but the flags I am adding are msvc specific and start 
with ‘/‘ and cmake seems to be turning these into ‘\’ when its passed to the 
linker. Then the linker thinks its trying to link in another file and 
everything blows up.

Also a secondary question is what does the INTERPROCEDURAL_OPTIMIZATIONS 
property at the directory level do. I assume on Windows it passes /GL to the 
compiler but will this also add /LCTG to the linker flags and prevent 
incremental linking. If I turn this property on will it also do it for debug 
configurations or just optimized configurations?

-- 
Matt Keeler

-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake

Re: [CMake] OBJECT Libraries with Xcode Generator

2016-04-06 Thread Matthew Keeler
Ah, I thought cmake was controlling the output filenames of the compiler and 
not Xcode. Then its not really a cmake problem. Changing source names is easy 
enough. I was just curious. Also in the real case I could just as easily use a 
STATIC library instead but normally go for OBJECT libraries first. Oh well. 
Thanks for the info.

-- 
Matthew Keeler
On April 6, 2016 at 16:06:11, Brad King (brad.k...@kitware.com) wrote:

On 04/06/2016 03:47 PM, Gregor Jasny wrote:  
> On 06/04/16 20:32, Matthew Keeler wrote:  
>> clang: error: no such file or directory:  
>> '.../lib/example.build/Debug/example.build/Objects-normal/x86_64/x.o'  
>>  
>> Within the directory 
>> .../lib/example.build/Debug/example.build/Objects-normal/x86_64  
>> there is in fact no x.o. Instead there are two files, x-8171277E06B93FB2.o 
>> and  
>> x-FA155118579B6D7E.o. So it looks like for the XCode generators sources 
>> intermediate  
>> object files for a single CMakeLists.txt are stored within a single 
>> directory.  
>> And in this case the sources have the same name so the x-.o names are 
>> used instead.  
>> However the $<TARGET_OBJECTS:…> generator expression seems to be referencing 
>> an  
>> incorrect name. Is there any workaround so that for the Xcode generator it 
>> will  
>> not store all the build artifacts in a single directory and not use the 
>> object  
>> file name with the unique id in it  

It is unlikely CMake will be able to predict the object file names  
Xcode will choose for repeated sources, so yes it would be nice to  
be able to tell Xcode to put the objects in separate directories.  
I don't know whether this is possible though.  

As a workaround you could either rename one source or add/generate  
another source with a different name that uses #include to get the  
original.  

>> and secondly where is the proper place to file a bug for this.  
> Thank you for the minimal example. Please file a bug in the bug tracker.  

https://cmake.org/Bug  

Thanks,  
-Brad  

-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake

[CMake] OBJECT Libraries with Xcode Generator

2016-04-06 Thread Matthew Keeler
 
I think I ran into a bug but I am wondering if anyone has seen it an worked 
around.

I have a source structure like the following (this is a contrived small example 
to illustrate the problem):  

- CMakeLists.txt  
- main.c
- lib
   - CMakeLists.txt
   - x.c
   - x.h
   - alt1
      - x.c
      - x.h
   - alt2
      - x.c
      - x.h

CMakeLists.txt:

   cmake_minimum_required(VERSION 3.5)
   project(example)
   add_subdirectory(lib)
   include_directories(lib)
   add_executable(main main.c $)


main.c:

   #include "x.h"
   
   int main()
   {
      return example_func();
   }

lib/CMakeLists.txt:

   option(ALT1 "ALT1" ON)
   option(ALT2 "ALT2" ON)
   set(SOURCES x.c)
   if ( ALT1 )
      add_definitions(-DALT1)
      list(APPEND SOURCES alt1/x.c)
   elseif ( ALT2 )
      add_definitions(-DALT2)
      list(APPEND SOURCES alt2/x.c)
   else ()
       message(FATAL_ERROR "No alt defined")
   endif()
   add_library(example OBJECT ${SOURCES})

lib/x.h:

   #ifndef X_H
   #define X_H
   int example_func();
   #endif

lib/x.c:

#include "x.h"
#ifdef ALT2
#include "alt2/x.h"
#else
#include "alt1/x.h"
#endif
int example_func()
{
return call_example_func();
}


lib/alt1/x.h:

   #ifndef ALT1_X_H
   #define ALT1_X_H
   int alt1_example_func();
   #define call_example_func() alt1_example_func()
   #endif


lib/alt1/x.c:

   int alt1_example_func()
   {
      return 1;
   }

lib/alt2/x.h:

   #ifndef ALT2_X_H
   #define ALT2_X_H
   int alt2_example_func();
   #define call_example_func() alt2_example_func()
   #endif


lib/alt2/x.c:

   int alt2_example_func()
   {
      return 2;
   }



Now if I run cmake using the makefile generator and then run make, all is well 
and everything is built and runs as expected. If I use the Xcode generator I 
get the following errors:

clang: error: no such file or directory: ‘/lib/example.build/Debug/example.build/Objects-normal/x86_64/x.o’

Within the directory /lib/example.build/Debug/example.build/Objects-normal/x86_64 there is 
in fact no x.o. Instead there are two files, x-8171277E06B93FB2.o and 
x-FA155118579B6D7E.o. So it looks like for the XCode generators sources 
intermediate object files for a single CMakeLists.txt are stored within a 
single directory. And in this case the sources have the same name so the 
x-.o names are used instead. However the $<TARGET_OBJECTS:…> generator 
expression seems to be referencing an incorrect name. Is there any workaround 
so that for the Xcode generator it will not store all the build artifacts in a 
single directory and not use the object file name with the unique id in it and 
secondly where is the proper place to file a bug for this.

--  
Matthew Keeler


-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake

Re: [CMake] Calling a Python Testing Script from CMake/CTest

2016-02-24 Thread Matthew Keeler
My guess is that the command prompt is seeing the .py extension and 
automatically invoking the python interpreter for you. On other platforms it 
looks for the #!/usr/bin/env python which won’t work on windows.What you should 
do is use the FindPythonInterp cmake module to find your python executable and 
specify the interpreter to execute in your add test line. 
https://cmake.org/cmake/help/v3.3/module/FindPythonInterp.html

Something like the following should work (I have not tested so the syntax might 
need some slight tweaks).

include(FindPythonInterp)
add_test(NAME sample_test COMMAND ${PYTHON_EXECUTABLE} 
${CMAKE_CURRENT_SOURCE_DIR}/sample_test.py WORKING_DIRECTORY 
${EXECUTABLE_OUTPUT_PATH} )

-- 
Matthew Keeler
On February 24, 2016 at 09:15:10, George Ryan (george.r...@geospectrum.ca) 
wrote:

Hi,  

I am having difficulty getting a python script to run a C++ subprocess  
on Window 7 using VS2013. On Linux, the following code works fine, but  
on Windows, from the command line I get the following output:  

Microsoft (R) Program Maintenance Utility Version 12.00.21005.1  
Copyright (C) Microsoft Corporation. All rights reserved.  

Running tests...  
Test project C:/work/s/sandbox/ctestpy/b  
Start 1: sample_test  
1/1 Test #1: sample_test ..***Not Run 0.00 sec  

0% tests passed, 1 tests failed out of 1  

Total Test time (real) = 0.06 sec  

The following tests FAILED:  
1 - sample_test (BAD_COMMAND)  
Errors while running CTest  
NMAKE : fatal error U1077: 'echo' : return code '0x8'  
Stop.  

No matter what options I supply to ctest, I can't seem to get any  
additional insight. I am assuming that for some reason the  
WORKING_DIRECTORY isn't being obeyed on Windows?  

If I run the python script manually from the command prompt, it works  
fine. The python executable is in my $PATH.On Linux I am using CMake  
3.3.1, and on Windows I have CMake 3.2.3.  

  

sample.cpp  

int main()  
{  
return 0;  
}  

--  

sample_test.py  

#!/usr/bin/env python  
import sys  
import subprocess  

sample = subprocess.Popen("./sample")  
sample.wait()  
if sample.returncode != 0:  
sys.exit(1)  
else:  
sys.exit(0)  
~  
  

CMakeLists.txt  

cmake_minimum_required(VERSION 3.0)  
project(sampleprg)  

enable_testing()  

add_executable( sample sample.cpp )  

add_test(NAME sample_test  
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/sample_test.py  
WORKING_DIRECTORY ${EXECUTABLE_OUTPUT_PATH} )  




--  

Powered by www.kitware.com  

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ  

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:  

CMake Support: http://cmake.org/cmake/help/support.html  
CMake Consulting: http://cmake.org/cmake/help/consulting.html  
CMake Training Courses: http://cmake.org/cmake/help/training.html  

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html  

Follow this link to subscribe/unsubscribe:  
http://public.kitware.com/mailman/listinfo/cmake  
-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake

Re: [CMake] Porting to CMAKE and utilizing the CPack

2015-11-12 Thread Matthew Keeler
Installing arbitrary files is accomplished by adding install commands into your 
CMakeLists. The documentation for the command is here: 
https://cmake.org/cmake/help/v3.3/command/install.html

For something like an init script or systemd unit file they are going to live 
outside the normal installation prefix. So you will need to do something like 
the following:

if (IS_DIRECTORY /usr/lib/systemd/system)
install(FILES myprog.service DESTINATION /usr/lib/systemd/system)
else()
install(FILES myprog DESTINATION /etc/init.d)
endif()

That code block will install the myprog.service file into 
/usr/lib/systemd/system if that directory exists and if not will install the 
myprog file (init script) int /etc/init.d

I have found that checking if the usual systemd directory exists is sufficient 
to determine that systemd is present on the build system. If you are compiling 
on one debian version but want to support multiple versions then you will most 
likely install your init script and systemd files into some place specific to 
your application and use a post install script to detect which version should 
get installed. This will however bypass the package manager for installing 
these and thus if the package is removed/altered dpkg wont handle anything for 
you regarding these files.

Check out the CpackDeb documentation for all the various variables that can be 
set to alter how the package builds and installs: 
https://cmake.org/cmake/help/v3.3/module/CPackDeb.html
In particular if you need to have postinstall scripts then you will want to set 
the variable CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA
--
Matt Keeler


On November 12, 2015 at 07:37:14, Šimon Tóth 
(t...@fi.muni.cz) wrote:

I have managed to port my SW to CMake fine, but now I'm running into
issues with the CPack package generation (debian packages for now).

I'm using the "dh_" commands in the package generation for debian.
What would be the equivalent in CMake? In particular, installing cron
scripts, init.d scripts and systemd service files.

Also is there a way to detect the presence systemd (and install systemd
service file if this is the case, init.d script otherwise)?

--
RNDr. Šimon Tóth
FI@MU (t...@fi.muni.cz) | CESNET (si...@cesnet.cz)
--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake
-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake

Re: [CMake] Python project using Cmake

2015-10-22 Thread Matthew Keeler
Sorry Srinivas, the projects was for a former employer of mine and I no longer 
have access to it. We were distributing “scripts” as executable zip files (a 
lesser known feature of Python). So we had a few things going on.

include(FindPythonInterp)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/setup.py.in 
${CMAKE_CURRENT_BINARY_DIR}/setup.py @ONLY)
add_custom_command(${CMAKE_CURRENT_BINARY_DIR}/ COMMAND 
${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/setup.py bdist -format zip 
COMMAND …)

For the add_custom_command we ran more commands after invoking python to run 
the setup.py file. The extra commands were to rename from the normal distutils 
name to the final name and to prepend a UNIX #!/usr/bin/env python text line to 
the zip file. In this way you can make a self contained “executable” that on 
UNIX at least runs like any other binary.

All of the add_custom_command logic to build these zip executables was put into 
a cmake function:
https://cmake.org/cmake/help/v3.3/command/function.html

If you do go the function route I would recommend taking a look at the 
CMakeParseArguments module it was very useful for me.
https://cmake.org/cmake/help/v3.3/module/CMakeParseArguments.html

Sorry I don’t have more specifics.

--
Matt Keeler


On October 21, 2015 at 16:21:36, srinivas boppu 
(srinivas.bo...@gmail.com<mailto:srinivas.bo...@gmail.com>) wrote:

Hi Matthew Keeler,

Thanks for your quick reply. My project is a pure python project. I wanted to 
use cmake and ctest for testing my individual python modules. Later on, I might 
have some "tcl" scripts and may be some c++ sources in the same project.

It would be great, if you could share your pure python project details and the 
macros or related documents.

Thanks and Regards,
Srinivas Boppu




On Wed, Oct 21, 2015 at 9:52 PM, Matthew Keeler 
<mkee...@tenable.com<mailto:mkee...@tenable.com>> wrote:
What are you trying to do? Are you trying to build Python C extensions? If so 
then the FindPythonLibs module will help you in that regard. It will determine 
if the Python development files are installed and populate variables with the 
necessary paths to provide to link_directories and include_directories. 
https://cmake.org/cmake/help/v3.3/module/FindPythonLibs.html

Additionally there is the FindPythonInterp module which will find the Python 
interpreter for invoking via custom commands or execute_process.
https://cmake.org/cmake/help/v3.3/module/FindPythonInterp.html

Also if you aren’t actually compiling any C/C++ code it will speed up build 
system generation if you specify the languages as NONE during the project 
command invocation. That behavior is documented at: 
https://cmake.org/cmake/help/v3.3/command/project.html

In the past I have used cmake even for pure Python projects to just get the 
benefits of generic packaging with cpack and to be able to use ctest. If this 
is the case for you then you may end up defining a bunch of functions/macros to 
do all the work as I did.

--
Matt Keeler


On October 21, 2015 at 11:28:28, srinivas boppu 
(srinivas.bo...@gmail.com<mailto:srinivas.bo...@gmail.com>) wrote:

Hello All,

I am new to cmake and its build and ctest system. I read some where that cmake 
default look for c++ compiler and we need to modify/configure the cmake to 
recongize the python files.
I googled for the same but I couldn't find any concrete and complete example.
Any pointers in this regard would be useful.

Thanks in advance.

--
Apologizing doesn't mean U r wrong & the other is right,It means that U value 
the relationship more than Ur ego...

--

Powered by www.kitware.com<http://www.kitware.com>

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake



--
Apologizing doesn't mean U r wrong & the other is right,It means that U value 
the relationship more than Ur ego...

-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake

Re: [CMake] Python project using Cmake

2015-10-21 Thread Matthew Keeler
What are you trying to do? Are you trying to build Python C extensions? If so 
then the FindPythonLibs module will help you in that regard. It will determine 
if the Python development files are installed and populate variables with the 
necessary paths to provide to link_directories and include_directories. 
https://cmake.org/cmake/help/v3.3/module/FindPythonLibs.html

Additionally there is the FindPythonInterp module which will find the Python 
interpreter for invoking via custom commands or execute_process.
https://cmake.org/cmake/help/v3.3/module/FindPythonInterp.html

Also if you aren’t actually compiling any C/C++ code it will speed up build 
system generation if you specify the languages as NONE during the project 
command invocation. That behavior is documented at: 
https://cmake.org/cmake/help/v3.3/command/project.html

In the past I have used cmake even for pure Python projects to just get the 
benefits of generic packaging with cpack and to be able to use ctest. If this 
is the case for you then you may end up defining a bunch of functions/macros to 
do all the work as I did.

--
Matt Keeler


On October 21, 2015 at 11:28:28, srinivas boppu 
(srinivas.bo...@gmail.com) wrote:

Hello All,

I am new to cmake and its build and ctest system. I read some where that cmake 
default look for c++ compiler and we need to modify/configure the cmake to 
recongize the python files.
I googled for the same but I couldn't find any concrete and complete example.
Any pointers in this regard would be useful.

Thanks in advance.

--
Apologizing doesn't mean U r wrong & the other is right,It means that U value 
the relationship more than Ur ego...

--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake
-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake

[CMake] Is there a variable containing the C flags that would be used to compile something in a directory

2015-09-29 Thread Matthew Keeler
There are various variables like CMAKE_C_FLAGS_ that can influence the 
final flags sent to the compiler. Is there a variable that exists or a function 
to call to get the final C flags.

What I am trying to do is invoke a custom command to run make on an external 
source tree. This makefile has CC, AR, RANLIB CFLAGS and LDFLAGS variables. The 
command I would like to do is

add_custom_command( COMMAND make CC=${CMAKE_C_COMPILER} AR=${CMAKE_AR} 
RANLIB=${CMAKE_RANLIB} CFLAGS= LDFLAGS= ……)

However it doesn’t seem like there is a variable that contains a set of all the 
flags that cmake would use. For example, when building on OS X the 
-mmacosx-version-min flag gets tacked on by cmake but I can’t find a variable 
that contains this flag.

Is there a way to do what I want or am I going to have to manage all the C 
flags manually?

--
Matt Keeler
-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake