[CMake] Question about CHECK_C_COMPILER_FLAG

2016-06-17 Thread Sergei Nikulov
Hi All,

I have a question about CHECK_C_COMPILER_FLAG behaviour.

Documentation will tell that "the compiler does not give an error
message when it encounters the flag".
Unfortunately, it not only compiles but try to link executable.

If linker fails, due missed libraries it also does not produce
positive result even if compilation was successful.

Is it expected behaviour or issue?

My example environment

cmake v3.4.3/Linux/gcc v4.8.5

check_c_compiler_flag("-fsanitize=address" HAVE_C_FLAG_asan)

Log in CMakeError.log
...
erforming C SOURCE FILE Test HAVE_C_FLAG_asan failed with the following output:
Change Dir: /home/snikulov/work/github/curl/build/CMakeFiles/CMakeTmp

Run Build Command:"/usr/bin/gmake" "cmTC_846be/fast"
/usr/bin/gmake -f CMakeFiles/cmTC_846be.dir/build.make
CMakeFiles/cmTC_846be.dir/build
gmake[1]: Entering directory
`/home/snikulov/work/github/curl/build/CMakeFiles/CMakeTmp'
Building C object CMakeFiles/cmTC_846be.dir/src.c.o
/usr/bin/cc-DHAVE_C_FLAG_asan   -fsanitize=address -o
CMakeFiles/cmTC_846be.dir/src.c.o   -c
/home/snikulov/work/github/curl/build/CMakeFiles/CMakeTmp/src.c
Linking C executable cmTC_846be
/usr/local/bin/cmake -E cmake_link_script
CMakeFiles/cmTC_846be.dir/link.txt --verbose=1
/usr/bin/cc-DHAVE_C_FLAG_asanCMakeFiles/cmTC_846be.dir/src.c.o
 -o cmTC_846be -rdynamic /usr/lib64/libssl.so /usr/lib64/libcrypto.so
-lldap -llber
CMakeFiles/cmTC_846be.dir/src.c.o: In function `_GLOBAL__sub_I_00099_0_main':
src.c:(.text+0x10): undefined reference to `__asan_init_v1'
collect2: error: ld returned 1 exit status
gmake[1]: *** [cmTC_846be] Error 1
gmake[1]: Leaving directory
`/home/snikulov/work/github/curl/build/CMakeFiles/CMakeTmp'
gmake: *** [cmTC_846be/fast] Error 2

Source file was:
int main(void) { return 0; }

...

-- 
Best Regards,
Sergei Nikulov
-- 

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  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